@@ -17,15 +17,19 @@ public function discoverTranslations(): Collection
1717 ->flatMap (static fn (string $ path ): Collection => collect (File::allFiles ($ path ))
1818 ->map (static fn (SplFileInfo $ file ): array => [
1919 'path ' => $ file ->getPathname (),
20- 'lang ' => str (substr (pathinfo ($ file ->getPathname (), PATHINFO_DIRNAME ), strlen ($ path ) + 1 ))
21- ->replace ('/ ' , '. ' )
22- ->toString (),
20+ 'lang ' => str (substr (pathinfo ($ file ->getPathname (), PATHINFO_DIRNAME ), strlen ($ path ) + 1 ))->replace (
21+ search: '/ ' ,
22+ replace: '. ' ,
23+ )->toString (),
2324 ]))
2425 ->reduceWithKeys (static function (Collection $ acc , array $ file ): Collection {
25- $ key = implode ('. ' , [$ file ['lang ' ], pathinfo ($ file ['path ' ], PATHINFO_FILENAME )]);
26+ $ key = implode (
27+ separator: '. ' ,
28+ array: [$ file ['lang ' ], pathinfo ($ file ['path ' ], PATHINFO_FILENAME )],
29+ );
2630
2731 $ acc [$ key ] = match (pathinfo ($ file ['path ' ], PATHINFO_EXTENSION )) {
28- 'json ' => json_decode ($ file ['path ' ], true , JSON_THROW_ON_ERROR ),
32+ 'json ' => json_decode ($ file ['path ' ], associative: true , flags: JSON_THROW_ON_ERROR ),
2933 'php ' => require $ file ['path ' ],
3034 default => [],
3135 };
@@ -34,15 +38,15 @@ public function discoverTranslations(): Collection
3438 }, collect ())
3539 ->undot ()
3640 ->map (static function (array $ value ): array {
37- return collect ($ value )->dot ()->filter (fn ($ trans ) => is_string ($ trans ))->toArray ();
41+ return collect ($ value )->dot ()->filter (fn (mixed $ trans ): bool => is_string ($ trans ))->toArray ();
3842 });
3943 }
4044
4145 public function discoverUsedTranslationKeys (): Collection
4246 {
43- $ outputPath = Config::get ( 'polywarp.output_path ' );
47+ $ outputPath = Config::string (key: 'polywarp.output_path ' );
4448
45- return collect (Config::get ( 'polywarp.script_paths ' ))
49+ return collect (Config::array (key: 'polywarp.script_paths ' ))
4650 ->flatMap (File::allFiles (...))
4751 ->flatMap (static function (SplFileInfo $ file ) use ($ outputPath ): Collection {
4852 if ($ file ->getExtension () !== 'ts ' || $ file ->getPathname () === $ outputPath ) {
@@ -51,7 +55,11 @@ public function discoverUsedTranslationKeys(): Collection
5155
5256 $ content = $ file ->getContents ();
5357
54- preg_match_all ('/t\(\s*([ \'"])(.*?)\1/ ' , $ content , $ matches );
58+ preg_match_all (
59+ pattern: '/t\(\s*([ \'"])(.*?)\1/ ' ,
60+ subject: $ content ,
61+ matches: $ matches ,
62+ );
5563
5664 return collect ($ matches [2 ]);
5765 });
@@ -60,34 +68,41 @@ public function discoverUsedTranslationKeys(): Collection
6068 private function compileTypeOverloads (Collection $ translations ): string
6169 {
6270 return $ translations
63- ->flatMap ( fn ( $ e ) => $ e )
71+ ->collapse ( )
6472 ->map (static function (string $ value , string $ key ): string {
6573 $ params = [];
66- preg_match_all ('/:(\w+)/ ' , $ value , $ matches );
74+ preg_match_all (
75+ pattern: '/:(\w+)/ ' ,
76+ subject: $ value ,
77+ matches: $ matches ,
78+ );
6779 if (isset ($ matches [1 ])) {
6880 $ params = $ matches [1 ];
6981 }
7082
7183 if ($ params ) {
72- $ paramStr = implode (', ' , array_map (fn (string $ p ): string => "{$ p }: string | number " , $ params ));
84+ $ paramStr = implode (
85+ separator: ', ' ,
86+ array: array_map (fn (string $ p ): string => "{$ p }: string | number " , $ params ),
87+ );
7388 return "(key: \"{$ key }\", params: { {$ paramStr } }): string; " ;
7489 }
7590
7691 return "(key: \"{$ key }\"): string; " ;
7792 })
78- ->implode ('' );
93+ ->implode (value: '' );
7994 }
8095
8196 public function compile (Collection $ availableTranlsations , Collection $ keysToKeep ): string
8297 {
83- $ translationsToIncludeInBundle = json_encode ($ availableTranlsations -> mapWithKeys ( static fn (
84- array $ value ,
85- string $ lang ,
86- ): array => [ $ lang => array_filter (
87- $ value ,
88- $ keysToKeep -> contains (... ),
89- mode: ARRAY_FILTER_USE_KEY ,
90- )]), JSON_THROW_ON_ERROR ) ;
98+ $ translationsToIncludeInBundle = json_encode (
99+ $ availableTranlsations -> mapWithKeys ( static fn ( array $ value , string $ lang ): array => [ $ lang => array_filter (
100+ $ value ,
101+ $ keysToKeep -> contains (...),
102+ mode: ARRAY_FILTER_USE_KEY ,
103+ )] ),
104+ JSON_THROW_ON_ERROR ,
105+ );
91106
92107 return <<<ts
93108 // This file is auto-generated. Do not edit it manually.
0 commit comments