11
11
use Symfony \Component \Console \Input \InputArgument ;
12
12
use Symfony \Component \Console \Input \InputDefinition ;
13
13
use Symfony \Component \Console \Input \InputInterface ;
14
+ use Symfony \Component \Console \Input \InputOption ;
14
15
use Symfony \Component \Console \Output \OutputInterface ;
15
16
16
17
final class PhpCodeCheckerCommand extends Command
@@ -44,6 +45,41 @@ public function configure(): void
44
45
new InputArgument ('autoload-file ' , InputArgument::OPTIONAL , 'The path to your autoloader ' ),
45
46
]
46
47
)
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 '
47
83
);
48
84
}
49
85
@@ -63,6 +99,15 @@ public function execute(InputInterface $input, OutputInterface $output): int
63
99
$ this ->composerAutoloaderProjectPaths [] = $ autoloadRealPath ;
64
100
}
65
101
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
+
66
111
$ formatter = $ output ->getFormatter ();
67
112
$ formatter ->setStyle ('file ' , new OutputFormatterStyle ('default ' , null , ['bold ' ]));
68
113
$ formatter ->setStyle ('error ' , new OutputFormatterStyle ('red ' , null , []));
@@ -73,22 +118,22 @@ public function execute(InputInterface $input, OutputInterface $output): int
73
118
$ output ->writeln (\str_repeat ('= ' , \strlen ($ banner )));
74
119
$ output ->writeln ('' );
75
120
76
- $ access = ['public ' , 'protected ' , 'private ' ];
77
- $ skipMixedTypesAsError = false ;
78
- $ skipDeprecatedMethods = false ;
79
- $ skipFunctionsWithLeadingUnderscore = false ;
80
-
81
121
$ errors = \voku \SimplePhpParser \Parsers \PhpCodeChecker::checkPhpFiles (
82
122
$ realPath ,
83
123
$ access ,
84
124
$ skipMixedTypesAsError ,
85
- $ skipDeprecatedMethods ,
125
+ $ skipDeprecatedFunctions ,
86
126
$ skipFunctionsWithLeadingUnderscore ,
127
+ $ skipParseErrorsAsError ,
87
128
$ this ->composerAutoloaderProjectPaths
88
129
);
89
130
131
+ $ errorCount = 0 ;
90
132
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) ' );
92
137
93
138
foreach ($ errorsInner as $ errorInner ) {
94
139
$ output ->writeln ('<error> ' . $ errorInner . '</error> ' );
@@ -98,6 +143,10 @@ public function execute(InputInterface $input, OutputInterface $output): int
98
143
$ output ->writeln ('' );
99
144
}
100
145
146
+ $ output ->writeln ('------------------------------- ' );
147
+ $ output ->writeln ($ errorCount . ' errors in ' . \count ($ errors ) . ' files. ' );
148
+ $ output ->writeln ('------------------------------- ' );
149
+
101
150
return 0 ;
102
151
}
103
152
}
0 commit comments