diff --git a/src/Features/CheckImports/CheckImportReporter.php b/src/Features/CheckImports/CheckImportReporter.php index 607a52fd..7061bb29 100644 --- a/src/Features/CheckImports/CheckImportReporter.php +++ b/src/Features/CheckImports/CheckImportReporter.php @@ -14,7 +14,8 @@ public static function printPsr4(array $psr4Stats) { $output = ''; foreach ($psr4Stats as $composerPath => $psr4) { - $output .= self::formatComposerPath($composerPath).PHP_EOL; + $output .= self::formatComposerPath($composerPath); + $output .= PHP_EOL; $output .= self::formatPsr4Stats($psr4); } @@ -33,14 +34,16 @@ public static function formatComposerPath($composerPath): string * @param array> $psr4 * @return string */ - public static function formatPsr4Stats(array $psr4) + public static function formatPsr4Stats($psr4) { $maxLen = self::getMaxLength($psr4); $result = ''; foreach ($psr4 as $psr4Namespace => $psr4Paths) { foreach ($psr4Paths as $path => $countClasses) { - $result .= self::hyphen().''.self::paddedNamespace($maxLen, $psr4Namespace).' '; - $result .= PHP_EOL.' '.self::blue($countClasses).'file'.($countClasses == 1 ? '' : 's').' found ('.self::green('./'.$path).")".PHP_EOL; + if ($countClasses) { + $result .= self::hyphen().''.self::paddedNamespace($maxLen, $psr4Namespace).' '; + $result .= PHP_EOL.' '.self::blue($countClasses).'file'.($countClasses == 1 ? '' : 's').' found ('.self::green('./'.$path).")".PHP_EOL; + } } } @@ -74,7 +77,7 @@ public static function foldersStats($foldersStats) $total += count($files); } - $output .= self::blue($total).$fileType; + $total && ($output .= self::blue($total).$fileType); foreach ($stats as $dir => $files) { $count = count($files); @@ -158,11 +161,6 @@ public static function paddedNamespace($longest, $namespace) return $namespace.str_repeat(' ', $padLength); } - public static function paddedClassCount($countClasses) - { - return str_pad((string) $countClasses, 3, ' ', STR_PAD_LEFT); - } - public static function header(): string { return ' ⬛️ Overall:'; diff --git a/src/Features/CheckImports/CheckImportsCommand.php b/src/Features/CheckImports/CheckImportsCommand.php index 88fc4124..5d0044e0 100644 --- a/src/Features/CheckImports/CheckImportsCommand.php +++ b/src/Features/CheckImports/CheckImportsCommand.php @@ -39,7 +39,7 @@ class CheckImportsCommand extends Command protected $description = 'Checks the validity of use statements'; - protected $customMsg = 'All imports are Correct! \(^_^)/'; + protected $customMsg = ''; /** * @var array> @@ -101,24 +101,30 @@ public function handle() $psr4Stats = ForPsr4LoadedClasses::check($this->checks, $paramProvider, $fileName, $folder); $bladeStats = BladeFiles::check($this->checks, $paramProvider, $fileName, $folder); - $checkedFilesCount = ChecksOnPsr4Classes::$checkedFilesCount; + $filesCount = ChecksOnPsr4Classes::$checkedFilesCount; + $bladeCount = BladeFiles::$checkedFilesCount; + $refCount = ImportsAnalyzer::$checkedRefCount; $errorPrinter = ErrorPrinter::singleton($this->output); $this->finishCommand($errorPrinter); ErrorCounter::$errors = $errorPrinter->errorsList; $messages = []; - $messages[] = CheckImportReporter::totalImportsMsg(ImportsAnalyzer::$checkedRefCount); + $messages[] = CheckImportReporter::totalImportsMsg($refCount); $messages[] = CheckImportReporter::printPsr4($psr4Stats); $messages[] = CheckImportReporter::header(); - $checkedFilesCount && $messages[] = CheckImportReporter::getFilesStats($checkedFilesCount); - $bladeStats && $messages[] = CheckImportReporter::getBladeStats($bladeStats, BladeFiles::$checkedFilesCount); - $foldersStats && $messages[] = CheckImportReporter::foldersStats($foldersStats); - $messages[] = CheckImportReporter::getRouteStats(count($routeFiles)); + $filesCount && $messages[] = CheckImportReporter::getFilesStats($filesCount); + $bladeCount && $messages[] = CheckImportReporter::getBladeStats($bladeStats, $bladeCount); + $messages[] = CheckImportReporter::foldersStats($foldersStats); + count($routeFiles) && $messages[] = CheckImportReporter::getRouteStats(count($routeFiles)); $messages[] = CheckImportReporter::formatErrorSummary(ErrorCounter::getTotalErrors(), ImportsAnalyzer::$checkedRefCount); $messages[] = CheckImportReporter::format('unused import', ErrorCounter::getExtraImportsCount()); $messages[] = CheckImportReporter::format('wrong import', ErrorCounter::getExtraWrongCount()); $messages[] = CheckImportReporter::format('wrong class reference', ErrorCounter::getWrongUsedClassCount()); + if (! $refCount) { + $messages = ['No imports were found! with filter: "'. ($fileName ?: $folder).'"']; + } + $this->getOutput()->writeln(implode(PHP_EOL, array_filter($messages))); $errorPrinter->printTime(); @@ -132,6 +138,11 @@ public function handle() return $errorPrinter->hasErrors() ? 1 : 0; } + /** + * @param string[] $paths + * @param \Closure $paramProvider + * @return void + */ private function checkFilePaths($paths, $paramProvider) { $checks = $this->checks; @@ -148,11 +159,11 @@ private function checkFilePaths($paths, $paramProvider) } /** - * @param $dirsList + * @param array $dirsList * @param $paramProvider - * @param $file - * @param $folder - * @return array>>> + * @param string $file + * @param string $folder + * @return array>> */ private function checkFolders($dirsList, $paramProvider, $file, $folder) { @@ -184,6 +195,9 @@ private function shouldRequestThanks(): bool return $show; } + /** + * @return \Closure + */ private function getParamProvider() { return function ($tokens) { @@ -193,10 +207,9 @@ private function getParamProvider() }; } - private function reportAll($psr4Stats, $foldersStats, $bladeStats, $routeCounts, $errors) - { - } - + /** + * @return array + */ private function getLaravelFolders() { return [ diff --git a/src/FileReaders/FilePath.php b/src/FileReaders/FilePath.php index 5a38bd9a..bc872788 100644 --- a/src/FileReaders/FilePath.php +++ b/src/FileReaders/FilePath.php @@ -95,6 +95,12 @@ public static function contains($absFilePath, $excludeFile, $excludeFolder) return false; } + /** + * @param $paths + * @param $includeFile + * @param $includeFolder + * @return string[] + */ public static function removeExtraPaths($paths, $includeFile, $includeFolder) { $results = []; diff --git a/src/LaravelPaths/LaravelPaths.php b/src/LaravelPaths/LaravelPaths.php index 84702ae2..3e93f57d 100644 --- a/src/LaravelPaths/LaravelPaths.php +++ b/src/LaravelPaths/LaravelPaths.php @@ -10,6 +10,9 @@ class LaravelPaths { + /** + * @return string[] + */ public static function configDirs() { return array_merge([config_path()], config('microscope.additional_config_paths', []));