File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,3 +21,7 @@ Don't worry if your code styling isn't perfect! `Fix PHP code style issues` acti
2121## Testing
2222
2323The added code needs to be well tested and not reduce the coverage. Feel free to use ` Pest ` or ` PHPUnit ` .
24+
25+ ## TODO
26+
27+ - Custom exceptions
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ protected function setLocaleLoadersCollection(): void
5252 {
5353 $ this ->localeLoadersCollection = [];
5454
55- foreach ($ this ->directory ->getDirectoryContent () as $ lang => $ abs_path ) {
55+ foreach ($ this ->directory ->getSubDirectories () as $ lang => $ abs_path ) {
5656 $ this ->localeLoadersCollection [$ lang ] = $ this ->localeFolderFactory ->make ($ abs_path );
5757 }
5858 }
@@ -66,7 +66,7 @@ protected function setLocaleLoadersCollection(): void
6666 */
6767 public function getLocalesList (): array
6868 {
69- return array_keys ($ this ->directory ->getDirectoryContent ());
69+ return array_keys ($ this ->directory ->getSubDirectories ());
7070 }
7171
7272 /**
Original file line number Diff line number Diff line change @@ -98,18 +98,30 @@ public function getDirectoryContent(): array
9898 return $ this ->directoryContent ;
9999 }
100100
101+ /**
102+ * 'Dir_name/locale' => 'dir_absolute_path'
103+ */
104+ public function getSubDirectories (): array
105+ {
106+ $ directoryContent = $ this ->getDirectoryContent ();
107+
108+ return array_filter (
109+ $ directoryContent ,
110+ fn ($ abs_path ) => is_dir ($ abs_path ),
111+ ARRAY_FILTER_USE_BOTH
112+ );
113+ }
114+
101115 /**
102116 * 'JSON_name' => 'file_absolute_path'
103117 */
104118 public function getDirectoryJsonContent (): array
105119 {
106- if (! $ this ->isDir ()) {
107- throw new Exception ("This object isn't a directory " );
108- }
120+ $ directoryContent = $ this ->getDirectoryContent ();
109121
110122 return array_filter (
111- $ this -> directoryContent ,
112- fn ($ file_name , $ abs_path ) => is_json ($ file_name ),
123+ $ directoryContent ,
124+ fn ($ abs_path , $ file_name ) => is_json ($ file_name ),
113125 ARRAY_FILTER_USE_BOTH
114126 );
115127 }
Original file line number Diff line number Diff line change 6666 ->expect (fn () => (new File ('composer.json ' ))->getDirectoryContent ())
6767 ->throws (\Exception::class, 'This object isn \'t a directory ' );
6868
69+ test ('getSubDirectories ' )
70+ ->expect ((new File ())->getSubDirectories ())
71+ ->not ->toContain (realpath (__DIR__ .'/../../../composer.json ' ))
72+ ->toContain (realpath (__DIR__ .'/../../../src ' ))
73+ ->toContain (realpath (__DIR__ .'/../../../tests ' ))
74+ ->toContain (realpath (__DIR__ .'/../../../vendor ' ));
75+
6976test ('getDirectoryJsonContent ' )
7077 ->expect ((new File ())->getDirectoryJsonContent ())
7178 ->toHaveCount (1 )
7279 ->toContain (realpath (__DIR__ .'/../../../composer.json ' ));
73-
74- it ('throws an exception for calling getDirectoryJsonContent on a file ' )
75- ->expect (fn () => (new File ('composer.json ' ))->getDirectoryJsonContent ())
76- ->throws (\Exception::class, 'This object isn \'t a directory ' );
You can’t perform that action at this time.
0 commit comments