@@ -57,6 +57,9 @@ class CheckerCommand extends Command
5757 */
5858 protected $ output ;
5959
60+ /** @var int */
61+ protected $ passed = 0 ;
62+
6063 /**
6164 * Configure the console command, add options, etc.
6265 */
@@ -70,7 +73,8 @@ protected function configure()
7073 ->addOption ('skip-classes ' , null , InputOption::VALUE_NONE , 'Don \'t check classes for docblocks. ' )
7174 ->addOption ('skip-methods ' , null , InputOption::VALUE_NONE , 'Don \'t check methods for docblocks. ' )
7275 ->addOption ('skip-anonymous-functions ' , null , InputOption::VALUE_NONE , 'Don \'t check anonymous functions for docblocks. ' )
73- ->addOption ('json ' , 'j ' , InputOption::VALUE_NONE , 'Output JSON instead of a log. ' );
76+ ->addOption ('json ' , 'j ' , InputOption::VALUE_NONE , 'Output JSON instead of a log. ' )
77+ ->addOption ('info-only ' , 'i ' , InputOption::VALUE_NONE , 'Information-only mode, just show summary. ' );
7478 }
7579
7680 /**
@@ -89,7 +93,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
8993 $ this ->output = $ output ;
9094 $ this ->skipClasses = $ input ->getOption ('skip-classes ' );
9195 $ this ->skipMethods = $ input ->getOption ('skip-methods ' );
92- $ this ->skipAnonymousFunctions = $ input ->getOption ('skip-anonymous-functions ' );
9396
9497 // Set up excludes:
9598 if (!is_null ($ exclude )) {
@@ -101,8 +104,67 @@ protected function execute(InputInterface $input, OutputInterface $output)
101104 $ this ->basePath .= '/ ' ;
102105 }
103106
104- // Process:
105- $ this ->processDirectory ();
107+ // Get files to check:
108+ $ files = [];
109+ $ this ->processDirectory ('' , $ files );
110+
111+ // Check files:
112+ $ totalFiles = count ($ files );
113+ $ progressStep = ceil ($ totalFiles / 10 );
114+ $ progressStep = $ progressStep < 1 ? 1 : $ progressStep ;
115+ $ progressDot = round ($ progressStep / 10 );
116+ $ progressDot = $ progressDot < 1 ? 1 : $ progressDot ;
117+
118+ $ i = 0 ;
119+ $ stepi = 0 ;
120+ foreach ($ files as $ file ) {
121+ if ($ this ->verbose && $ progressStep > 0 && $ i > 0 ) {
122+ if ($ stepi % $ progressDot == 0 ) {
123+ $ this ->output ->write ('. ' );
124+ }
125+
126+ if ($ i % $ progressStep == 0 || $ i == ($ totalFiles - 1 )) {
127+ $ this ->output ->write ('. ' . $ i . ' / ' . $ totalFiles . ' ( ' . floor ((100 /$ totalFiles ) * $ i ) . '%) ' );
128+ $ this ->output ->writeln ('' );
129+ $ stepi = 0 ;
130+ }
131+ }
132+
133+ $ this ->processFile ($ file );
134+
135+ $ i ++;
136+ $ stepi ++;
137+ }
138+
139+ if ($ this ->verbose ) {
140+ $ this ->output ->writeln ('' );
141+ $ this ->output ->writeln ('' );
142+ $ this ->output ->writeln ($ totalFiles . ' Files Checked. ' );
143+ $ this ->output ->writeln ('<info> ' . $ this ->passed . ' Passed</info> / <fg=red> ' .count ($ this ->report ).' Errors</> ' );
144+
145+ if (count ($ this ->report ) && !$ input ->getOption ('info-only ' )) {
146+ $ this ->output ->writeln ('' );
147+ $ this ->output ->writeln ('' );
148+
149+ foreach ($ this ->report as $ error ) {
150+ $ this ->output ->write ('<error> ' . $ error ['file ' ] . ': ' . $ error ['line ' ] . '</error> - ' );
151+
152+ if ($ error ['type ' ] == 'class ' ) {
153+ $ this ->output ->write ('Class <info> ' . $ error ['class ' ] . '</info> is missing a docblock. ' );
154+ }
155+
156+ if ($ error ['type ' ] == 'method ' ) {
157+ $ this ->output ->write ('Method <info> ' . $ error ['class ' ] . ':: ' . $ error ['method ' ] . '</info> is missing a docblock. ' );
158+ }
159+
160+ $ this ->output ->writeln ('' );
161+ }
162+ }
163+
164+ $ this ->output ->writeln ('' );
165+ }
166+
167+
106168
107169 // Output JSON if requested:
108170 if ($ json ) {
@@ -116,7 +178,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
116178 * Iterate through a directory and check all of the PHP files within it.
117179 * @param string $path
118180 */
119- protected function processDirectory ($ path = '' )
181+ protected function processDirectory ($ path = '' , array & $ worklist = [] )
120182 {
121183 $ dir = new DirectoryIterator ($ this ->basePath . $ path );
122184
@@ -132,11 +194,11 @@ protected function processDirectory($path = '')
132194 }
133195
134196 if ($ item ->isFile () && $ item ->getExtension () == 'php ' ) {
135- $ this -> processFile ( $ itemPath) ;
197+ $ worklist [] = $ itemPath ;
136198 }
137199
138200 if ($ item ->isDir ()) {
139- $ this ->processDirectory ($ itemPath . '/ ' );
201+ $ this ->processDirectory ($ itemPath . '/ ' , $ worklist );
140202 }
141203 }
142204 }
@@ -147,25 +209,18 @@ protected function processDirectory($path = '')
147209 */
148210 protected function processFile ($ file )
149211 {
212+ $ errors = false ;
150213 $ stream = new PHP_Token_Stream ($ this ->basePath . $ file );
151214
152215 foreach ($ stream ->getClasses () as $ name => $ class ) {
153- $ errors = false ;
154-
155216 if (!$ this ->skipClasses && is_null ($ class ['docblock ' ])) {
156217 $ errors = true ;
157-
158218 $ this ->report [] = array (
159219 'type ' => 'class ' ,
160220 'file ' => $ file ,
161221 'class ' => $ name ,
162222 'line ' => $ class ['startLine ' ],
163223 );
164-
165- if ($ this ->verbose ) {
166- $ message = $ class ['file ' ] . ': ' . $ class ['startLine ' ] . ' - Class ' . $ name . ' is missing a docblock. ' ;
167- $ this ->output ->writeln ('<error> ' . $ message . '</error> ' );
168- }
169224 }
170225
171226 if (!$ this ->skipMethods ) {
@@ -175,33 +230,21 @@ protected function processFile($file)
175230 }
176231
177232 if (is_null ($ method ['docblock ' ])) {
178- if ($ this ->skipAnonymousFunctions && $ methodName == 'anonymous function ' ) {
179- continue ;
180- }
181-
182233 $ errors = true ;
183-
184234 $ this ->report [] = array (
185235 'type ' => 'method ' ,
186236 'file ' => $ file ,
187237 'class ' => $ name ,
188238 'method ' => $ methodName ,
189239 'line ' => $ method ['startLine ' ],
190240 );
191-
192- if ($ this ->verbose ) {
193- $ message = $ class ['file ' ] . ': ' . $ method ['startLine ' ] . ' - Method ' .$ name .':: ' .$ methodName .' is missing a docblock. ' ;
194- $ this ->output ->writeln ('<error> ' . $ message . '</error> ' );
195- }
196241 }
197242 }
198243 }
199-
200- if (!$ errors && $ this ->verbose ) {
201- $ this ->output ->writeln ($ name . ' <info>OK</info> ' );
202- }
203244 }
204245
205-
246+ if (!$ errors ) {
247+ $ this ->passed += 1 ;
248+ }
206249 }
207250}
0 commit comments