11<?php
22
3+ declare (strict_types = 1 );
4+
35namespace PhpDocChecker ;
46
57use DirectoryIterator ;
@@ -66,7 +68,7 @@ class CheckerCommand extends Command
6668 /**
6769 * Configure the console command, add options, etc.
6870 */
69- protected function configure ()
71+ protected function configure (): void
7072 {
7173 $ this
7274 ->setName ('check ' )
@@ -84,31 +86,32 @@ protected function configure()
8486
8587 /**
8688 * Execute the actual docblock checker.
89+ *
8790 * @param InputInterface $input
8891 * @param OutputInterface $output
92+ *
8993 * @return int
9094 */
91- protected function execute (InputInterface $ input , OutputInterface $ output )
95+ protected function execute (InputInterface $ input , OutputInterface $ output ): int
9296 {
93- // Process options:
94- $ exclude = $ input ->getOption ('exclude ' );
95- $ json = $ input ->getOption ('json ' );
96- $ this ->basePath = $ input ->getOption ('directory ' );
97- $ this ->verbose = !$ json ;
98- $ this ->output = $ output ;
99- $ this ->skipClasses = $ input ->getOption ('skip-classes ' );
100- $ this ->skipMethods = $ input ->getOption ('skip-methods ' );
97+ $ exclude = $ input ->getOption ('exclude ' );
98+ $ json = $ input ->getOption ('json ' );
99+ $ this ->basePath = $ input ->getOption ('directory ' );
100+ $ this ->verbose = !$ json ;
101+ $ this ->output = $ output ;
102+ $ this ->skipClasses = $ input ->getOption ('skip-classes ' );
103+ $ this ->skipMethods = $ input ->getOption ('skip-methods ' );
101104 $ this ->skipSignatures = $ input ->getOption ('skip-signatures ' );
102- $ failOnWarnings = $ input ->getOption ('fail-on-warnings ' );
103- $ startTime = microtime (true );
105+ $ failOnWarnings = $ input ->getOption ('fail-on-warnings ' );
106+ $ startTime = \ microtime (true );
104107
105108 // Set up excludes:
106- if (!is_null ($ exclude )) {
107- $ this ->exclude = array_map ('trim ' , explode (', ' , $ exclude ));
109+ if (!\ is_null ($ exclude )) {
110+ $ this ->exclude = \ array_map ('trim ' , \ explode (', ' , $ exclude ));
108111 }
109112
110113 // Check base path ends with a slash:
111- if (substr ($ this ->basePath , -1 ) != '/ ' ) {
114+ if (\ substr ($ this ->basePath , -1 ) != '/ ' ) {
112115 $ this ->basePath .= '/ ' ;
113116 }
114117
@@ -118,23 +121,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
118121
119122 // Check files:
120123 $ filesPerLine = (int )$ input ->getOption ('files-per-line ' );
121- $ totalFiles = count ($ files );
122- $ files = array_chunk ($ files , $ filesPerLine );
124+ $ totalFiles = \ count ($ files );
125+ $ files = \ array_chunk ($ files , $ filesPerLine );
123126 $ processed = 0 ;
124- $ fileCountLength = strlen ((string )$ totalFiles );
127+ $ fileCountLength = \ strlen ((string )$ totalFiles );
125128
126129 if ($ this ->verbose ) {
127130 $ output ->writeln ('<fg=blue>PHPDoc Checker</> ' );
128131 $ output ->writeln ('' );
129132 }
130133
131- while (count ($ files )) {
132- $ chunk = array_shift ($ files );
133- $ chunkFiles = count ($ chunk );
134+ while (\ count ($ files )) {
135+ $ chunk = \ array_shift ($ files );
136+ $ chunkFiles = \ count ($ chunk );
134137
135- while (count ($ chunk )) {
138+ while (\ count ($ chunk )) {
136139 $ processed ++;
137- $ file = array_shift ($ chunk );
140+ $ file = \ array_shift ($ chunk );
138141
139142 list ($ errors , $ warnings ) = $ this ->processFile ($ file );
140143
@@ -150,23 +153,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
150153 }
151154
152155 if ($ this ->verbose ) {
153- $ this ->output ->write (str_pad ('' , $ filesPerLine - $ chunkFiles ));
154- $ this ->output ->writeln (' ' . str_pad ($ processed , $ fileCountLength , ' ' , STR_PAD_LEFT ) . '/ ' . $ totalFiles . ' ( ' . floor ((100 /$ totalFiles ) * $ processed ) . '%) ' );
156+ $ this ->output ->write (\ str_pad ('' , $ filesPerLine - $ chunkFiles ));
157+ $ this ->output ->writeln (' ' . \ str_pad (( string ) $ processed , $ fileCountLength , ' ' , STR_PAD_LEFT ) . '/ ' . $ totalFiles . ' ( ' . \ floor ((100 /$ totalFiles ) * $ processed ) . '%) ' );
155158 }
156159 }
157160
158161 if ($ this ->verbose ) {
159- $ time = round (microtime (true ) - $ startTime , 2 );
162+ $ time = \ round (\ microtime (true ) - $ startTime , 2 );
160163 $ this ->output ->writeln ('' );
161164 $ this ->output ->writeln ('' );
162- $ this ->output ->writeln ('Checked ' . number_format ($ totalFiles ) . ' files in ' . $ time . ' seconds. ' );
163- $ this ->output ->write ('<info> ' . number_format ($ this ->passed ) . ' Passed</info> ' );
164- $ this ->output ->write (' / <fg=red> ' . number_format (count ($ this ->errors )). ' Errors</> ' );
165- $ this ->output ->write (' / <fg=yellow> ' . number_format (count ($ this ->warnings )). ' Warnings</> ' );
165+ $ this ->output ->writeln ('Checked ' . \ number_format ($ totalFiles ) . ' files in ' . $ time . ' seconds. ' );
166+ $ this ->output ->write ('<info> ' . \ number_format ($ this ->passed ) . ' Passed</info> ' );
167+ $ this ->output ->write (' / <fg=red> ' . \ number_format (\ count ($ this ->errors )) . ' Errors</> ' );
168+ $ this ->output ->write (' / <fg=yellow> ' . \ number_format (\ count ($ this ->warnings )) . ' Warnings</> ' );
166169
167170 $ this ->output ->writeln ('' );
168171
169- if (count ($ this ->errors ) && !$ input ->getOption ('info-only ' )) {
172+ if (\ count ($ this ->errors ) && !$ input ->getOption ('info-only ' )) {
170173 $ this ->output ->writeln ('' );
171174 $ this ->output ->writeln ('' );
172175
@@ -185,7 +188,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
185188 }
186189 }
187190
188- if (count ($ this ->warnings ) && !$ input ->getOption ('info-only ' )) {
191+ if (\ count ($ this ->warnings ) && !$ input ->getOption ('info-only ' )) {
189192 foreach ($ this ->warnings as $ error ) {
190193 $ this ->output ->write ('<fg=yellow>WARNING </> ' );
191194
@@ -214,18 +217,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
214217
215218 // Output JSON if requested:
216219 if ($ json ) {
217- print json_encode (array_merge ($ this ->errors , $ this ->warnings ));
220+ print \ json_encode (\ array_merge ($ this ->errors , $ this ->warnings ));
218221 }
219222
220- return count ($ this ->errors ) || ($ failOnWarnings && count ($ this ->warnings )) ? 1 : 0 ;
223+ return \ count ($ this ->errors ) || ($ failOnWarnings && \ count ($ this ->warnings )) ? 1 : 0 ;
221224 }
222225
223226 /**
224227 * Iterate through a directory and check all of the PHP files within it.
228+ *
225229 * @param string $path
226- * @param string[] $worklist
230+ * @param string[] $workList
227231 */
228- protected function processDirectory ($ path = '' , array &$ worklist = [])
232+ protected function processDirectory (string $ path = '' , array &$ workList = []): void
229233 {
230234 $ dir = new DirectoryIterator ($ this ->basePath . $ path );
231235
@@ -236,34 +240,36 @@ protected function processDirectory($path = '', array &$worklist = [])
236240
237241 $ itemPath = $ path . $ item ->getFilename ();
238242
239- if (in_array ($ itemPath , $ this ->exclude )) {
243+ if (\ in_array ($ itemPath , $ this ->exclude )) {
240244 continue ;
241245 }
242246
243247 if ($ item ->isFile () && $ item ->getExtension () == 'php ' ) {
244- $ worklist [] = $ itemPath ;
248+ $ workList [] = $ itemPath ;
245249 }
246250
247251 if ($ item ->isDir ()) {
248- $ this ->processDirectory ($ itemPath . '/ ' , $ worklist );
252+ $ this ->processDirectory ($ itemPath . '/ ' , $ workList );
249253 }
250254 }
251255 }
252256
253257 /**
254258 * Check a specific PHP file for errors.
259+ *
255260 * @param string $file
261+ *
256262 * @return array
257263 */
258- protected function processFile ($ file )
264+ protected function processFile (string $ file ): array
259265 {
260- $ errors = false ;
261- $ warnings = false ;
266+ $ errors = false ;
267+ $ warnings = false ;
262268 $ processor = new FileProcessor ($ this ->basePath . $ file );
263269
264270 if (!$ this ->skipClasses ) {
265271 foreach ($ processor ->getClasses () as $ name => $ class ) {
266- if (is_null ($ class ['docblock ' ])) {
272+ if (\ is_null ($ class ['docblock ' ])) {
267273 $ errors = true ;
268274 $ this ->errors [] = [
269275 'type ' => 'class ' ,
@@ -277,7 +283,7 @@ protected function processFile($file)
277283
278284 if (!$ this ->skipMethods ) {
279285 foreach ($ processor ->getMethods () as $ name => $ method ) {
280- if (is_null ($ method ['docblock ' ])) {
286+ if (\ is_null ($ method ['docblock ' ])) {
281287 $ errors = true ;
282288 $ this ->errors [] = [
283289 'type ' => 'method ' ,
@@ -292,7 +298,7 @@ protected function processFile($file)
292298
293299 if (!$ this ->skipSignatures ) {
294300 foreach ($ processor ->getMethods () as $ name => $ method ) {
295- if (count ($ method ['params ' ])) {
301+ if (\ count ($ method ['params ' ])) {
296302 foreach ($ method ['params ' ] as $ param => $ type ) {
297303 if (empty ($ method ['docblock ' ]['params ' ][$ param ])) {
298304 $ warnings = true ;
@@ -304,8 +310,8 @@ protected function processFile($file)
304310 'line ' => $ method ['line ' ],
305311 'param ' => $ param ,
306312 ];
307- } elseif (is_array ($ type )) {
308- $ docblockTypes = explode ('| ' , $ method ['docblock ' ]['params ' ][$ param ]);
313+ } elseif (\ is_array ($ type )) {
314+ $ docblockTypes = \ explode ('| ' , $ method ['docblock ' ]['params ' ][$ param ]);
309315 $ normalizedType = $ type ;
310316 $ normalizedType [0 ] = $ docblockTypes [0 ];
311317
@@ -318,13 +324,13 @@ protected function processFile($file)
318324 'method ' => $ method ['name ' ],
319325 'line ' => $ method ['line ' ],
320326 'param ' => $ param ,
321- 'param-type ' => implode ('| ' , $ type ),
327+ 'param-type ' => \ implode ('| ' , $ type ),
322328 'doc-type ' => $ method ['docblock ' ]['params ' ][$ param ],
323329 ];
324330 }
325331 } elseif (!empty ($ type ) && $ method ['docblock ' ]['params ' ][$ param ] !== $ type ) {
326332 if (
327- ($ type === 'array ' && substr ($ method ['docblock ' ]['params ' ][$ param ], -2 ) === '[] ' )
333+ ($ type === 'array ' && \ substr ($ method ['docblock ' ]['params ' ][$ param ], -2 ) === '[] ' )
328334 || $ method ['docblock ' ]['params ' ][$ param ] === 'mixed '
329335 ) {
330336 // Do nothing because this is fine.
@@ -360,8 +366,8 @@ protected function processFile($file)
360366 'method ' => $ method ['name ' ],
361367 'line ' => $ method ['line ' ],
362368 ];
363- } elseif (is_array ($ method ['return ' ])) {
364- $ docblockTypes = explode ('| ' , $ method ['docblock ' ]['return ' ]);
369+ } elseif (\ is_array ($ method ['return ' ])) {
370+ $ docblockTypes = \ explode ('| ' , $ method ['docblock ' ]['return ' ]);
365371 if ($ method ['return ' ] !== $ docblockTypes ) {
366372 $ warnings = true ;
367373 $ this ->warnings [] = [
@@ -370,15 +376,15 @@ protected function processFile($file)
370376 'class ' => $ method ['class ' ],
371377 'method ' => $ method ['name ' ],
372378 'line ' => $ method ['line ' ],
373- 'return-type ' => implode ('| ' , $ method ['return ' ]),
379+ 'return-type ' => \ implode ('| ' , $ method ['return ' ]),
374380 'doc-type ' => $ method ['docblock ' ]['return ' ],
375381 ];
376382 }
377383 } elseif ($ method ['docblock ' ]['return ' ] !== $ method ['return ' ]) {
378384 if (
379- ($ method ['return ' ] === 'array ' && substr ($ method ['docblock ' ]['return ' ], -2 ) === '[] ' )
385+ ($ method ['return ' ] === 'array ' && \ substr ($ method ['docblock ' ]['return ' ], -2 ) === '[] ' )
380386 || $ method ['docblock ' ]['return ' ] === 'mixed '
381- || (strpos ($ method ['docblock ' ]['return ' ], '| ' ) !== false && PHP_MAJOR_VERSION < 8 )
387+ || (\ strpos ($ method ['docblock ' ]['return ' ], '| ' ) !== false && PHP_MAJOR_VERSION < 8 )
382388 ) {
383389 // Do nothing because this is fine.
384390 } else {
0 commit comments