77use Symfony \Component \Console \Command \Command ;
88use Symfony \Component \Console \Input \InputInterface ;
99use Symfony \Component \Console \Output \OutputInterface ;
10+ use Symfony \Component \Console \Style \SymfonyStyle ;
1011
1112final class TestTypeUsageCommand extends Command
1213{
@@ -42,6 +43,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4243
4344 foreach ($ usedByRouteTypeList as $ usedByRouteType ) {
4445 $ definedType = $ this ->definedTypes [$ usedByRouteType ];
46+ if (!array_key_exists ('type ' , $ definedType )) {
47+ //TODO: warning
48+ dump ($ definedType );
49+ }
4550 $ usedType = str_ends_with ($ definedType ['type ' ], '[] ' ) ? substr ($ definedType ['type ' ], 0 , -2 ) : $ definedType ['type ' ];
4651 if (!in_array ($ usedType , $ this ->usedByOtherTypeTypeList )) {
4752 $ this ->usedByOtherTypeTypeList [] = $ usedType ;
@@ -52,7 +57,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5257 $ usedTypeList = array_merge ($ usedByRouteTypeList , $ this ->usedByOtherTypeTypeList );
5358 $ unusedTypeList = array_values (array_diff (array_keys ($ this ->definedTypes ), $ usedTypeList ));
5459 sort ($ unusedTypeList );
55- dump ($ unusedTypeList );
60+
61+ if (!empty ($ unusedTypeList )) {
62+ $ style = new SymfonyStyle ($ input , $ output );
63+ $ style ->title ('Unused types ' );
64+ $ style ->listing ($ unusedTypeList );
65+ return Command::FAILURE ;
66+ }
5667
5768 return Command::SUCCESS ;
5869 }
@@ -65,9 +76,13 @@ private function exploreProperties(array $definedType)
6576 if (is_array ($ propertyDefinition )) {
6677 if (array_key_exists ('type ' , $ propertyDefinition )) {
6778 if ('array ' === $ propertyDefinition ['type ' ]) {
68- $ usedType = $ propertyDefinition ['items ' ];
79+ if (is_array ($ propertyDefinition ['items ' ]) && array_key_exists ('properties ' , $ propertyDefinition ['items ' ])) {
80+ $ this ->exploreProperties ($ propertyDefinition ['items ' ]);
81+ } else {
82+ $ usedType = $ propertyDefinition ['items ' ];
83+ }
6984 } elseif (array_key_exists ('properties ' , $ propertyDefinition )) {
70- $ this ->exploreProperties ($ propertyDefinition, $ this -> usedByOtherTypeTypeList );
85+ $ this ->exploreProperties ($ propertyDefinition );
7186 } elseif (str_ends_with ($ propertyDefinition ['type ' ], '[] ' )) {
7287 $ usedType = substr ($ propertyDefinition ['type ' ], 0 , -2 );
7388 } else {
@@ -82,8 +97,16 @@ private function exploreProperties(array $definedType)
8297 }
8398 }
8499 if (null !== $ usedType && !in_array ($ usedType , $ this ->usedByOtherTypeTypeList )) {
100+ if (!is_string ($ usedType )) {
101+ //TODO: warning
102+ dump ($ propertyDefinition , $ usedType );
103+ }
85104 $ this ->usedByOtherTypeTypeList [] = $ usedType ;
86105 if (array_key_exists ($ usedType , $ this ->definedTypes )) {
106+ if (!is_array ($ this ->definedTypes [$ usedType ])) {
107+ //TODO: warning
108+ dump ($ usedType , $ this ->definedTypes [$ usedType ]);
109+ }
87110 $ this ->exploreProperties ($ this ->definedTypes [$ usedType ]);
88111 }
89112 }
0 commit comments