1111use Symfony \Component \Console \Input \InputArgument ;
1212use Symfony \Component \Console \Input \InputDefinition ;
1313use Symfony \Component \Console \Input \InputInterface ;
14+ use Symfony \Component \Console \Input \InputOption ;
1415use Symfony \Component \Console \Output \OutputInterface ;
1516
1617final class PhpCodeCheckerCommand extends Command
@@ -44,6 +45,41 @@ public function configure(): void
4445 new InputArgument ('autoload-file ' , InputArgument::OPTIONAL , 'The path to your autoloader ' ),
4546 ]
4647 )
48+ )
49+ ->addOption (
50+ 'access ' ,
51+ null ,
52+ InputOption::VALUE_OPTIONAL ,
53+ 'Check for "public|protected|private" methods. ' ,
54+ 'public|protected|private '
55+ )
56+ ->addOption (
57+ 'skip-mixed-types-as-error ' ,
58+ null ,
59+ InputOption::VALUE_OPTIONAL ,
60+ 'Skip check for mixed types. (false or true) ' ,
61+ 'false '
62+ )
63+ ->addOption (
64+ 'skip-deprecated-functions ' ,
65+ null ,
66+ InputOption::VALUE_OPTIONAL ,
67+ 'Skip check for deprecated functions / methods. (false or true) ' ,
68+ 'false '
69+ )
70+ ->addOption (
71+ 'skip-functions-with-leading-underscore ' ,
72+ null ,
73+ InputOption::VALUE_OPTIONAL ,
74+ 'Skip check for functions / methods with leading underscore. (false or true) ' ,
75+ 'false '
76+ )
77+ ->addOption (
78+ 'skip-parse-errors ' ,
79+ null ,
80+ InputOption::VALUE_OPTIONAL ,
81+ 'Skip parse errors in the output. (false or true) ' ,
82+ 'true '
4783 );
4884 }
4985
@@ -63,6 +99,15 @@ public function execute(InputInterface $input, OutputInterface $output): int
6399 $ this ->composerAutoloaderProjectPaths [] = $ autoloadRealPath ;
64100 }
65101
102+ $ access = $ input ->getOption ('access ' );
103+ \assert (\is_string ($ access ));
104+ $ access = (array ) \explode ('| ' , $ access );
105+
106+ $ skipMixedTypesAsError = (bool ) $ input ->getOption ('skip-mixed-types-as-error ' );
107+ $ skipDeprecatedFunctions = (bool ) $ input ->getOption ('skip-deprecated-functions ' );
108+ $ skipFunctionsWithLeadingUnderscore = (bool ) $ input ->getOption ('skip-functions-with-leading-underscore ' );
109+ $ skipParseErrorsAsError = (bool ) $ input ->getOption ('skip-parse-errors ' );
110+
66111 $ formatter = $ output ->getFormatter ();
67112 $ formatter ->setStyle ('file ' , new OutputFormatterStyle ('default ' , null , ['bold ' ]));
68113 $ formatter ->setStyle ('error ' , new OutputFormatterStyle ('red ' , null , []));
@@ -73,22 +118,22 @@ public function execute(InputInterface $input, OutputInterface $output): int
73118 $ output ->writeln (\str_repeat ('= ' , \strlen ($ banner )));
74119 $ output ->writeln ('' );
75120
76- $ access = ['public ' , 'protected ' , 'private ' ];
77- $ skipMixedTypesAsError = false ;
78- $ skipDeprecatedMethods = false ;
79- $ skipFunctionsWithLeadingUnderscore = false ;
80-
81121 $ errors = \voku \SimplePhpParser \Parsers \PhpCodeChecker::checkPhpFiles (
82122 $ realPath ,
83123 $ access ,
84124 $ skipMixedTypesAsError ,
85- $ skipDeprecatedMethods ,
125+ $ skipDeprecatedFunctions ,
86126 $ skipFunctionsWithLeadingUnderscore ,
127+ $ skipParseErrorsAsError ,
87128 $ this ->composerAutoloaderProjectPaths
88129 );
89130
131+ $ errorCount = 0 ;
90132 foreach ($ errors as $ file => $ errorsInner ) {
91- $ output ->writeln ('<file> ' . $ file . '</file> ' );
133+ $ errorCountFile = \count ($ errorsInner );
134+ $ errorCount += $ errorCountFile ;
135+
136+ $ output ->writeln ('<file> ' . $ file . '</file> ' . ' ( ' . $ errorCountFile . ' errors) ' );
92137
93138 foreach ($ errorsInner as $ errorInner ) {
94139 $ output ->writeln ('<error> ' . $ errorInner . '</error> ' );
@@ -98,6 +143,10 @@ public function execute(InputInterface $input, OutputInterface $output): int
98143 $ output ->writeln ('' );
99144 }
100145
146+ $ output ->writeln ('------------------------------- ' );
147+ $ output ->writeln ($ errorCount . ' errors in ' . \count ($ errors ) . ' files. ' );
148+ $ output ->writeln ('------------------------------- ' );
149+
101150 return 0 ;
102151 }
103152}
0 commit comments