33namespace Phug \Split \Command ;
44
55use Phug \Split ;
6+ use Phug \Split \UnableToListDirectoryItems ;
67use SimpleCli \SimpleCli ;
78use Traversable ;
89
@@ -66,7 +67,7 @@ protected function calculatePackagesTree(Split $cli): bool
6667 return $ cli ->error ('Root project directory should contains a ' .$ this ->composerFile .' file. ' );
6768 }
6869
69- $ data = (array ) json_decode (file_get_contents ($ this ->composerFile ), true );
70+ $ data = (array ) json_decode (( string ) file_get_contents ($ this ->composerFile ), true );
7071 $ vendorDirectory = ($ data ['config ' ] ?? [])['vendor-dir ' ] ?? 'vendor ' ;
7172
7273 $ cli ->writeLine ((string ) $ data ['name ' ]);
@@ -93,7 +94,7 @@ protected function getPackages(): iterable
9394
9495 protected function dumpPackagesTree (Split $ cli , iterable $ packages , int $ level = 0 ): bool
9596 {
96- $ count = is_countable ($ packages ) ? count ($ packages ) : INF ;
97+ $ count = is_countable ($ packages ) ? count ($ packages ) : 0 ;
9798
9899 foreach ($ packages as $ index => $ package ) {
99100 $ symbol = $ index === $ count - 1 ? '└ ' : '├ ' ;
@@ -106,7 +107,13 @@ protected function dumpPackagesTree(Split $cli, iterable $packages, int $level =
106107
107108 protected function mapDirectories (string $ directory , callable $ callback ): iterable
108109 {
109- foreach (scandir ($ directory ) as $ element ) {
110+ $ elements = scandir ($ directory );
111+
112+ if ($ elements === false ) {
113+ throw new UnableToListDirectoryItems ($ directory );
114+ }
115+
116+ foreach ($ elements as $ element ) {
110117 if (substr ($ element , 0 , 1 ) === '. ' ) {
111118 continue ;
112119 }
@@ -141,7 +148,7 @@ protected function scanDirectories(string $directory): iterable
141148 $ composerPath = $ directory .DIRECTORY_SEPARATOR .$ this ->composerFile ;
142149
143150 if (file_exists ($ composerPath )) {
144- $ data = json_decode (file_get_contents ($ composerPath ), true );
151+ $ data = json_decode (( string ) file_get_contents ($ composerPath ), true );
145152 $ mainPackage = $ this ->getPackage ($ directory , $ data );
146153 }
147154
0 commit comments