1- <?php declare (strict_types=1 );
1+ <?php
2+ declare (strict_types=1 );
23
34namespace Frosh \Tools \Controller ;
45
56use Shopware \Core \Kernel ;
7+ use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
68use Symfony \Component \DependencyInjection \Attribute \Autowire ;
79use Symfony \Component \HttpFoundation \JsonResponse ;
810use Symfony \Component \HttpFoundation \Request ;
911use Symfony \Component \Routing \Annotation \Route ;
1012
1113#[Route(path: '/api/_action/frosh-tools ' , defaults: ['_routeScope ' => ['api ' ], '_acl ' => ['frosh_tools:read ' ]])]
12- class ShopwareFilesController
14+ class ShopwareFilesController extends AbstractController
1315{
1416 private const STATUS_OK = 0 ;
1517 private const STATUS_IGNORED_ALL = 1 ;
1618 private const STATUS_IGNORED_IN_PROJECT = 2 ;
17- private bool $ isPlatform ;
19+
20+ private readonly bool $ isPlatform ;
1821
1922 public function __construct (
2023 #[Autowire('%kernel.shopware_version% ' )] private readonly string $ shopwareVersion ,
21- #[Autowire('%kernel.project_dir%< ' )] private readonly string $ projectDir ,
22- #[Autowire('%frosh_tools.file_checker.exclude_files% ' )] private readonly array $ projectIgnoredFiles
23- )
24- {
24+ #[Autowire('%kernel.project_dir% ' )] private readonly string $ projectDir ,
25+ #[Autowire('%frosh_tools.file_checker.exclude_files% ' )] private readonly array $ projectExcludeFiles
26+ ) {
2527 $ this ->isPlatform = !is_dir ($ this ->projectDir . '/vendor/shopware/core ' ) && is_dir ($ this ->projectDir . '/src/Core ' );
2628 }
2729
@@ -45,9 +47,7 @@ public function listShopwareFiles(): JsonResponse
4547
4648 foreach (explode ("\n" , $ data ) as $ row ) {
4749 if ($ this ->isPlatform ) {
48- $ row = preg_replace_callback ('/vendor\/shopware\/(.)/ ' , function ($ matches ) {
49- return 'src/ ' . strtoupper ($ matches [1 ]);
50- }, $ row );
50+ $ row = preg_replace_callback ('/vendor\/shopware\/(.)/ ' , fn ($ matches ): string => 'src/ ' . strtoupper ($ matches [1 ]), $ row );
5151 }
5252
5353 [$ expectedMd5Sum , $ file ] = explode (' ' , trim ($ row ));
@@ -77,8 +77,8 @@ public function listShopwareFiles(): JsonResponse
7777 ];
7878 }
7979
80- //WE SHOULD STOP HERE, WHILE THERE MIGHT BE ANY BIG PROBLEM!
81- if (count ($ invalidFiles ) > 100 ) {
80+ // WE SHOULD STOP HERE, WHILE THERE MIGHT BE ANY BIG PROBLEM!
81+ if (\ count ($ invalidFiles ) > 100 ) {
8282 break ;
8383 }
8484 }
@@ -148,22 +148,18 @@ public function restoreShopwareFile(Request $request): JsonResponse
148148
149149 private function getShopwareUrl (string $ name ): ?string
150150 {
151- if ($ this ->isPlatform ) {
152- $ name = preg_replace ('/^src\// ' , '' , $ name );
153- } else {
154- $ name = preg_replace ('/^vendor\/shopware\// ' , '' , $ name );
155- }
151+ $ name = $ this ->isPlatform ? preg_replace ('/^src\// ' , '' , $ name ) : preg_replace ('/^vendor\/shopware\// ' , '' , $ name );
156152
157153 $ pathParts = \explode ('/ ' , $ name );
158154 $ repo = $ pathParts [0 ];
159155 array_shift ($ pathParts );
160156
161- return 'https://github.com/shopware/ ' .
162- $ repo .
163- '/blob/v ' .
164- $ this ->shopwareVersion .
165- '/ ' .
166- \implode ('/ ' , $ pathParts );
157+ return 'https://github.com/shopware/ '
158+ . $ repo
159+ . '/blob/v '
160+ . $ this ->shopwareVersion
161+ . '/ '
162+ . \implode ('/ ' , $ pathParts );
167163 }
168164
169165 private function getOriginalFileContent (string $ name ): ?string
@@ -173,19 +169,10 @@ private function getOriginalFileContent(string $name): ?string
173169
174170 private function isIgnoredFileHash (string $ file ): int
175171 {
176- if (in_array ($ file , $ this ->projectIgnoredFiles , true )) {
172+ if (\ in_array ($ file , $ this ->projectExcludeFiles , true )) {
177173 return self ::STATUS_IGNORED_IN_PROJECT ;
178174 }
179175
180176 return self ::STATUS_OK ;
181177 }
182-
183- private function assertNoGitVersion (): ?JsonResponse
184- {
185- if ($ this ->shopwareVersion === Kernel::SHOPWARE_FALLBACK_VERSION ) {
186- return new JsonResponse (['error ' => 'Git version is not supported ' ]);
187- }
188-
189- return null ;
190- }
191178}
0 commit comments