From 7d0db07de7469ea66dbb8dce108575823e86ed88 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 20 Feb 2024 20:02:11 +0100 Subject: [PATCH] Refactor Codebase to use modern PHP features using Rector (#225) * Add void Return Type to Tests * Add void return type to package source * Update rector.php * Run Rector * Remove Dead Code * Enable Coding Style Rector --- rector.php | 3 +- src/ClassesFinder.php | 17 +++----- src/Classifier.php | 4 +- src/Classifiers/ControllerClassifier.php | 10 ++--- src/Classifiers/EventListenerClassifier.php | 6 +-- src/Classifiers/MiddlewareClassifier.php | 6 ++- src/Classifiers/ObserverClassifier.php | 18 ++------ src/Classifiers/ResourceClassifier.php | 1 + src/Console/StatsListCommand.php | 42 ++++++++----------- src/Outputs/AsciiTableOutput.php | 31 ++++++-------- src/Project.php | 41 ++++++------------ src/ReflectionClass.php | 8 +--- src/Statistics/NumberOfRoutes.php | 2 +- src/Statistics/ProjectStatistic.php | 36 ++++------------ src/StatsServiceProvider.php | 8 +--- src/ValueObjects/ClassifiedClass.php | 11 ++--- src/ValueObjects/Component.php | 38 ++++------------- tests/ClassesFinderTest.php | 40 +++++++++--------- tests/ClassifierTest.php | 8 ++-- .../BladeComponentClassifierTest.php | 2 +- tests/Classifiers/CommandClassifierTest.php | 2 +- .../Classifiers/ControllerClassifierTest.php | 8 ++-- .../Classifiers/CustomCastClassifierTest.php | 4 +- .../DatabaseFactoryClassifierTest.php | 6 +-- tests/Classifiers/EventClassifierTest.php | 2 +- .../EventListenerClassifierTest.php | 2 +- tests/Classifiers/JobClassifierTest.php | 2 +- .../LivewireComponentClassifierTest.php | 4 +- tests/Classifiers/MailClassifierTest.php | 2 +- .../Classifiers/MiddlewareClassifierTest.php | 6 +-- tests/Classifiers/MigrationClassifierTest.php | 4 +- tests/Classifiers/ModelClassifierTest.php | 2 +- .../NotificationClassifierTest.php | 2 +- .../Classifiers/Nova/ActionClassifierTest.php | 2 +- .../Nova/DashboardClassifierTest.php | 2 +- .../Classifiers/Nova/FilterClassifierTest.php | 2 +- tests/Classifiers/Nova/LensClassifierTest.php | 2 +- .../Nova/ResourceClassifierTest.php | 2 +- tests/Classifiers/NullClassifierTest.php | 2 +- tests/Classifiers/ObserverClassifierTest.php | 2 +- tests/Classifiers/PolicyClassifierTest.php | 4 +- tests/Classifiers/RequestClassifierTest.php | 2 +- tests/Classifiers/ResourceClassifierTest.php | 6 +-- tests/Classifiers/RuleClassifierTest.php | 2 +- tests/Classifiers/SeederClassifierTest.php | 2 +- .../ServiceProviderClassifierTest.php | 2 +- .../BrowserKitTestCaseClassifierTest.php | 2 +- .../Testing/DuskClassifierTest.php | 2 +- .../Testing/PhpUnitClassifierTest.php | 2 +- tests/Console/StatsListCommandTest.php | 16 +++---- tests/Outputs/JsonOutputTest.php | 12 +++--- tests/ProjectTest.php | 14 +++---- tests/ReflectionClassTest.php | 4 +- .../RejectInternalClassesTest.php | 4 +- .../RejectVendorClassesTest.php | 6 +-- tests/Statistics/NumberOfRoutesTest.php | 6 +-- tests/Statistics/ProjectStatisticsTest.php | 20 ++++----- tests/Stubs/Commands/DemoCommand.php | 4 +- tests/Stubs/Controllers/Controller.php | 4 +- tests/Stubs/Controllers/UsersController.php | 2 +- .../EventListeners/DemoEventListener.php | 3 +- .../EventListeners/UserEventSubscriber.php | 3 +- tests/Stubs/Events/DemoEvent.php | 5 ++- tests/Stubs/Jobs/DemoJob.php | 10 ++--- tests/Stubs/Mails/DemoMail.php | 4 +- tests/Stubs/Middleware/DemoMiddleware.php | 1 - tests/Stubs/Middleware/RouteMiddleware.php | 1 - .../2014_10_12_000000_create_users_table.php | 10 ++--- ...12_100000_create_password_resets_table.php | 10 ++--- tests/Stubs/Models/User.php | 2 +- .../Notifications/ServerDownNotification.php | 9 ++-- tests/Stubs/Observers/UserObserver.php | 15 +++---- tests/Stubs/Rules/DemoRule.php | 4 +- tests/Stubs/Seeders/DemoSeeder.php | 4 +- tests/Stubs/ServiceProviders/DemoProvider.php | 8 +--- .../ServiceProviders/EventServiceProvider.php | 4 +- tests/Stubs/Tests/DemoBrowserKit.php | 4 +- tests/Stubs/Tests/DemoDuskTest.php | 2 +- tests/Stubs/Tests/DemoUnitTest.php | 4 +- tests/TestCase.php | 7 +--- tests/ValueObjects/ClassifiedClassTest.php | 12 +++--- tests/ValueObjects/ComponentTest.php | 20 ++++----- 82 files changed, 258 insertions(+), 392 deletions(-) diff --git a/rector.php b/rector.php index 5bf896cb..2186e154 100644 --- a/rector.php +++ b/rector.php @@ -11,7 +11,8 @@ __DIR__ . '/tests', ]) // uncomment to reach your current PHP version - // ->withPhpSets(php80: true) + ->withPhpSets(php80: true) + ->withPreparedSets(deadCode: true, codingStyle: true) ->withRules([ AddVoidReturnTypeWhereNoReturnRector::class, ]); diff --git a/src/ClassesFinder.php b/src/ClassesFinder.php index e7e7ee1a..3007175a 100644 --- a/src/ClassesFinder.php +++ b/src/ClassesFinder.php @@ -26,8 +26,9 @@ public function findAndLoadClasses(): Collection if ($this->isMostLikelyPestTest($file)) { return true; } + require_once $file->getRealPath(); - } catch (Exception $e) { + } catch (Exception) { // } }); @@ -35,9 +36,7 @@ public function findAndLoadClasses(): Collection ob_end_clean(); return collect(get_declared_classes()) - ->reject(function (string $className) { - return Str::startsWith($className, ['SwooleLibrary']); - }); + ->reject(static fn (string $className) => Str::startsWith($className, ['SwooleLibrary'])); } /** @@ -52,9 +51,7 @@ protected function findFilesInProjectPath(): Collection ->name('*.php'); return collect($files) - ->reject(function ($file) use ($excludes) { - return $this->isExcluded($file, $excludes); - }); + ->reject(fn ($file) => $this->isExcluded($file, $excludes)); } /** @@ -62,9 +59,7 @@ protected function findFilesInProjectPath(): Collection */ protected function isExcluded(SplFileInfo $file, Collection $excludes): bool { - return $excludes->contains(function ($exclude) use ($file) { - return Str::startsWith($file->getPathname(), $exclude); - }); + return $excludes->contains(static fn ($exclude) => Str::startsWith($file->getPathname(), $exclude)); } /** @@ -102,7 +97,7 @@ protected function isMostLikelyPestTest(SplFileInfo $file): bool 'afterAll', ]); - if (preg_match("/$methodNames\s*\(/", $fileContent)) { + if (preg_match(sprintf('/%s\s*\(/', $methodNames), $fileContent)) { return true; } diff --git a/src/Classifier.php b/src/Classifier.php index 333d6a07..f9b9100e 100644 --- a/src/Classifier.php +++ b/src/Classifier.php @@ -91,12 +91,12 @@ public function getClassifierForClassInstance(ReflectionClass $class): Classifie $classifierInstance = new $classifier(); if (! $this->implementsContract($classifier)) { - throw new Exception("Classifier {$classifier} does not implement ".ClassifierContract::class.'.'); + throw new Exception(sprintf('Classifier %s does not implement ', $classifier).ClassifierContract::class.'.'); } try { $satisfied = $classifierInstance->satisfies($class); - } catch (Exception $e) { + } catch (Exception) { $satisfied = false; } diff --git a/src/Classifiers/ControllerClassifier.php b/src/Classifiers/ControllerClassifier.php index f7bc9166..5758064f 100644 --- a/src/Classifiers/ControllerClassifier.php +++ b/src/Classifiers/ControllerClassifier.php @@ -18,25 +18,23 @@ public function name(): string public function satisfies(ReflectionClass $class): bool { return collect(app(Router::class)->getRoutes()) - ->reject(function ($route) { + ->reject(static function ($route) { if (method_exists($route, 'getActionName')) { // Laravel return $route->getActionName() === 'Closure'; } - // Lumen return data_get($route, 'action.uses') === null; }) - ->map(function ($route) { + ->map(static function ($route) { if (method_exists($route, 'getController')) { // Laravel try { - return get_class($route->getController()); - } catch (Throwable $e) { + return $route->getController()::class; + } catch (Throwable) { return; } } - // Lumen return Str::before(data_get($route, 'action.uses'), '@'); }) diff --git a/src/Classifiers/EventListenerClassifier.php b/src/Classifiers/EventListenerClassifier.php index 6c8d9a0f..b9fdd57a 100644 --- a/src/Classifiers/EventListenerClassifier.php +++ b/src/Classifiers/EventListenerClassifier.php @@ -23,11 +23,7 @@ public function name(): string public function satisfies(ReflectionClass $class): bool { return collect($this->getEvents()) - ->map(function (array $listeners) { - return collect($listeners)->map(function ($closure) { - return $this->getEventListener($closure); - })->toArray(); - }) + ->map(fn (array $listeners) => collect($listeners)->map(fn ($closure) => $this->getEventListener($closure))->toArray()) ->collapse() ->flatten() ->unique() diff --git a/src/Classifiers/MiddlewareClassifier.php b/src/Classifiers/MiddlewareClassifier.php index eedea7ae..7ed0b90b 100644 --- a/src/Classifiers/MiddlewareClassifier.php +++ b/src/Classifiers/MiddlewareClassifier.php @@ -40,10 +40,12 @@ protected function getMiddlewares(): array { $reflection = new ReflectionProperty($this->httpKernel, 'middleware'); $reflection->setAccessible(true); + $middleware = $reflection->getValue($this->httpKernel); $reflection = new ReflectionProperty($this->httpKernel, 'routeMiddleware'); $reflection->setAccessible(true); + $routeMiddlwares = $reflection->getValue($this->httpKernel); return array_values(array_unique(array_merge($middleware, $routeMiddlwares))); @@ -65,7 +67,7 @@ protected function getHttpKernelInstance() { try { return app(Kernel::class); - } catch (BindingResolutionException $e) { + } catch (BindingResolutionException) { // Lumen return app(); } @@ -89,7 +91,7 @@ private function getRouteMiddlewares(): array $router = $reflection->getValue($this->httpKernel); return collect($router->getRoutes()->getRoutes()) - ->map(fn (Route $route) => $route->middleware()) + ->map(static fn (Route $route) => $route->middleware()) ->flatten() ->unique() ->toArray(); diff --git a/src/Classifiers/ObserverClassifier.php b/src/Classifiers/ObserverClassifier.php index aeef62bf..1512cbcc 100644 --- a/src/Classifiers/ObserverClassifier.php +++ b/src/Classifiers/ObserverClassifier.php @@ -24,22 +24,12 @@ public function name(): string public function satisfies(ReflectionClass $class): bool { return collect($this->getEvents()) - ->filter(function ($_listeners, $event) { - return Str::startsWith($event, 'eloquent.'); - }) - ->map(function ($listeners) { - return collect($listeners)->map(function ($closure) { - return $this->getEventListener($closure); - })->toArray(); - }) + ->filter(static fn ($_listeners, $event) => Str::startsWith($event, 'eloquent.')) + ->map(fn ($listeners) => collect($listeners)->map(fn ($closure) => $this->getEventListener($closure))->toArray()) ->collapse() ->unique() - ->filter(function ($eventListener) { - return is_string($eventListener); - }) - ->filter(function (string $eventListenerSignature) use ($class) { - return Str::contains($eventListenerSignature, $class->getName()); - }) + ->filter(static fn ($eventListener) => is_string($eventListener)) + ->filter(static fn (string $eventListenerSignature) => Str::contains($eventListenerSignature, $class->getName())) ->count() > 0; } diff --git a/src/Classifiers/ResourceClassifier.php b/src/Classifiers/ResourceClassifier.php index 455611a3..a2f55601 100644 --- a/src/Classifiers/ResourceClassifier.php +++ b/src/Classifiers/ResourceClassifier.php @@ -19,6 +19,7 @@ public function satisfies(ReflectionClass $class): bool if ($class->isSubclassOf(JsonResource::class)) { return true; } + return $class->isSubclassOf(ResourceCollection::class); } diff --git a/src/Console/StatsListCommand.php b/src/Console/StatsListCommand.php index b80a9d91..7499af6a 100644 --- a/src/Console/StatsListCommand.php +++ b/src/Console/StatsListCommand.php @@ -34,37 +34,31 @@ class StatsListCommand extends Command /** * Execute the console command. - * - * @return void */ - public function handle() + public function handle(): void { $classes = app(ClassesFinder::class)->findAndLoadClasses(); // Transform Classes into ReflectionClass instances // Remove Classes based on the RejectionStrategy // Remove Classes based on the namespace - $reflectionClasses = $classes->map(function ($class) { - return new ReflectionClass($class); - })->reject(function (ReflectionClass $class) { - return app(config('stats.rejection_strategy', RejectVendorClasses::class)) - ->shouldClassBeRejected($class); - })->unique(function (ReflectionClass $class) { - return $class->getFileName(); - })->reject(function (ReflectionClass $class) { - // Never discard anonymous database migrations - if (Str::contains($class->getName(), 'Migration@anonymous')) { - return false; - } - - foreach (config('stats.ignored_namespaces', []) as $namespace) { - if (Str::startsWith($class->getNamespaceName(), $namespace)) { - return true; + $reflectionClasses = $classes + ->map(static fn ($class) => new ReflectionClass($class)) + ->reject(static fn (ReflectionClass $class) => app(config('stats.rejection_strategy', RejectVendorClasses::class)) + ->shouldClassBeRejected($class)) + ->unique(static fn (ReflectionClass $class) => $class->getFileName()) + ->reject(static function (ReflectionClass $class) { + // Never discard anonymous database migrations + if (Str::contains($class->getName(), 'Migration@anonymous')) { + return false; } - } - - return false; - }); + foreach (config('stats.ignored_namespaces', []) as $namespace) { + if (Str::startsWith($class->getNamespaceName(), $namespace)) { + return true; + } + } + return false; + }); $project = new Project($reflectionClasses); @@ -84,7 +78,7 @@ private function getArrayOfComponentsToDisplay(): array return explode(',', $this->option('components')); } - private function renderOutput(Project $project) + private function renderOutput(Project $project): void { if ($this->option('json') === true) { $json = (new JsonOutput())->render( diff --git a/src/Outputs/AsciiTableOutput.php b/src/Outputs/AsciiTableOutput.php index b6278d74..7ca4002f 100644 --- a/src/Outputs/AsciiTableOutput.php +++ b/src/Outputs/AsciiTableOutput.php @@ -38,7 +38,7 @@ public function __construct(OutputStyle $output) $this->output = $output; } - public function render(Project $project, bool $isVerbose = false, array $filterByComponentName = []) + public function render(Project $project, bool $isVerbose = false, array $filterByComponentName = []): void { $this->isVerbose = $isVerbose; $this->project = $project; @@ -52,19 +52,13 @@ public function render(Project $project, bool $isVerbose = false, array $filterB ->setHeaders(['Name', 'Classes', 'Methods', 'Methods/Class', 'LoC', 'LLoC', 'LLoC/Method']); // Render "Core" components - $this->renderComponents($table, $groupedByComponent->filter(function ($_, $key) { - return $key !== 'Other' && ! Str::contains($key, 'Test'); - })); + $this->renderComponents($table, $groupedByComponent->filter(static fn ($_, $key) => $key !== 'Other' && ! Str::contains($key, 'Test'))); // Render Test components - $this->renderComponents($table, $groupedByComponent->filter(function ($_, $key) { - return Str::contains($key, 'Test'); - })); + $this->renderComponents($table, $groupedByComponent->filter(static fn ($_, $key) => Str::contains($key, 'Test'))); // Render "Other" component - $this->renderComponents($table, $groupedByComponent->filter(function ($_, $key) { - return $key == 'Other'; - })); + $this->renderComponents($table, $groupedByComponent->filter(static fn ($_, $key) => $key === 'Other')); $table->addRow(new TableSeparator); $this->addTotalRow($table); @@ -73,7 +67,7 @@ public function render(Project $project, bool $isVerbose = false, array $filterB $table->render(); } - private function renderComponents(Table $table, Collection $groupedByComponent) + private function renderComponents(Table $table, Collection $groupedByComponent): void { foreach ($groupedByComponent as $componentName => $classifiedClasses) { $component = new Component($componentName, $classifiedClasses); @@ -86,6 +80,7 @@ private function renderComponents(Table $table, Collection $groupedByComponent) foreach ($classifiedClasses as $classifiedClass) { $this->addClassifiedClassTableRow($table, $classifiedClass); } + $table->addRow(new TableSeparator); } } @@ -104,7 +99,7 @@ private function addComponentTableRow(Table $table, Component $component): void ]); } - private function addClassifiedClassTableRow(Table $table, ClassifiedClass $classifiedClass) + private function addClassifiedClassTableRow(Table $table, ClassifiedClass $classifiedClass): void { $table->addRow([ new TableCell( @@ -119,7 +114,7 @@ private function addClassifiedClassTableRow(Table $table, ClassifiedClass $class ]); } - private function addTotalRow(Table $table) + private function addTotalRow(Table $table): void { $table->addRow([ 'name' => 'Total', @@ -132,19 +127,19 @@ private function addTotalRow(Table $table) ]); } - private function addMetaRow(Table $table) + private function addMetaRow(Table $table): void { $table->setFooterTitle(implode(' • ', [ - "Code LLoC: {$this->project->statistic()->getLogicalLinesOfCodeForApplicationCode()}", - "Test LLoC: {$this->project->statistic()->getLogicalLinesOfCodeForTestCode()}", + 'Code LLoC: ' . $this->project->statistic()->getLogicalLinesOfCodeForApplicationCode(), + 'Test LLoC: ' . $this->project->statistic()->getLogicalLinesOfCodeForTestCode(), 'Code/Test Ratio: 1:'.$this->project->statistic()->getApplicationCodeToTestCodeRatio(), 'Routes: '.app(NumberOfRoutes::class)->get(), ])); } - private function rightAlignNumbers(Table $table) + private function rightAlignNumbers(Table $table): void { - for ($i = 1; $i <= 6; $i++) { + for ($i = 1; $i <= 6; ++$i) { $table->setColumnStyle($i, (new TableStyle)->setPadType(STR_PAD_LEFT)); } } diff --git a/src/Project.php b/src/Project.php index ca9eb26e..4c839c4e 100644 --- a/src/Project.php +++ b/src/Project.php @@ -8,13 +8,6 @@ class Project { - /** - * Collection of ReflectionClasses. - * - * @var \Illuminate\Support\Collection <\Wnx\LaravelStats\ReflectionClass> - */ - private $classes; - /** * Collection of ClassifiedClasses. * @@ -22,17 +15,14 @@ class Project */ private $classifiedClasses; - public function __construct(Collection $classes) - { - $this->classes = $classes; - + public function __construct( + private Collection $classes + ) { // Loop through ReflectionClasses and classify them. - $this->classifiedClasses = $classes->map(function (ReflectionClass $reflectionClass) { - return new ClassifiedClass( - $reflectionClass, - app(Classifier::class)->getClassifierForClassInstance($reflectionClass) - ); - }); + $this->classifiedClasses = $this->classes->map(static fn (ReflectionClass $reflectionClass) => new ClassifiedClass( + $reflectionClass, + app(Classifier::class)->getClassifierForClassInstance($reflectionClass) + )); } public function classifiedClasses(): Collection @@ -43,12 +33,8 @@ public function classifiedClasses(): Collection public function classifiedClassesGroupedByComponentName(): Collection { return $this->classifiedClasses() - ->groupBy(function (ClassifiedClass $classifiedClass) { - return $classifiedClass->classifier->name(); - }) - ->sortBy(function ($_, string $componentName) { - return $componentName; - }); + ->groupBy(static fn (ClassifiedClass $classifiedClass) => $classifiedClass->classifier->name()) + ->sortBy(static fn ($_, string $componentName) => $componentName); } public function classifiedClassesGroupedAndFilteredByComponentNames(array $componentNamesToFilter = []): Collection @@ -56,11 +42,10 @@ public function classifiedClassesGroupedAndFilteredByComponentNames(array $compo $shouldCollectionBeFiltered = ! empty(array_filter($componentNamesToFilter)); return $this->classifiedClassesGroupedByComponentName() - ->when($shouldCollectionBeFiltered, function ($components) use ($componentNamesToFilter) { - return $components->filter(function ($_item, $key) use ($componentNamesToFilter) { - return in_array($key, $componentNamesToFilter); - }); - }); + ->when( + $shouldCollectionBeFiltered, + static fn (Collection $components) => $components->filter(static fn ($_item, string $key) => in_array($key, $componentNamesToFilter)) + ); } public function statistic(): ProjectStatistic diff --git a/src/ReflectionClass.php b/src/ReflectionClass.php index 2a307754..6907ad80 100644 --- a/src/ReflectionClass.php +++ b/src/ReflectionClass.php @@ -25,9 +25,7 @@ public function isVendorProvided(): bool public function usesTrait(string $name): bool { return collect($this->getTraits()) - ->contains(function (NativeReflectionClass $trait) use ($name) { - return $trait->name == $name; - }); + ->contains(static fn (NativeReflectionClass $trait) => $trait->name == $name); } /** @@ -37,8 +35,6 @@ public function usesTrait(string $name): bool public function getDefinedMethods(): Collection { return collect($this->getMethods()) - ->filter(function (ReflectionMethod $method) { - return $method->getFileName() === $this->getFileName(); - }); + ->filter(fn (ReflectionMethod $method) => $method->getFileName() === $this->getFileName()); } } diff --git a/src/Statistics/NumberOfRoutes.php b/src/Statistics/NumberOfRoutes.php index 65878300..091de94f 100644 --- a/src/Statistics/NumberOfRoutes.php +++ b/src/Statistics/NumberOfRoutes.php @@ -11,7 +11,7 @@ public function get(): int { try { return collect(app(Router::class)->getRoutes())->count(); - } catch (Exception $e) { + } catch (Exception) { return 0; } } diff --git a/src/Statistics/ProjectStatistic.php b/src/Statistics/ProjectStatistic.php index 6d540ff7..519a2f1a 100644 --- a/src/Statistics/ProjectStatistic.php +++ b/src/Statistics/ProjectStatistic.php @@ -7,11 +7,6 @@ class ProjectStatistic { - /** - * @var \Wnx\LaravelStats\Project - */ - private $project; - /** * @var int */ @@ -42,9 +37,8 @@ class ProjectStatistic */ private $logicalLinesOfCodePerMethod; - public function __construct(Project $project) + public function __construct(private Project $project) { - $this->project = $project; } public function getNumberOfClasses(): int @@ -59,9 +53,7 @@ public function getNumberOfClasses(): int public function getNumberOfMethods(): int { if ($this->numberOfMethods === null) { - $this->numberOfMethods = $this->project->classifiedClasses()->sum(function (ClassifiedClass $class) { - return $class->getNumberOfMethods(); - }); + $this->numberOfMethods = $this->project->classifiedClasses()->sum(static fn (ClassifiedClass $class) => $class->getNumberOfMethods()); } return $this->numberOfMethods; @@ -79,9 +71,7 @@ public function getNumberOfMethodsPerClass(): float public function getLinesOfCode(): int { if ($this->linesOfCode === null) { - $this->linesOfCode = $this->project->classifiedClasses()->sum(function (ClassifiedClass $class) { - return $class->getLines(); - }); + $this->linesOfCode = $this->project->classifiedClasses()->sum(static fn (ClassifiedClass $class) => $class->getLines()); } return $this->linesOfCode; @@ -90,9 +80,7 @@ public function getLinesOfCode(): int public function getLogicalLinesOfCode(): float { if ($this->logicalLinesOfCode === null) { - $this->logicalLinesOfCode = $this->project->classifiedClasses()->sum(function (ClassifiedClass $class) { - return $class->getLogicalLinesOfCode(); - }); + $this->logicalLinesOfCode = $this->project->classifiedClasses()->sum(static fn (ClassifiedClass $class) => $class->getLogicalLinesOfCode()); } return $this->logicalLinesOfCode; @@ -116,12 +104,8 @@ public function getLogicalLinesOfCodeForApplicationCode(): float return $this ->project ->classifiedClasses() - ->filter(function (ClassifiedClass $classifiedClass) { - return $classifiedClass->classifier->countsTowardsApplicationCode(); - }) - ->sum(function (ClassifiedClass $class) { - return $class->getLogicalLinesOfCode(); - }); + ->filter(static fn (ClassifiedClass $classifiedClass) => $classifiedClass->classifier->countsTowardsApplicationCode()) + ->sum(static fn (ClassifiedClass $class) => $class->getLogicalLinesOfCode()); } public function getLogicalLinesOfCodeForTestCode(): float @@ -129,12 +113,8 @@ public function getLogicalLinesOfCodeForTestCode(): float return $this ->project ->classifiedClasses() - ->filter(function (ClassifiedClass $classifiedClass) { - return $classifiedClass->classifier->countsTowardsTests(); - }) - ->sum(function (ClassifiedClass $class) { - return $class->getLogicalLinesOfCode(); - }); + ->filter(static fn (ClassifiedClass $classifiedClass) => $classifiedClass->classifier->countsTowardsTests()) + ->sum(static fn (ClassifiedClass $class) => $class->getLogicalLinesOfCode()); } public function getApplicationCodeToTestCodeRatio(): float diff --git a/src/StatsServiceProvider.php b/src/StatsServiceProvider.php index 7196e6bf..e67284b5 100644 --- a/src/StatsServiceProvider.php +++ b/src/StatsServiceProvider.php @@ -14,10 +14,8 @@ class StatsServiceProvider extends ServiceProvider /** * Bootstrap the application events. - * - * @return void */ - public function boot() + public function boot(): void { if ($this->app->runningInConsole()) { $this->publishes([ @@ -28,10 +26,8 @@ public function boot() /** * Register the service provider. - * - * @return void */ - public function register() + public function register(): void { $this->mergeConfigFrom($this->config, 'stats'); diff --git a/src/ValueObjects/ClassifiedClass.php b/src/ValueObjects/ClassifiedClass.php index 99fe18c2..bcab9625 100644 --- a/src/ValueObjects/ClassifiedClass.php +++ b/src/ValueObjects/ClassifiedClass.php @@ -2,6 +2,7 @@ namespace Wnx\LaravelStats\ValueObjects; +use ReflectionMethod; use Wnx\LaravelStats\ReflectionClass; use SebastianBergmann\PHPLOC\Analyser; use Wnx\LaravelStats\Contracts\Classifier; @@ -72,9 +73,7 @@ public function getNumberOfPublicMethods(): int { if ($this->numberOfPublicMethods === null) { $this->numberOfPublicMethods = $this->reflectionClass->getDefinedMethods() - ->filter(function (\ReflectionMethod $method) { - return $method->isPublic(); - })->count(); + ->filter(static fn (ReflectionMethod $method) => $method->isPublic())->count(); } return $this->numberOfPublicMethods; @@ -84,9 +83,7 @@ public function getNumberOfNonPublicMethods(): int { if ($this->numberOfNonPublicMethods === null) { $this->numberOfNonPublicMethods = $this->reflectionClass->getDefinedMethods() - ->filter(function (\ReflectionMethod $method) { - return ! $method->isPublic(); - })->count(); + ->filter(static fn (ReflectionMethod $method) => ! $method->isPublic())->count(); } return $this->numberOfNonPublicMethods; @@ -125,7 +122,7 @@ public function getLogicalLinesOfCodePerMethod(): float { if ($this->logicalLinesOfCodePerMethod === null) { if ($this->getNumberOfMethods() === 0) { - $this->logicalLinesOfCodePerMethod = $this->logicalLinesOfCodePerMethod = 0; + $this->logicalLinesOfCodePerMethod = 0; } else { $this->logicalLinesOfCodePerMethod = round($this->getLogicalLinesOfCode() / $this->getNumberOfMethods(), 2); } diff --git a/src/ValueObjects/Component.php b/src/ValueObjects/Component.php index 69786b27..7aefec95 100644 --- a/src/ValueObjects/Component.php +++ b/src/ValueObjects/Component.php @@ -6,16 +6,6 @@ class Component { - /** - * @var string - */ - public $name; - - /** - * @var \Illuminate\Support\Collection - */ - private $classifiedClasses; - /** * @var int */ @@ -56,10 +46,10 @@ class Component */ private $logicalLinesOfCodePerMethod; - public function __construct(string $name, Collection $classifiedClasses) - { - $this->name = $name; - $this->classifiedClasses = $classifiedClasses; + public function __construct( + public string $name, + private Collection $classifiedClasses + ) { } public function getNumberOfClasses(): int @@ -74,9 +64,7 @@ public function getNumberOfClasses(): int public function getNumberOfMethods(): int { if ($this->numberOfMethods === null) { - $this->numberOfMethods = $this->classifiedClasses->sum(function (ClassifiedClass $class) { - return $class->getNumberOfMethods(); - }); + $this->numberOfMethods = $this->classifiedClasses->sum(static fn (ClassifiedClass $class) => $class->getNumberOfMethods()); } return $this->numberOfMethods; @@ -85,9 +73,7 @@ public function getNumberOfMethods(): int public function getNumberOfPublicMethods(): int { if ($this->numberOfPublicMethods === null) { - $this->numberOfPublicMethods = $this->classifiedClasses->sum(function (ClassifiedClass $class) { - return $class->getNumberOfPublicMethods(); - }); + $this->numberOfPublicMethods = $this->classifiedClasses->sum(static fn (ClassifiedClass $class) => $class->getNumberOfPublicMethods()); } return $this->numberOfPublicMethods; @@ -96,9 +82,7 @@ public function getNumberOfPublicMethods(): int public function getNumberOfNonPublicMethods(): int { if ($this->numberOfNonPublicMethods === null) { - $this->numberOfNonPublicMethods = $this->classifiedClasses->sum(function (ClassifiedClass $class) { - return $class->getNumberOfNonPublicMethods(); - }); + $this->numberOfNonPublicMethods = $this->classifiedClasses->sum(static fn (ClassifiedClass $class) => $class->getNumberOfNonPublicMethods()); } return $this->numberOfNonPublicMethods; @@ -116,9 +100,7 @@ public function getNumberOfMethodsPerClass(): float public function getLinesOfCode(): int { if ($this->linesOfCode === null) { - $this->linesOfCode = $this->classifiedClasses->sum(function (ClassifiedClass $class) { - return $class->getLines(); - }); + $this->linesOfCode = $this->classifiedClasses->sum(static fn (ClassifiedClass $class) => $class->getLines()); } return $this->linesOfCode; @@ -127,9 +109,7 @@ public function getLinesOfCode(): int public function getLogicalLinesOfCode(): float { if ($this->logicalLinesOfCode === null) { - $this->logicalLinesOfCode = $this->classifiedClasses->sum(function (ClassifiedClass $class) { - return $class->getLogicalLinesOfCode(); - }); + $this->logicalLinesOfCode = $this->classifiedClasses->sum(static fn (ClassifiedClass $class) => $class->getLogicalLinesOfCode()); } return $this->logicalLinesOfCode; diff --git a/tests/ClassesFinderTest.php b/tests/ClassesFinderTest.php index c48d18ae..0518a99e 100644 --- a/tests/ClassesFinderTest.php +++ b/tests/ClassesFinderTest.php @@ -6,7 +6,7 @@ class ClassesFinderTest extends TestCase { - public function setUp() : void + protected function setUp() : void { parent::setUp(); @@ -27,117 +27,117 @@ public function setUp() : void } /** @test */ - public function it_finds_controllers() + public function it_finds_controllers(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Controllers\ProjectsController::class)); $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Controllers\Controller::class)); } /** @test */ - public function it_finds_commands() + public function it_finds_commands(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Commands\DemoCommand::class)); } /** @test */ - public function it_finds_events() + public function it_finds_events(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Events\DemoEvent::class)); } /** @test */ - public function it_finds_jobs() + public function it_finds_jobs(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Jobs\DemoJob::class)); } /** @test */ - public function it_finds_mails() + public function it_finds_mails(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Mails\DemoMail::class)); } /** @test */ - public function it_finds_middleware() + public function it_finds_middleware(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Middleware\DemoMiddleware::class)); } /** @test */ - public function it_finds_route_middleware() + public function it_finds_route_middleware(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Middleware\RouteMiddleware::class)); } /** @test */ - public function it_finds_migrations() + public function it_finds_migrations(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Migrations\CreatePasswordResetsTable::class)); } /** @test */ - public function it_finds_models() + public function it_finds_models(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Models\Project::class)); } /** @test */ - public function it_finds_notifications() + public function it_finds_notifications(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Notifications\ServerDownNotification::class)); } /** @test */ - public function it_finds_policies() + public function it_finds_policies(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Policies\DemoPolicy::class)); } /** @test */ - public function it_finds_request() + public function it_finds_request(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Requests\UserRequest::class)); } /** @test */ - public function it_finds_resources() + public function it_finds_resources(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Resources\DemoResource::class)); } /** @test */ - public function it_finds_rules() + public function it_finds_rules(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Rules\DemoRule::class)); } /** @test */ - public function it_finds_seeders() + public function it_finds_seeders(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\Seeders\DemoSeeder::class)); } /** @test */ - public function it_finds_service_providers() + public function it_finds_service_providers(): void { $this->assertTrue($this->classes->contains(\Wnx\LaravelStats\Tests\Stubs\ServiceProviders\DemoProvider::class)); } /** @test */ - public function it_includes_native_php_classes() + public function it_includes_native_php_classes(): void { $this->assertTrue($this->classes->contains('stdClass')); $this->assertTrue($this->classes->contains('Exception')); } /** @test */ - public function it_ignores_exluded_file() + public function it_ignores_exluded_file(): void { $this->assertFalse($this->classes->contains('ExcludedFile')); } /** @test */ - public function it_includes_vendored_classes() + public function it_includes_vendored_classes(): void { $this->assertTrue($this->classes->contains(\Symfony\Component\Finder\Finder::class)); } diff --git a/tests/ClassifierTest.php b/tests/ClassifierTest.php index b6995dc7..1effc771 100644 --- a/tests/ClassifierTest.php +++ b/tests/ClassifierTest.php @@ -18,7 +18,7 @@ public function getClassifier($args) } /** @test */ - public function it_returns_instance_of_null_classifier_if_given_class_could_not_be_associated_with_a_component() + public function it_returns_instance_of_null_classifier_if_given_class_could_not_be_associated_with_a_component(): void { $this->assertInstanceOf( NullClassifier::class, @@ -30,7 +30,7 @@ public function it_returns_instance_of_null_classifier_if_given_class_could_not_ } /** @test */ - public function it_returns_instance_of_custom_classifier_if_the_custom_classifier_has_been_registered_correctly() + public function it_returns_instance_of_custom_classifier_if_the_custom_classifier_has_been_registered_correctly(): void { config()->set('stats.custom_component_classifier', [ MyCustomComponentClassifier::class, @@ -45,7 +45,7 @@ public function it_returns_instance_of_custom_classifier_if_the_custom_classifie } /** @test */ - public function it_returns_an_instance_of_null_classifier_if_during_the_satisfy_check_an_exception_is_thrown() + public function it_returns_an_instance_of_null_classifier_if_during_the_satisfy_check_an_exception_is_thrown(): void { config()->set('stats.custom_component_classifier', [ ThrowExceptionCustomComponentClassifier::class, @@ -60,7 +60,7 @@ public function it_returns_an_instance_of_null_classifier_if_during_the_satisfy_ } /** @test */ - public function it_throws_an_exception_if_a_custom_component_classifier_does_not_follow_the_contract() + public function it_throws_an_exception_if_a_custom_component_classifier_does_not_follow_the_contract(): void { $this->expectException(\Exception::class); diff --git a/tests/Classifiers/BladeComponentClassifierTest.php b/tests/Classifiers/BladeComponentClassifierTest.php index df7fb153..96f0d852 100644 --- a/tests/Classifiers/BladeComponentClassifierTest.php +++ b/tests/Classifiers/BladeComponentClassifierTest.php @@ -10,7 +10,7 @@ class BladeComponentClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_blade_component() + public function it_returns_true_if_given_class_is_a_blade_component(): void { $this->assertTrue( (new BladeComponentClassifier())->satisfies( diff --git a/tests/Classifiers/CommandClassifierTest.php b/tests/Classifiers/CommandClassifierTest.php index 699c5cda..c15d8805 100644 --- a/tests/Classifiers/CommandClassifierTest.php +++ b/tests/Classifiers/CommandClassifierTest.php @@ -10,7 +10,7 @@ class CommandClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_artisan_command_is_passed_to_satisfy_method() + public function it_returns_true_if_artisan_command_is_passed_to_satisfy_method(): void { $this->assertTrue( (new CommandClassifier())->satisfies( diff --git a/tests/Classifiers/ControllerClassifierTest.php b/tests/Classifiers/ControllerClassifierTest.php index 800f78ee..7c97c5d5 100644 --- a/tests/Classifiers/ControllerClassifierTest.php +++ b/tests/Classifiers/ControllerClassifierTest.php @@ -12,7 +12,7 @@ class ControllerClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_controller_which_is_associated_with_a_registered_route() + public function it_returns_true_if_given_class_is_a_controller_which_is_associated_with_a_registered_route(): void { Route::get('users', 'Wnx\LaravelStats\Tests\Stubs\Controllers\UsersController@index'); @@ -24,7 +24,7 @@ public function it_returns_true_if_given_class_is_a_controller_which_is_associat } /** @test */ - public function it_returns_false_if_given_class_is_not_associated_with_a_registered_route() + public function it_returns_false_if_given_class_is_not_associated_with_a_registered_route(): void { $this->assertFalse( (new ControllerClassifier())->satisfies( @@ -34,7 +34,7 @@ public function it_returns_false_if_given_class_is_not_associated_with_a_registe } /** @test */ - public function it_does_not_throw_an_exception_if_controller_for_a_route_could_not_be_found() + public function it_does_not_throw_an_exception_if_controller_for_a_route_could_not_be_found(): void { Route::get('users', 'Wnx\LaravelStats\Tests\Stubs\Controllers\NotFoundController@index'); @@ -46,7 +46,7 @@ public function it_does_not_throw_an_exception_if_controller_for_a_route_could_n } /** @test */ - public function it_returns_true_when_controller_does_not_extend_laravels_base_controller() + public function it_returns_true_when_controller_does_not_extend_laravels_base_controller(): void { Route::get('projects', 'Wnx\LaravelStats\Tests\Stubs\Controllers\ProjectsController@index'); diff --git a/tests/Classifiers/CustomCastClassifierTest.php b/tests/Classifiers/CustomCastClassifierTest.php index 299e099b..6302e956 100644 --- a/tests/Classifiers/CustomCastClassifierTest.php +++ b/tests/Classifiers/CustomCastClassifierTest.php @@ -11,7 +11,7 @@ class CustomCastClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_custom_cast() + public function it_returns_true_if_given_class_is_a_custom_cast(): void { $this->assertTrue( (new CustomCastClassifier())->satisfies( @@ -21,7 +21,7 @@ public function it_returns_true_if_given_class_is_a_custom_cast() } /** @test */ - public function it_returns_true_if_given_class_is_a_custom_inbound_cast() + public function it_returns_true_if_given_class_is_a_custom_inbound_cast(): void { $this->assertTrue( (new CustomCastClassifier())->satisfies( diff --git a/tests/Classifiers/DatabaseFactoryClassifierTest.php b/tests/Classifiers/DatabaseFactoryClassifierTest.php index 12a54ead..84bba4cd 100644 --- a/tests/Classifiers/DatabaseFactoryClassifierTest.php +++ b/tests/Classifiers/DatabaseFactoryClassifierTest.php @@ -10,7 +10,7 @@ class DatabaseFactoryClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_database_factory_is_passed_to_satisfy_method() + public function it_returns_true_if_database_factory_is_passed_to_satisfy_method(): void { $this->assertTrue( (new DatabaseFactoryClassifier())->satisfies( @@ -20,13 +20,13 @@ public function it_returns_true_if_database_factory_is_passed_to_satisfy_method( } /** @test */ - public function it_does_not_count_database_factory_againt_app_code() + public function it_does_not_count_database_factory_againt_app_code(): void { $this->assertFalse((new DatabaseFactoryClassifier())->countsTowardsApplicationCode()); } /** @test */ - public function it_does_not_count_database_factor_against_test_code() + public function it_does_not_count_database_factor_against_test_code(): void { $this->assertFalse((new DatabaseFactoryClassifier())->countsTowardsTests()); } diff --git a/tests/Classifiers/EventClassifierTest.php b/tests/Classifiers/EventClassifierTest.php index 2123feab..3bb557e6 100644 --- a/tests/Classifiers/EventClassifierTest.php +++ b/tests/Classifiers/EventClassifierTest.php @@ -10,7 +10,7 @@ class EventClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_an_event_class() + public function it_returns_true_if_given_class_is_an_event_class(): void { $this->assertTrue( (new EventClassifier())->satisfies( diff --git a/tests/Classifiers/EventListenerClassifierTest.php b/tests/Classifiers/EventListenerClassifierTest.php index 96cf4800..86bad0e2 100644 --- a/tests/Classifiers/EventListenerClassifierTest.php +++ b/tests/Classifiers/EventListenerClassifierTest.php @@ -11,7 +11,7 @@ class EventListenerClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_an_event_listener() + public function it_returns_true_if_given_class_is_an_event_listener(): void { $this->assertTrue( (new EventListenerClassifier())->satisfies( diff --git a/tests/Classifiers/JobClassifierTest.php b/tests/Classifiers/JobClassifierTest.php index 40ab68f3..29169bf9 100644 --- a/tests/Classifiers/JobClassifierTest.php +++ b/tests/Classifiers/JobClassifierTest.php @@ -10,7 +10,7 @@ class JobClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_job() + public function it_returns_true_if_given_class_is_a_job(): void { $this->assertTrue( (new JobClassifier())->satisfies( diff --git a/tests/Classifiers/LivewireComponentClassifierTest.php b/tests/Classifiers/LivewireComponentClassifierTest.php index e5c54d2f..efba7298 100644 --- a/tests/Classifiers/LivewireComponentClassifierTest.php +++ b/tests/Classifiers/LivewireComponentClassifierTest.php @@ -11,7 +11,7 @@ class LivewireComponentClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_livewire_component() + public function it_returns_true_if_given_class_is_a_livewire_component(): void { $this->assertTrue( (new LivewireComponentClassifier())->satisfies( @@ -21,7 +21,7 @@ public function it_returns_true_if_given_class_is_a_livewire_component() } /** @test */ - public function it_returns_true_if_given_class_is_a_livewire_component_which_is_associated_with_a_registered_route() + public function it_returns_true_if_given_class_is_a_livewire_component_which_is_associated_with_a_registered_route(): void { Route::get('users', StubLivewireComponent::class); diff --git a/tests/Classifiers/MailClassifierTest.php b/tests/Classifiers/MailClassifierTest.php index 0f411614..db592a85 100644 --- a/tests/Classifiers/MailClassifierTest.php +++ b/tests/Classifiers/MailClassifierTest.php @@ -10,7 +10,7 @@ class MailClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_mailable() + public function it_returns_true_if_given_class_is_a_mailable(): void { $this->assertTrue( (new MailClassifier())->satisfies( diff --git a/tests/Classifiers/MiddlewareClassifierTest.php b/tests/Classifiers/MiddlewareClassifierTest.php index c19959b2..a1f4128c 100644 --- a/tests/Classifiers/MiddlewareClassifierTest.php +++ b/tests/Classifiers/MiddlewareClassifierTest.php @@ -20,9 +20,7 @@ class MiddlewareClassifierTest extends TestCase */ protected function usesMiddlewareRoutes($router) { - $router->get('/demo', function () { - return 'Hello World'; - })->middleware(DemoMiddleware::class); + $router->get('/demo', static fn () => 'Hello World')->middleware(DemoMiddleware::class); } #[Test] @@ -37,7 +35,7 @@ public function it_returns_true_if_given_class_is_a_middleware(): void } /** @test */ - public function it_returns_true_if_given_class_is_a_route_middleware() + public function it_returns_true_if_given_class_is_a_route_middleware(): void { $this->assertTrue( (new MiddlewareClassifier())->satisfies( diff --git a/tests/Classifiers/MigrationClassifierTest.php b/tests/Classifiers/MigrationClassifierTest.php index 456700e0..923e1a82 100644 --- a/tests/Classifiers/MigrationClassifierTest.php +++ b/tests/Classifiers/MigrationClassifierTest.php @@ -10,7 +10,7 @@ class MigrationClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_migration() + public function it_returns_true_if_given_class_is_a_migration(): void { require_once __DIR__.'/../Stubs/Migrations/2014_10_12_100000_create_password_resets_table.php'; @@ -22,7 +22,7 @@ public function it_returns_true_if_given_class_is_a_migration() } /** @test */ - public function it_detects_anonymous_migrations() + public function it_detects_anonymous_migrations(): void { $createUsersTableMigration = require __DIR__.'/../Stubs/Migrations/2014_10_12_000000_create_users_table.php'; diff --git a/tests/Classifiers/ModelClassifierTest.php b/tests/Classifiers/ModelClassifierTest.php index 66e1d75d..230b7c87 100644 --- a/tests/Classifiers/ModelClassifierTest.php +++ b/tests/Classifiers/ModelClassifierTest.php @@ -10,7 +10,7 @@ class ModelClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_an_eloquent_model() + public function it_returns_true_if_given_class_is_an_eloquent_model(): void { $this->assertTrue( (new ModelClassifier())->satisfies( diff --git a/tests/Classifiers/NotificationClassifierTest.php b/tests/Classifiers/NotificationClassifierTest.php index e43e2716..7c014b08 100644 --- a/tests/Classifiers/NotificationClassifierTest.php +++ b/tests/Classifiers/NotificationClassifierTest.php @@ -10,7 +10,7 @@ class NotificationClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_notification() + public function it_returns_true_if_given_class_is_a_notification(): void { $this->assertTrue( (new NotificationClassifier())->satisfies( diff --git a/tests/Classifiers/Nova/ActionClassifierTest.php b/tests/Classifiers/Nova/ActionClassifierTest.php index d636ba52..78a43974 100644 --- a/tests/Classifiers/Nova/ActionClassifierTest.php +++ b/tests/Classifiers/Nova/ActionClassifierTest.php @@ -10,7 +10,7 @@ class ActionClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_nova_action() + public function it_returns_true_if_given_class_is_a_nova_action(): void { $this->assertTrue( (new ActionClassifier())->satisfies( diff --git a/tests/Classifiers/Nova/DashboardClassifierTest.php b/tests/Classifiers/Nova/DashboardClassifierTest.php index da9c0581..de77b3be 100644 --- a/tests/Classifiers/Nova/DashboardClassifierTest.php +++ b/tests/Classifiers/Nova/DashboardClassifierTest.php @@ -10,7 +10,7 @@ class DashboardClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_nova_dashboard() + public function it_returns_true_if_given_class_is_a_nova_dashboard(): void { $this->assertTrue( (new DashboardClassifier())->satisfies( diff --git a/tests/Classifiers/Nova/FilterClassifierTest.php b/tests/Classifiers/Nova/FilterClassifierTest.php index 1f9bdda6..8611ff80 100644 --- a/tests/Classifiers/Nova/FilterClassifierTest.php +++ b/tests/Classifiers/Nova/FilterClassifierTest.php @@ -10,7 +10,7 @@ class FilterClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_nova_filter() + public function it_returns_true_if_given_class_is_a_nova_filter(): void { $this->assertTrue( (new FilterClassifier())->satisfies( diff --git a/tests/Classifiers/Nova/LensClassifierTest.php b/tests/Classifiers/Nova/LensClassifierTest.php index 86b1d2c9..e13e4b2d 100644 --- a/tests/Classifiers/Nova/LensClassifierTest.php +++ b/tests/Classifiers/Nova/LensClassifierTest.php @@ -10,7 +10,7 @@ class LensClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_nova_lens() + public function it_returns_true_if_given_class_is_a_nova_lens(): void { $this->assertTrue( (new LensClassifier())->satisfies( diff --git a/tests/Classifiers/Nova/ResourceClassifierTest.php b/tests/Classifiers/Nova/ResourceClassifierTest.php index a089c55e..d19524f7 100644 --- a/tests/Classifiers/Nova/ResourceClassifierTest.php +++ b/tests/Classifiers/Nova/ResourceClassifierTest.php @@ -10,7 +10,7 @@ class ResourceClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_nova_resource() + public function it_returns_true_if_given_class_is_a_nova_resource(): void { $this->assertTrue( (new ResourceClassifier())->satisfies( diff --git a/tests/Classifiers/NullClassifierTest.php b/tests/Classifiers/NullClassifierTest.php index 22412d48..e3614f61 100644 --- a/tests/Classifiers/NullClassifierTest.php +++ b/tests/Classifiers/NullClassifierTest.php @@ -10,7 +10,7 @@ class NullClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_artisan_command_is_passed_to_satisfy_method() + public function it_returns_true_if_artisan_command_is_passed_to_satisfy_method(): void { $this->assertTrue( (new CommandClassifier())->satisfies( diff --git a/tests/Classifiers/ObserverClassifierTest.php b/tests/Classifiers/ObserverClassifierTest.php index 001e3a8b..8dc91852 100644 --- a/tests/Classifiers/ObserverClassifierTest.php +++ b/tests/Classifiers/ObserverClassifierTest.php @@ -11,7 +11,7 @@ class ObserverClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_registered_observer() + public function it_returns_true_if_given_class_is_a_registered_observer(): void { User::observe(UserObserver::class); diff --git a/tests/Classifiers/PolicyClassifierTest.php b/tests/Classifiers/PolicyClassifierTest.php index 45c342dd..1341d308 100644 --- a/tests/Classifiers/PolicyClassifierTest.php +++ b/tests/Classifiers/PolicyClassifierTest.php @@ -12,7 +12,7 @@ class PolicyClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_policy_which_has_been_registered_in_the_application() + public function it_returns_true_if_given_class_is_a_policy_which_has_been_registered_in_the_application(): void { Gate::policy(Project::class, DemoPolicy::class); @@ -24,7 +24,7 @@ public function it_returns_true_if_given_class_is_a_policy_which_has_been_regist } /** @test */ - public function it_returns_false_if_given_class_is_a_policy_but_has_not_been_registered_to_a_model() + public function it_returns_false_if_given_class_is_a_policy_but_has_not_been_registered_to_a_model(): void { $this->assertFalse( (new PolicyClassifier())->satisfies( diff --git a/tests/Classifiers/RequestClassifierTest.php b/tests/Classifiers/RequestClassifierTest.php index 486940b5..8c2c9596 100644 --- a/tests/Classifiers/RequestClassifierTest.php +++ b/tests/Classifiers/RequestClassifierTest.php @@ -10,7 +10,7 @@ class RequestClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_laravel_form_request() + public function it_returns_true_if_given_class_is_a_laravel_form_request(): void { $this->assertTrue( (new RequestClassifier())->satisfies( diff --git a/tests/Classifiers/ResourceClassifierTest.php b/tests/Classifiers/ResourceClassifierTest.php index 1180da14..522545b7 100644 --- a/tests/Classifiers/ResourceClassifierTest.php +++ b/tests/Classifiers/ResourceClassifierTest.php @@ -12,7 +12,7 @@ class ResourceClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_an_api_resource() + public function it_returns_true_if_given_class_is_an_api_resource(): void { $this->assertTrue( (new ResourceClassifier())->satisfies( @@ -22,7 +22,7 @@ public function it_returns_true_if_given_class_is_an_api_resource() } /** @test */ - public function it_returns_true_if_given_class_is_a_json_resoure() + public function it_returns_true_if_given_class_is_a_json_resoure(): void { $this->assertTrue( (new ResourceClassifier())->satisfies( @@ -32,7 +32,7 @@ public function it_returns_true_if_given_class_is_a_json_resoure() } /** @test */ - public function it_returns_true_if_given_class_is_a_resource_collection() + public function it_returns_true_if_given_class_is_a_resource_collection(): void { $this->assertTrue( (new ResourceClassifier())->satisfies( diff --git a/tests/Classifiers/RuleClassifierTest.php b/tests/Classifiers/RuleClassifierTest.php index fb974d46..0f8f81fc 100644 --- a/tests/Classifiers/RuleClassifierTest.php +++ b/tests/Classifiers/RuleClassifierTest.php @@ -10,7 +10,7 @@ class RuleClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_validation_rule() + public function it_returns_true_if_given_class_is_a_validation_rule(): void { $this->assertTrue( (new RuleClassifier())->satisfies( diff --git a/tests/Classifiers/SeederClassifierTest.php b/tests/Classifiers/SeederClassifierTest.php index ff4ab457..aba1379b 100644 --- a/tests/Classifiers/SeederClassifierTest.php +++ b/tests/Classifiers/SeederClassifierTest.php @@ -10,7 +10,7 @@ class SeederClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_database_seeder() + public function it_returns_true_if_given_class_is_a_database_seeder(): void { $this->assertTrue( (new SeederClassifier())->satisfies( diff --git a/tests/Classifiers/ServiceProviderClassifierTest.php b/tests/Classifiers/ServiceProviderClassifierTest.php index 462e84b0..31524b82 100644 --- a/tests/Classifiers/ServiceProviderClassifierTest.php +++ b/tests/Classifiers/ServiceProviderClassifierTest.php @@ -10,7 +10,7 @@ class ServiceProviderClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_class_is_a_service_provider() + public function it_returns_true_if_given_class_is_a_service_provider(): void { $this->assertTrue( (new ServiceProviderClassifier())->satisfies( diff --git a/tests/Classifiers/Testing/BrowserKitTestCaseClassifierTest.php b/tests/Classifiers/Testing/BrowserKitTestCaseClassifierTest.php index cb9f26ca..c47a9308 100644 --- a/tests/Classifiers/Testing/BrowserKitTestCaseClassifierTest.php +++ b/tests/Classifiers/Testing/BrowserKitTestCaseClassifierTest.php @@ -10,7 +10,7 @@ class BrowserKitTestCaseClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_test_is_a_browser_kit_test() + public function it_returns_true_if_given_test_is_a_browser_kit_test(): void { $this->assertTrue( (new BrowserKitTestClassifier())->satisfies( diff --git a/tests/Classifiers/Testing/DuskClassifierTest.php b/tests/Classifiers/Testing/DuskClassifierTest.php index f0f71618..8f48d35b 100644 --- a/tests/Classifiers/Testing/DuskClassifierTest.php +++ b/tests/Classifiers/Testing/DuskClassifierTest.php @@ -10,7 +10,7 @@ class DuskClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_test_is_a_dusk_test() + public function it_returns_true_if_given_test_is_a_dusk_test(): void { $this->assertTrue( (new DuskClassifier())->satisfies( diff --git a/tests/Classifiers/Testing/PhpUnitClassifierTest.php b/tests/Classifiers/Testing/PhpUnitClassifierTest.php index 5ea0eda7..b8280fc8 100644 --- a/tests/Classifiers/Testing/PhpUnitClassifierTest.php +++ b/tests/Classifiers/Testing/PhpUnitClassifierTest.php @@ -10,7 +10,7 @@ class PhpUnitClassifierTest extends TestCase { /** @test */ - public function it_returns_true_if_given_test_is_a_php_unit_test() + public function it_returns_true_if_given_test_is_a_php_unit_test(): void { $this->assertTrue( (new PhpUnitClassifier())->satisfies( diff --git a/tests/Console/StatsListCommandTest.php b/tests/Console/StatsListCommandTest.php index 691d1d3a..6aa484d1 100644 --- a/tests/Console/StatsListCommandTest.php +++ b/tests/Console/StatsListCommandTest.php @@ -8,7 +8,7 @@ class StatsListCommandTest extends TestCase { - public function setUp() : void + protected function setUp() : void { parent::setUp(); @@ -29,7 +29,7 @@ public function setUp() : void } /** @test */ - public function it_executes_stats_command_without_options_and_outputs_an_ascii_table() + public function it_executes_stats_command_without_options_and_outputs_an_ascii_table(): void { Route::get('projects', 'Wnx\LaravelStats\Tests\Stubs\Controllers\ProjectsController@index'); Route::get('users', 'Wnx\LaravelStats\Tests\Stubs\Controllers\UsersController@index'); @@ -47,7 +47,7 @@ public function it_executes_stats_command_without_options_and_outputs_an_ascii_t } /** @test */ - public function it_executes_stats_command_with_verbose_option_and_displays_to_which_component_each_class_belongs_to() + public function it_executes_stats_command_with_verbose_option_and_displays_to_which_component_each_class_belongs_to(): void { Route::get('projects', 'Wnx\LaravelStats\Tests\Stubs\Controllers\ProjectsController@index'); Route::get('users', 'Wnx\LaravelStats\Tests\Stubs\Controllers\UsersController@index'); @@ -68,7 +68,7 @@ public function it_executes_stats_command_with_verbose_option_and_displays_to_wh } /** @test */ - public function it_displays_correct_headers_in_ascii_table() + public function it_displays_correct_headers_in_ascii_table(): void { $this->artisan('stats'); $output = Artisan::output(); @@ -83,7 +83,7 @@ public function it_displays_correct_headers_in_ascii_table() } /** @test */ - public function it_returns_stats_as_json() + public function it_returns_stats_as_json(): void { $this->artisan('stats', [ '--json' => true, @@ -94,7 +94,7 @@ public function it_returns_stats_as_json() } /** @test */ - public function it_executes_stats_command_in_verbose_mode_and_shows_which_class_belongs_to_which_component() + public function it_executes_stats_command_in_verbose_mode_and_shows_which_class_belongs_to_which_component(): void { $this->artisan('stats', [ '--json' => true, @@ -115,7 +115,7 @@ public function it_executes_stats_command_in_verbose_mode_and_shows_which_class_ } /** @test */ - public function it_only_returns_stats_for_given_components() + public function it_only_returns_stats_for_given_components(): void { $this->artisan('stats', [ '--json' => true, @@ -129,7 +129,7 @@ public function it_only_returns_stats_for_given_components() } /** @test */ - public function it_outputs_warning_when_someone_uses_the_share_option() + public function it_outputs_warning_when_someone_uses_the_share_option(): void { $this->artisan('stats', [ '--share' => true, diff --git a/tests/Outputs/JsonOutputTest.php b/tests/Outputs/JsonOutputTest.php index e3283c95..6226360c 100644 --- a/tests/Outputs/JsonOutputTest.php +++ b/tests/Outputs/JsonOutputTest.php @@ -26,7 +26,7 @@ public function getTestProject() } /** @test */ - public function it_creates_project_statistics_as_an_array() + public function it_creates_project_statistics_as_an_array(): void { $json = (new JsonOutput)->render($this->getTestProject()); @@ -55,7 +55,7 @@ public function it_creates_project_statistics_as_an_array() 'number_of_classes' => 1, 'number_of_methods' => 1, 'methods_per_class' => 1.0, - 'loc' => 18, + 'loc' => 16, 'lloc' => 1.0, 'lloc_per_method' => 1.0, ], @@ -64,7 +64,7 @@ public function it_creates_project_statistics_as_an_array() 'number_of_classes' => 1, 'number_of_methods' => 3, 'methods_per_class' => 3.0, - 'loc' => 41, + 'loc' => 39, 'lloc' => 1, 'lloc_per_method' => 0.33, ], @@ -73,7 +73,7 @@ public function it_creates_project_statistics_as_an_array() 'number_of_classes' => 4, 'number_of_methods' => 7, 'methods_per_class' => 1.75, - 'loc' => 90, + 'loc' => 86, 'lloc' => 5, 'lloc_per_method' => 0.71, ], @@ -89,7 +89,7 @@ public function it_creates_project_statistics_as_an_array() } /** @test */ - public function it_includes_classes_in_project_statistics_array_if_verbose_output_is_requested() + public function it_includes_classes_in_project_statistics_array_if_verbose_output_is_requested(): void { $json = (new JsonOutput)->render($this->getTestProject(), $isVerbose = true); @@ -113,7 +113,7 @@ public function it_includes_classes_in_project_statistics_array_if_verbose_outpu } /** @test */ - public function it_only_contains_components_in_statistics_array_which_have_been_requested() + public function it_only_contains_components_in_statistics_array_which_have_been_requested(): void { $json = (new JsonOutput)->render( $this->getTestProject(), diff --git a/tests/ProjectTest.php b/tests/ProjectTest.php index dd34a6ff..69724722 100644 --- a/tests/ProjectTest.php +++ b/tests/ProjectTest.php @@ -14,7 +14,7 @@ class ProjectTest extends TestCase { /** @test */ - public function creates_a_project_object_from_a_collection_of_reflection_classes() + public function creates_a_project_object_from_a_collection_of_reflection_classes(): void { $classes = collect([ $projectModel = new ReflectionClass(ProjectModel::class), @@ -23,15 +23,13 @@ public function creates_a_project_object_from_a_collection_of_reflection_classes $project = new Project($classes); $this->assertTrue( - $project->classifiedClasses()->map(function ($class) { - return $class->reflectionClass; - })->contains($projectModel) + $project->classifiedClasses()->map(static fn ($class) => $class->reflectionClass)->contains($projectModel) ); $this->assertInstanceOf(ClassifiedClass::class, $project->classifiedClasses()->first()); } /** @test */ - public function returns_instance_of_project_statistics_when_accessing_project_statistics() + public function returns_instance_of_project_statistics_when_accessing_project_statistics(): void { $classes = collect([ $projectModel = new ReflectionClass(ProjectModel::class), @@ -43,7 +41,7 @@ public function returns_instance_of_project_statistics_when_accessing_project_st } /** @test */ - public function groups_classes_into_components() + public function groups_classes_into_components(): void { Gate::policy(\Wnx\LaravelStats\Tests\Stubs\Models\Project::class, \Wnx\LaravelStats\Tests\Stubs\Policies\DemoPolicy::class); @@ -64,7 +62,7 @@ public function groups_classes_into_components() } /** @test */ - public function groups_classes_into_components_and_filters_by_component_name() + public function groups_classes_into_components_and_filters_by_component_name(): void { Gate::policy(\Wnx\LaravelStats\Tests\Stubs\Models\Project::class, \Wnx\LaravelStats\Tests\Stubs\Policies\DemoPolicy::class); @@ -83,7 +81,7 @@ public function groups_classes_into_components_and_filters_by_component_name() } /** @test */ - public function groups_classes_into_component_and_does_not_apply_filter_if_array_is_empty() + public function groups_classes_into_component_and_does_not_apply_filter_if_array_is_empty(): void { Gate::policy(\Wnx\LaravelStats\Tests\Stubs\Models\Project::class, \Wnx\LaravelStats\Tests\Stubs\Policies\DemoPolicy::class); diff --git a/tests/ReflectionClassTest.php b/tests/ReflectionClassTest.php index 1da3692f..f26f3bc6 100644 --- a/tests/ReflectionClassTest.php +++ b/tests/ReflectionClassTest.php @@ -10,7 +10,7 @@ class ReflectionClassTest extends TestCase { /** @test */ - public function it_returns_a_list_of_methods_for_the_given_class_and_ignores_parent_and_trait_methods() + public function it_returns_a_list_of_methods_for_the_given_class_and_ignores_parent_and_trait_methods(): void { $class = new ReflectionClass(ProjectsController::class); @@ -21,7 +21,7 @@ public function it_returns_a_list_of_methods_for_the_given_class_and_ignores_par } /** @test */ - public function it_determines_wether_the_given_class_uses_a_given_trait() + public function it_determines_wether_the_given_class_uses_a_given_trait(): void { $class = new ReflectionClass(Controller::class); diff --git a/tests/RejectionStrategies/RejectInternalClassesTest.php b/tests/RejectionStrategies/RejectInternalClassesTest.php index 8c69cd77..8c7cd856 100644 --- a/tests/RejectionStrategies/RejectInternalClassesTest.php +++ b/tests/RejectionStrategies/RejectInternalClassesTest.php @@ -10,7 +10,7 @@ class RejectInternalClassesTest extends TestCase { /** @test */ - public function it_returns_true_if_the_given_class_is_a_php_internal() + public function it_returns_true_if_the_given_class_is_a_php_internal(): void { $strategy = app(RejectInternalClasses::class); $class = new ReflectionClass(new \stdClass); @@ -19,7 +19,7 @@ public function it_returns_true_if_the_given_class_is_a_php_internal() } /** @test */ - public function it_returns_false_if_the_class_belongs_to_the_app() + public function it_returns_false_if_the_class_belongs_to_the_app(): void { $strategy = app(RejectInternalClasses::class); $class = new ReflectionClass(ModelClassifier::class); diff --git a/tests/RejectionStrategies/RejectVendorClassesTest.php b/tests/RejectionStrategies/RejectVendorClassesTest.php index 5c17c2db..2008f676 100644 --- a/tests/RejectionStrategies/RejectVendorClassesTest.php +++ b/tests/RejectionStrategies/RejectVendorClassesTest.php @@ -11,7 +11,7 @@ class RejectVendorClassesTest extends TestCase { /** @test */ - public function it_returns_true_if_the_given_class_is_a_php_internal() + public function it_returns_true_if_the_given_class_is_a_php_internal(): void { $strategy = app(RejectVendorClasses::class); $class = new ReflectionClass(new \stdClass); @@ -20,7 +20,7 @@ public function it_returns_true_if_the_given_class_is_a_php_internal() } /** @test */ - public function it_returns_true_if_the_class_is_located_in_the_vendor_folder() + public function it_returns_true_if_the_class_is_located_in_the_vendor_folder(): void { $strategy = app(RejectVendorClasses::class); $class = new ReflectionClass(Encrypter::class); @@ -29,7 +29,7 @@ public function it_returns_true_if_the_class_is_located_in_the_vendor_folder() } /** @test */ - public function it_returns_false_if_the_class_belongs_to_the_app() + public function it_returns_false_if_the_class_belongs_to_the_app(): void { $strategy = app(RejectVendorClasses::class); $class = new ReflectionClass(ModelClassifier::class); diff --git a/tests/Statistics/NumberOfRoutesTest.php b/tests/Statistics/NumberOfRoutesTest.php index 773d1e3d..5cf2ba99 100644 --- a/tests/Statistics/NumberOfRoutesTest.php +++ b/tests/Statistics/NumberOfRoutesTest.php @@ -9,7 +9,7 @@ class NumberOfRoutesTest extends TestCase { /** @test */ - public function it_returns_0_if_no_routes_are_registered() + public function it_returns_0_if_no_routes_are_registered(): void { $result = app(NumberOfRoutes::class)->get(); @@ -17,7 +17,7 @@ public function it_returns_0_if_no_routes_are_registered() } /** @test */ - public function it_returns_the_number_of_registered_routes() + public function it_returns_the_number_of_registered_routes(): void { Route::get('users', 'Wnx\LaravelStats\Tests\Stubs\Controllers\UsersController@index'); Route::get('users/create', 'Wnx\LaravelStats\Tests\Stubs\Controllers\UsersController@create'); @@ -33,7 +33,7 @@ public function it_returns_the_number_of_registered_routes() } /** @test */ - public function it_only_counts_unique_routes() + public function it_only_counts_unique_routes(): void { Route::get('users', 'Wnx\LaravelStats\Tests\Stubs\Controllers\UsersController@index'); Route::get('users', 'Wnx\LaravelStats\Tests\Stubs\Controllers\UsersController@create'); diff --git a/tests/Statistics/ProjectStatisticsTest.php b/tests/Statistics/ProjectStatisticsTest.php index c7b6a158..2027f0ea 100644 --- a/tests/Statistics/ProjectStatisticsTest.php +++ b/tests/Statistics/ProjectStatisticsTest.php @@ -26,7 +26,7 @@ public function getTestProject() } /** @test */ - public function it_returns_total_number_of_classes_for_given_project() + public function it_returns_total_number_of_classes_for_given_project(): void { $statistic = new ProjectStatistic($this->getTestProject()); @@ -34,7 +34,7 @@ public function it_returns_total_number_of_classes_for_given_project() } /** @test */ - public function it_returns_total_number_of_method_for_a_given_project() + public function it_returns_total_number_of_method_for_a_given_project(): void { $statistic = new ProjectStatistic($this->getTestProject()); @@ -42,7 +42,7 @@ public function it_returns_total_number_of_method_for_a_given_project() } /** @test */ - public function it_returns_average_number_of_methods_per_class_for_a_given_project() + public function it_returns_average_number_of_methods_per_class_for_a_given_project(): void { $statistic = new ProjectStatistic($this->getTestProject()); @@ -54,15 +54,15 @@ public function it_returns_average_number_of_methods_per_class_for_a_given_proje } /** @test */ - public function it_returns_total_number_of_lines_of_code_for_a_given_project() + public function it_returns_total_number_of_lines_of_code_for_a_given_project(): void { $statistic = new ProjectStatistic($this->getTestProject()); - $this->assertEquals(136, $statistic->getLinesOfCode()); + $this->assertEquals(133, $statistic->getLinesOfCode()); } /** @test */ - public function it_returns_total_number_of_logical_lines_of_code_for_a_given_project() + public function it_returns_total_number_of_logical_lines_of_code_for_a_given_project(): void { $statistic = new ProjectStatistic($this->getTestProject()); @@ -70,7 +70,7 @@ public function it_returns_total_number_of_logical_lines_of_code_for_a_given_pro } /** @test */ - public function it_returns_average_number_of_logical_lines_of_code_per_method_for_a_given_project() + public function it_returns_average_number_of_logical_lines_of_code_per_method_for_a_given_project(): void { $statistic = new ProjectStatistic($this->getTestProject()); @@ -82,7 +82,7 @@ public function it_returns_average_number_of_logical_lines_of_code_per_method_fo } /** @test */ - public function it_returns_total_number_of_logical_lines_of_code_for_application_code() + public function it_returns_total_number_of_logical_lines_of_code_for_application_code(): void { $statistic = new ProjectStatistic($this->getTestProject()); @@ -90,7 +90,7 @@ public function it_returns_total_number_of_logical_lines_of_code_for_application } /** @test */ - public function it_returns_total_number_of_logical_lines_of_code_for_test_code() + public function it_returns_total_number_of_logical_lines_of_code_for_test_code(): void { $statistic = new ProjectStatistic($this->getTestProject()); @@ -98,7 +98,7 @@ public function it_returns_total_number_of_logical_lines_of_code_for_test_code() } /** @test */ - public function it_returns_application_code_to_test_code_ratio() + public function it_returns_application_code_to_test_code_ratio(): void { $statistic = new ProjectStatistic($this->getTestProject()); diff --git a/tests/Stubs/Commands/DemoCommand.php b/tests/Stubs/Commands/DemoCommand.php index 9e1a42ad..56965072 100644 --- a/tests/Stubs/Commands/DemoCommand.php +++ b/tests/Stubs/Commands/DemoCommand.php @@ -32,10 +32,8 @@ public function __construct() /** * Execute the console command. - * - * @return mixed */ - public function handle() + public function handle(): void { // } diff --git a/tests/Stubs/Controllers/Controller.php b/tests/Stubs/Controllers/Controller.php index 136904d2..64c914b1 100644 --- a/tests/Stubs/Controllers/Controller.php +++ b/tests/Stubs/Controllers/Controller.php @@ -9,5 +9,7 @@ class Controller extends BaseController { - use AuthorizesRequests, DispatchesJobs, ValidatesRequests; + use AuthorizesRequests; + use DispatchesJobs; + use ValidatesRequests; } diff --git a/tests/Stubs/Controllers/UsersController.php b/tests/Stubs/Controllers/UsersController.php index e4008181..d98042c9 100644 --- a/tests/Stubs/Controllers/UsersController.php +++ b/tests/Stubs/Controllers/UsersController.php @@ -41,7 +41,7 @@ public function delete() return []; } - private function thePrivateMethod() + private function thePrivateMethod(): void { // } diff --git a/tests/Stubs/EventListeners/DemoEventListener.php b/tests/Stubs/EventListeners/DemoEventListener.php index 3f883fbe..d3b42400 100644 --- a/tests/Stubs/EventListeners/DemoEventListener.php +++ b/tests/Stubs/EventListeners/DemoEventListener.php @@ -18,9 +18,8 @@ public function __construct() * Handle the event. * * @param object $event - * @return void */ - public function handle($event) + public function handle($event): void { // } diff --git a/tests/Stubs/EventListeners/UserEventSubscriber.php b/tests/Stubs/EventListeners/UserEventSubscriber.php index c59738e6..b41bc4fc 100644 --- a/tests/Stubs/EventListeners/UserEventSubscriber.php +++ b/tests/Stubs/EventListeners/UserEventSubscriber.php @@ -21,9 +21,8 @@ public function handleUserLogout($event) {} * Register the listeners for the subscriber. * * @param \Illuminate\Events\Dispatcher $events - * @return void */ - public function subscribe($events) + public function subscribe($events): void { $events->listen( Login::class, diff --git a/tests/Stubs/Events/DemoEvent.php b/tests/Stubs/Events/DemoEvent.php index 95b2ab06..efc21e23 100644 --- a/tests/Stubs/Events/DemoEvent.php +++ b/tests/Stubs/Events/DemoEvent.php @@ -9,8 +9,9 @@ class DemoEvent { - use Dispatchable, InteractsWithSockets, SerializesModels; - + use Dispatchable; + use InteractsWithSockets; + use SerializesModels; /** * Create a new event instance. * diff --git a/tests/Stubs/Jobs/DemoJob.php b/tests/Stubs/Jobs/DemoJob.php index 87ed8d23..614c9bd3 100644 --- a/tests/Stubs/Jobs/DemoJob.php +++ b/tests/Stubs/Jobs/DemoJob.php @@ -10,8 +10,10 @@ class DemoJob implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - + use Dispatchable; + use InteractsWithQueue; + use Queueable; + use SerializesModels; /** * Create a new job instance. * @@ -24,10 +26,8 @@ public function __construct() /** * Execute the job. - * - * @return void */ - public function handle() + public function handle(): void { // } diff --git a/tests/Stubs/Mails/DemoMail.php b/tests/Stubs/Mails/DemoMail.php index 59c60ef7..0d12c4f9 100644 --- a/tests/Stubs/Mails/DemoMail.php +++ b/tests/Stubs/Mails/DemoMail.php @@ -8,8 +8,8 @@ class DemoMail extends Mailable { - use Queueable, SerializesModels; - + use Queueable; + use SerializesModels; /** * Create a new message instance. * diff --git a/tests/Stubs/Middleware/DemoMiddleware.php b/tests/Stubs/Middleware/DemoMiddleware.php index aa148241..f58b68f7 100644 --- a/tests/Stubs/Middleware/DemoMiddleware.php +++ b/tests/Stubs/Middleware/DemoMiddleware.php @@ -10,7 +10,6 @@ class DemoMiddleware * Handle an incoming request. * * @param \Illuminate\Http\Request $request - * @param \Closure $next * * @return mixed */ diff --git a/tests/Stubs/Middleware/RouteMiddleware.php b/tests/Stubs/Middleware/RouteMiddleware.php index 7349b33e..d3908f35 100644 --- a/tests/Stubs/Middleware/RouteMiddleware.php +++ b/tests/Stubs/Middleware/RouteMiddleware.php @@ -10,7 +10,6 @@ class RouteMiddleware * Handle an incoming request. * * @param \Illuminate\Http\Request $request - * @param \Closure $next * * @return mixed */ diff --git a/tests/Stubs/Migrations/2014_10_12_000000_create_users_table.php b/tests/Stubs/Migrations/2014_10_12_000000_create_users_table.php index 045218c3..2f67f4c3 100644 --- a/tests/Stubs/Migrations/2014_10_12_000000_create_users_table.php +++ b/tests/Stubs/Migrations/2014_10_12_000000_create_users_table.php @@ -10,12 +10,10 @@ { /** * Run the migrations. - * - * @return void */ - public function up() + public function up(): void { - Schema::create('users', function (Blueprint $table) { + Schema::create('users', static function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('email')->unique(); @@ -28,10 +26,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('users'); } diff --git a/tests/Stubs/Migrations/2014_10_12_100000_create_password_resets_table.php b/tests/Stubs/Migrations/2014_10_12_100000_create_password_resets_table.php index 7d65507b..007bc224 100644 --- a/tests/Stubs/Migrations/2014_10_12_100000_create_password_resets_table.php +++ b/tests/Stubs/Migrations/2014_10_12_100000_create_password_resets_table.php @@ -10,12 +10,10 @@ class CreatePasswordResetsTable extends Migration { /** * Run the migrations. - * - * @return void */ - public function up() + public function up(): void { - Schema::create('password_resets', function (Blueprint $table) { + Schema::create('password_resets', static function (Blueprint $table) { $table->string('email')->index(); $table->string('token'); $table->timestamp('created_at')->nullable(); @@ -24,10 +22,8 @@ public function up() /** * Reverse the migrations. - * - * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('password_resets'); } diff --git a/tests/Stubs/Models/User.php b/tests/Stubs/Models/User.php index b4c5b09d..21a71a8f 100644 --- a/tests/Stubs/Models/User.php +++ b/tests/Stubs/Models/User.php @@ -12,7 +12,7 @@ class User extends Model protected static function booted() { - static::created(function ($user) { + static::created(static function ($user) { // Closure Event Listener }); } diff --git a/tests/Stubs/Notifications/ServerDownNotification.php b/tests/Stubs/Notifications/ServerDownNotification.php index 859fbb61..918798ec 100644 --- a/tests/Stubs/Notifications/ServerDownNotification.php +++ b/tests/Stubs/Notifications/ServerDownNotification.php @@ -23,11 +23,10 @@ public function __construct() /** * Get the notification's delivery channels. * - * @param mixed $notifiable * * @return array */ - public function via($notifiable) + public function via(mixed $notifiable) { return ['mail']; } @@ -35,11 +34,10 @@ public function via($notifiable) /** * Get the mail representation of the notification. * - * @param mixed $notifiable * * @return \Illuminate\Notifications\Messages\MailMessage */ - public function toMail($notifiable) + public function toMail(mixed $notifiable) { return (new MailMessage()) ->line('The introduction to the notification.') @@ -50,11 +48,10 @@ public function toMail($notifiable) /** * Get the array representation of the notification. * - * @param mixed $notifiable * * @return array */ - public function toArray($notifiable) + public function toArray(mixed $notifiable) { return [ // diff --git a/tests/Stubs/Observers/UserObserver.php b/tests/Stubs/Observers/UserObserver.php index 825521a2..1aa7484f 100644 --- a/tests/Stubs/Observers/UserObserver.php +++ b/tests/Stubs/Observers/UserObserver.php @@ -10,9 +10,8 @@ class UserObserver * Handle the user "created" event. * * @param \App\User $user - * @return void */ - public function created(User $user) + public function created(User $user): void { // } @@ -21,9 +20,8 @@ public function created(User $user) * Handle the user "updated" event. * * @param \App\User $user - * @return void */ - public function updated(User $user) + public function updated(User $user): void { // } @@ -32,9 +30,8 @@ public function updated(User $user) * Handle the user "deleted" event. * * @param \App\User $user - * @return void */ - public function deleted(User $user) + public function deleted(User $user): void { // } @@ -43,9 +40,8 @@ public function deleted(User $user) * Handle the user "restored" event. * * @param \App\User $user - * @return void */ - public function restored(User $user) + public function restored(User $user): void { // } @@ -54,9 +50,8 @@ public function restored(User $user) * Handle the user "force deleted" event. * * @param \App\User $user - * @return void */ - public function forceDeleted(User $user) + public function forceDeleted(User $user): void { // } diff --git a/tests/Stubs/Rules/DemoRule.php b/tests/Stubs/Rules/DemoRule.php index 6feae4a7..f39d1d85 100644 --- a/tests/Stubs/Rules/DemoRule.php +++ b/tests/Stubs/Rules/DemoRule.php @@ -21,10 +21,8 @@ public function __construct() * * @param string $attribute * @param mixed $value - * - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): void { // } diff --git a/tests/Stubs/Seeders/DemoSeeder.php b/tests/Stubs/Seeders/DemoSeeder.php index b870d194..e40e1c7d 100644 --- a/tests/Stubs/Seeders/DemoSeeder.php +++ b/tests/Stubs/Seeders/DemoSeeder.php @@ -8,10 +8,8 @@ class DemoSeeder extends Seeder { /** * Run the database seeds. - * - * @return void */ - public function run() + public function run(): void { // } diff --git a/tests/Stubs/ServiceProviders/DemoProvider.php b/tests/Stubs/ServiceProviders/DemoProvider.php index c4d89ae0..768c6cc5 100644 --- a/tests/Stubs/ServiceProviders/DemoProvider.php +++ b/tests/Stubs/ServiceProviders/DemoProvider.php @@ -8,20 +8,16 @@ class DemoProvider extends ServiceProvider { /** * Bootstrap the application services. - * - * @return void */ - public function boot() + public function boot(): void { // } /** * Register the application services. - * - * @return void */ - public function register() + public function register(): void { // } diff --git a/tests/Stubs/ServiceProviders/EventServiceProvider.php b/tests/Stubs/ServiceProviders/EventServiceProvider.php index b324e8c0..fb0f1c84 100644 --- a/tests/Stubs/ServiceProviders/EventServiceProvider.php +++ b/tests/Stubs/ServiceProviders/EventServiceProvider.php @@ -26,10 +26,8 @@ class EventServiceProvider extends ServiceProvider /** * Register any events for your application. - * - * @return void */ - public function boot() + public function boot(): void { parent::boot(); } diff --git a/tests/Stubs/Tests/DemoBrowserKit.php b/tests/Stubs/Tests/DemoBrowserKit.php index 80a4e065..74b781ce 100644 --- a/tests/Stubs/Tests/DemoBrowserKit.php +++ b/tests/Stubs/Tests/DemoBrowserKit.php @@ -6,13 +6,13 @@ class DemoBrowserKit extends TestCase { - public function createApplication() + public function createApplication(): void { // } /** @test */ - public function it_runs_browser_kit_tests() + public function it_runs_browser_kit_tests(): void { $this->assertTrue(true); } diff --git a/tests/Stubs/Tests/DemoDuskTest.php b/tests/Stubs/Tests/DemoDuskTest.php index 5b06fed1..6c7d6f52 100644 --- a/tests/Stubs/Tests/DemoDuskTest.php +++ b/tests/Stubs/Tests/DemoDuskTest.php @@ -5,7 +5,7 @@ abstract class DemoDuskTest extends \Laravel\Dusk\TestCase { /** @test */ - public function this_is_dusk_test() + public function this_is_dusk_test(): void { $this->assertTrue(true); } diff --git a/tests/Stubs/Tests/DemoUnitTest.php b/tests/Stubs/Tests/DemoUnitTest.php index 4a24a57a..aa3148e0 100644 --- a/tests/Stubs/Tests/DemoUnitTest.php +++ b/tests/Stubs/Tests/DemoUnitTest.php @@ -8,10 +8,8 @@ class DemoUnitTest extends TestCase { /** * A basic test example. - * - * @return void */ - public function testBasicTest() + public function testBasicTest(): void { $this->assertTrue(true); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 68fd560e..f57d8876 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -40,24 +40,19 @@ protected function resolveApplicationHttpKernel($app) /** * Create a new Project based on the passed FQDNs of Classes * - * @param array $classes * * @return \Wnx\LaravelStats\Project */ public function createProjectFromClasses(array $classes = []) { $classes = collect($classes) - ->map(function ($class) { - return new ReflectionClass($class); - }); + ->map(static fn ($class) => new ReflectionClass($class)); return new Project($classes); } /** * Get currently installed Laravel Version - * - * @return float */ public function getLaravelVersion(): float { diff --git a/tests/ValueObjects/ClassifiedClassTest.php b/tests/ValueObjects/ClassifiedClassTest.php index 3e0bea51..45d4abe4 100644 --- a/tests/ValueObjects/ClassifiedClassTest.php +++ b/tests/ValueObjects/ClassifiedClassTest.php @@ -19,7 +19,7 @@ public function getClassifiedClass() } /** @test */ - public function it_returns_number_of_methods_for_a_classified_class() + public function it_returns_number_of_methods_for_a_classified_class(): void { $this->assertEquals( 9, @@ -28,7 +28,7 @@ public function it_returns_number_of_methods_for_a_classified_class() } /** @test */ - public function it_returns_number_of_public_methods_for_a_classified_class() + public function it_returns_number_of_public_methods_for_a_classified_class(): void { $this->assertEquals( 7, @@ -37,7 +37,7 @@ public function it_returns_number_of_public_methods_for_a_classified_class() } /** @test */ - public function it_returns_number_of_non_public_methods_for_a_classified_class() + public function it_returns_number_of_non_public_methods_for_a_classified_class(): void { $this->assertEquals( 2, @@ -46,7 +46,7 @@ public function it_returns_number_of_non_public_methods_for_a_classified_class() } /** @test */ - public function it_returns_number_of_lines_of_code_for_a_classified_class() + public function it_returns_number_of_lines_of_code_for_a_classified_class(): void { $this->assertEquals( 53, @@ -55,7 +55,7 @@ public function it_returns_number_of_lines_of_code_for_a_classified_class() } /** @test */ - public function it_returns_number_of_logical_lines_of_code_for_a_classified_class() + public function it_returns_number_of_logical_lines_of_code_for_a_classified_class(): void { $this->assertSame( 7.0, @@ -64,7 +64,7 @@ public function it_returns_number_of_logical_lines_of_code_for_a_classified_clas } /** @test */ - public function it_returns_average_number_of_logical_lines_of_code_per_method_for_a_classified_class() + public function it_returns_average_number_of_logical_lines_of_code_per_method_for_a_classified_class(): void { $this->assertEquals( 0.78, diff --git a/tests/ValueObjects/ComponentTest.php b/tests/ValueObjects/ComponentTest.php index c4633efd..3a69b7e4 100644 --- a/tests/ValueObjects/ComponentTest.php +++ b/tests/ValueObjects/ComponentTest.php @@ -24,7 +24,7 @@ public function getTestComponent() } /** @test */ - public function component_name_is_accessible() + public function component_name_is_accessible(): void { $component = new Component('FooBar', collect([])); @@ -32,7 +32,7 @@ public function component_name_is_accessible() } /** @test */ - public function it_returns_number_of_classes_for_a_component() + public function it_returns_number_of_classes_for_a_component(): void { $component = $this->getTestComponent(); @@ -40,7 +40,7 @@ public function it_returns_number_of_classes_for_a_component() } /** @test */ - public function it_returns_number_of_methods_for_all_classes_within_a_component() + public function it_returns_number_of_methods_for_all_classes_within_a_component(): void { $component = $this->getTestComponent(); @@ -48,7 +48,7 @@ public function it_returns_number_of_methods_for_all_classes_within_a_component( } /** @test */ - public function it_returns_number_of_public_methods_for_all_classes_within_a_component() + public function it_returns_number_of_public_methods_for_all_classes_within_a_component(): void { $component = $this->getTestComponent(); @@ -56,7 +56,7 @@ public function it_returns_number_of_public_methods_for_all_classes_within_a_com } /** @test */ - public function it_returns_number_of_non_public_methods_for_all_classes_within_a_component() + public function it_returns_number_of_non_public_methods_for_all_classes_within_a_component(): void { $component = $this->getTestComponent(); @@ -64,7 +64,7 @@ public function it_returns_number_of_non_public_methods_for_all_classes_within_a } /** @test */ - public function it_returns_average_number_of_methods_per_class_for_all_classes_within_a_component() + public function it_returns_average_number_of_methods_per_class_for_all_classes_within_a_component(): void { $component = $this->getTestComponent(); @@ -72,14 +72,14 @@ public function it_returns_average_number_of_methods_per_class_for_all_classes_w } /** @test */ - public function it_returns_total_number_of_lines_of_code_for_all_classes_within_a_component() + public function it_returns_total_number_of_lines_of_code_for_all_classes_within_a_component(): void { $component = $this->getTestComponent(); - $this->assertEquals(115, $component->getLinesOfCode()); + $this->assertEquals(113, $component->getLinesOfCode()); } /** @test */ - public function it_returns_total_number_of_logical_lines_of_code_for_all_classes_within_a_component() + public function it_returns_total_number_of_logical_lines_of_code_for_all_classes_within_a_component(): void { $component = $this->getTestComponent(); @@ -87,7 +87,7 @@ public function it_returns_total_number_of_logical_lines_of_code_for_all_classes } /** @test */ - public function it_returns_average_number_of_logical_lines_of_code_per_method_for_all_classes_within_a_component() + public function it_returns_average_number_of_logical_lines_of_code_per_method_for_all_classes_within_a_component(): void { $component = $this->getTestComponent();