diff --git a/Taskfile.yml b/Taskfile.yml index 516b909..ca16cde 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -4,7 +4,7 @@ tasks: cmd: 'vendor/bin/phpunit --coverage-html coverage {{.CLI_ARGS}}' cs-fix: - cmd: 'vendor/bin/php-cs-fixer fix --diff --verbose --stop-on-violation {{.CLI_ARGS}}' + cmd: 'vendor/bin/php-cs-fixer fix --diff --verbose {{.CLI_ARGS}}' cs: cmds: @@ -60,8 +60,8 @@ tasks: check: cmds: - - task: lint - - task: psalm + - task: cs + - task: stan - task: rector - task: deptrac-directories - task: test diff --git a/src/Analyzer/AnalyzeFileTask.php b/src/Analyzer/AnalyzeFileTask.php index 047e42c..f9fde88 100644 --- a/src/Analyzer/AnalyzeFileTask.php +++ b/src/Analyzer/AnalyzeFileTask.php @@ -19,6 +19,7 @@ use function in_array; use function is_array; use function token_get_all; + use const T_COMMENT; use const T_DOC_COMMENT; @@ -48,9 +49,7 @@ public function run(SplFileInfo $file): array $fileComments = $this->cache->get( $cacheKey, - function () use ($filePath): iterable { - return $this->analyzeFile($filePath); - } + fn(): iterable => $this->analyzeFile($filePath), ); $totalLinesOfCode = $this->countTotalLines($file->getRealPath()); @@ -93,7 +92,7 @@ private function shouldAnalyzeMissingDocBlocks(): bool || in_array( $this->missingDocBlock->getName(), $this->configDTO->getAllowedTypes(), - true + true, ); } diff --git a/src/Analyzer/CommentStatisticsAggregator.php b/src/Analyzer/CommentStatisticsAggregator.php index 9705316..59a9967 100644 --- a/src/Analyzer/CommentStatisticsAggregator.php +++ b/src/Analyzer/CommentStatisticsAggregator.php @@ -10,7 +10,9 @@ use SavinMikhail\CommentsDensity\Config\DTO\ConfigDTO; use SavinMikhail\CommentsDensity\Exception\CommentsDensityException; use SavinMikhail\CommentsDensity\MissingDocblock\MissingDocBlockAnalyzer; + use function substr_count; + use const PHP_EOL; final readonly class CommentStatisticsAggregator diff --git a/src/Baseline/Storage/TreePhpBaselineStorage.php b/src/Baseline/Storage/TreePhpBaselineStorage.php index 0539ced..fb679e1 100644 --- a/src/Baseline/Storage/TreePhpBaselineStorage.php +++ b/src/Baseline/Storage/TreePhpBaselineStorage.php @@ -5,6 +5,7 @@ namespace SavinMikhail\CommentsDensity\Baseline\Storage; use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CommentDTO; + use const DIRECTORY_SEPARATOR; final class TreePhpBaselineStorage implements BaselineStorageInterface diff --git a/src/Commands/Command.php b/src/Commands/Command.php index 00f85ad..a7a218d 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -4,7 +4,6 @@ namespace SavinMikhail\CommentsDensity\Commands; -use Generator; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use SavinMikhail\CommentsDensity\Config\ConfigLoader; diff --git a/src/Composer/CommentsDensityPlugin.php b/src/Composer/CommentsDensityPlugin.php index f167510..19cbd72 100644 --- a/src/Composer/CommentsDensityPlugin.php +++ b/src/Composer/CommentsDensityPlugin.php @@ -11,9 +11,6 @@ use Composer\Script\Event; use Composer\Script\ScriptEvents; -use function chmod; -use function copy; -use function file_exists; use function file_put_contents; final class CommentsDensityPlugin implements PluginInterface, EventSubscriberInterface @@ -85,6 +82,7 @@ private static function promptForConfigFile(IOInterface $interface): void if (!$shouldCreateConfig) { $interface->write('Configuration file setup skipped.'); + return; } diff --git a/src/Config/ConfigLoader.php b/src/Config/ConfigLoader.php index d0542ef..2b42698 100644 --- a/src/Config/ConfigLoader.php +++ b/src/Config/ConfigLoader.php @@ -6,9 +6,11 @@ use SavinMikhail\CommentsDensity\Config\DTO\ConfigDTO; use SavinMikhail\CommentsDensity\Exception\CommentsDensityException; + use function defined; use function dirname; use function file_exists; + use const DIRECTORY_SEPARATOR; final readonly class ConfigLoader diff --git a/src/Config/DTO/ConfigDTO.php b/src/Config/DTO/ConfigDTO.php index 0bbaec9..e213436 100644 --- a/src/Config/DTO/ConfigDTO.php +++ b/src/Config/DTO/ConfigDTO.php @@ -10,7 +10,7 @@ * @param array $thresholds * @param string[] $exclude * @param string[] $directories - * @param string[] $only + * @param string[] $disable */ public function __construct( /** Limit occurrences of each comment type */ diff --git a/src/Reporters/ConsoleReporter.php b/src/Reporters/ConsoleReporter.php index 1c5d755..12d888a 100644 --- a/src/Reporters/ConsoleReporter.php +++ b/src/Reporters/ConsoleReporter.php @@ -12,6 +12,7 @@ use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\PerformanceMetricsDTO; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Output\OutputInterface; + use function array_map; final readonly class ConsoleReporter implements ReporterInterface diff --git a/src/Reporters/HtmlReporter.php b/src/Reporters/HtmlReporter.php index b009687..602783f 100644 --- a/src/Reporters/HtmlReporter.php +++ b/src/Reporters/HtmlReporter.php @@ -5,9 +5,11 @@ namespace SavinMikhail\CommentsDensity\Reporters; use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\OutputDTO; + use function file_put_contents; use function htmlspecialchars; use function nl2br; + use const ENT_QUOTES; use const ENT_SUBSTITUTE; diff --git a/tests/Analyzer/AnalyzerFactoryTest.php b/tests/Analyzer/AnalyzerFactoryTest.php index 07c6b24..04c5d3c 100644 --- a/tests/Analyzer/AnalyzerFactoryTest.php +++ b/tests/Analyzer/AnalyzerFactoryTest.php @@ -35,7 +35,7 @@ public function testGetAnalyzer(): void $analyzer = $factory->getAnalyzer($configDto, $output, $baselineStorage); // Assert that the returned object is an instance of Analyzer - $this->assertInstanceOf(Analyzer::class, $analyzer); + self::assertInstanceOf(Analyzer::class, $analyzer); // Use reflection to access the private property 'cache' $reflection = new ReflectionClass($analyzer); @@ -43,6 +43,6 @@ public function testGetAnalyzer(): void $cacheProperty->setAccessible(true); // Assert that the Cache instance is set correctly in the Analyzer - $this->assertInstanceOf(Cache::class, $cacheProperty->getValue($analyzer)); + self::assertInstanceOf(Cache::class, $cacheProperty->getValue($analyzer)); } } diff --git a/tests/Analyzer/CommentStatisticsAggregatorTest.php b/tests/Analyzer/CommentStatisticsAggregatorTest.php index dc7fb8e..ff4ffce 100644 --- a/tests/Analyzer/CommentStatisticsAggregatorTest.php +++ b/tests/Analyzer/CommentStatisticsAggregatorTest.php @@ -20,7 +20,9 @@ final class CommentStatisticsAggregatorTest extends TestCase { private MockObject $commentFactory; + private MockObject $missingDocBlock; + private CommentStatisticsAggregator $aggregator; protected function setUp(): void @@ -41,11 +43,11 @@ protected function setUp(): void $this->aggregator = new CommentStatisticsAggregator( $configDTO, $this->commentFactory, - $this->missingDocBlock + $this->missingDocBlock, ); } - public function testCalculateCommentStatisticsReturnsExpectedResult() + public function testCalculateCommentStatisticsReturnsExpectedResult(): void { $comments = [ new CommentDTO( @@ -53,14 +55,14 @@ public function testCalculateCommentStatisticsReturnsExpectedResult() 'red', 'file.php', 2, - 'Missing @throws tag' + 'Missing @throws tag', ), new CommentDTO( 'missingDocblock', 'red', 'file.php', 5, - 'Missing @throws tag' + 'Missing @throws tag', ), new CommentDTO( 'regular', @@ -91,10 +93,10 @@ public function testCalculateCommentStatisticsReturnsExpectedResult() $result = $this->aggregator->calculateCommentStatistics($comments); - $this->assertEquals($expectedStatistics, $result); + self::assertEquals($expectedStatistics, $result); } - public function testCalculateCommentStatisticsWithMissingDocBlock() + public function testCalculateCommentStatisticsWithMissingDocBlock(): void { $comments = [ new CommentDTO( @@ -102,7 +104,7 @@ public function testCalculateCommentStatisticsWithMissingDocBlock() 'red', 'file.php', 2, - 'Missing @throws tag' + 'Missing @throws tag', ), ]; @@ -116,7 +118,7 @@ public function testCalculateCommentStatisticsWithMissingDocBlock() $result = $this->aggregator->calculateCommentStatistics($comments); - $this->assertEquals($expectedStatistics, $result); + self::assertEquals($expectedStatistics, $result); } public function testCalculateCommentStatisticsThrowsExceptionForUnknownType(): void diff --git a/tests/Baseline/Storage/TreePhpBaselineStorageTest.php b/tests/Baseline/Storage/TreePhpBaselineStorageTest.php index 327c8e1..0e04048 100644 --- a/tests/Baseline/Storage/TreePhpBaselineStorageTest.php +++ b/tests/Baseline/Storage/TreePhpBaselineStorageTest.php @@ -8,12 +8,15 @@ use ReflectionClass; use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CommentDTO; use SavinMikhail\CommentsDensity\Baseline\Storage\TreePhpBaselineStorage; + use function ltrim; + use const DIRECTORY_SEPARATOR; final class TreePhpBaselineStorageTest extends TestCase { private string $path; + private TreePhpBaselineStorage $storage; protected function setUp(): void @@ -34,7 +37,7 @@ public function testInitCreatesFileIfNotExists(): void { unlink($this->path); $this->storage->init($this->path); - $this->assertFileExists($this->path); + self::assertFileExists($this->path); } public function testSetComments(): void @@ -50,16 +53,16 @@ public function testSetComments(): void 'path' => [ 'to' => [ 'file1.php' => [ - 10 => ['comment' => 'Test comment 1', 'type' => 'regular'] + 10 => ['comment' => 'Test comment 1', 'type' => 'regular'], ], 'file2.php' => [ - 20 => ['comment' => 'Test comment 2', 'type' => 'regular'] - ] - ] - ] + 20 => ['comment' => 'Test comment 2', 'type' => 'regular'], + ], + ], + ], ]; - $this->assertEquals($expectedData, include $this->path); + self::assertEquals($expectedData, include $this->path); } public function testFilterComments(): void @@ -70,7 +73,7 @@ public function testFilterComments(): void 'red', '/path/to/file1.php', 10, - 'Test comment 1' + 'Test comment 1', ), ]; $this->storage->setComments($existingComments); @@ -83,10 +86,10 @@ public function testFilterComments(): void $filteredComments = $this->storage->filterComments($comments); $expectedFilteredComments = [ - new CommentDTO('regular', 'red', '/path/to/file2.php', 20, 'Test comment 2') + new CommentDTO('regular', 'red', '/path/to/file2.php', 20, 'Test comment 2'), ]; - $this->assertEquals($expectedFilteredComments, $filteredComments); + self::assertEquals($expectedFilteredComments, $filteredComments); } public function testAddCommentToTree(): void @@ -104,13 +107,13 @@ public function testAddCommentToTree(): void 'path' => [ 'to' => [ 'file.php' => [ - 10 => ['comment' => 'test comment', 'type' => 'regular'] - ] - ] - ] + 10 => ['comment' => 'test comment', 'type' => 'regular'], + ], + ], + ], ]; - $this->assertEquals($expectedTree, $tree); + self::assertEquals($expectedTree, $tree); } public function testCommentExistsInTree(): void @@ -119,10 +122,10 @@ public function testCommentExistsInTree(): void 'path' => [ 'to' => [ 'file.php' => [ - 10 => ['comment' => 'Test comment', 'type' => 'regular'] - ] - ] - ] + 10 => ['comment' => 'Test comment', 'type' => 'regular'], + ], + ], + ], ]; $pathParts = explode(DIRECTORY_SEPARATOR, ltrim('/path/to/file.php', DIRECTORY_SEPARATOR)); @@ -133,6 +136,6 @@ public function testCommentExistsInTree(): void $method->setAccessible(true); $result = $method->invokeArgs($this->storage, [$tree, $pathParts, $line]); - $this->assertTrue($result); + self::assertTrue($result); } } diff --git a/tests/Cache/CacheTest.php b/tests/Cache/CacheTest.php index 3dd6d01..b1cadd0 100644 --- a/tests/Cache/CacheTest.php +++ b/tests/Cache/CacheTest.php @@ -5,6 +5,8 @@ namespace SavinMikhail\Tests\CommentsDensity\Cache; use PHPUnit\Framework\TestCase; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CommentDTO; use SavinMikhail\CommentsDensity\Cache\Cache; @@ -17,7 +19,7 @@ protected function setUp(): void $this->cacheDir = __DIR__ . '/../../var/cache_tests/'; $this->clearCacheDir(); if (!is_dir($this->cacheDir)) { - mkdir($this->cacheDir, 0777, true); + mkdir($this->cacheDir, 0o777, true); } } @@ -39,8 +41,8 @@ public function testSetAndGetCache(): void $cache->setCache($filePath, $comments); $cachedData = $cache->getCache($filePath); - $this->assertNotNull($cachedData); - $this->assertEquals($comments, $cachedData); + self::assertNotNull($cachedData); + self::assertEquals($comments, $cachedData); unlink($filePath); } @@ -57,15 +59,15 @@ public function testCacheInvalidationOnFileModification(): void $cache->setCache($filePath, $data); $cachedData = $cache->getCache($filePath); - $this->assertNotNull($cachedData); - $this->assertEquals($data, $cachedData); + self::assertNotNull($cachedData); + self::assertEquals($data, $cachedData); // Modify the file to invalidate the cache sleep(1); // Ensure the file modification time changes file_put_contents($filePath, 'getCache($filePath); - $this->assertNull($cachedData); + self::assertNull($cachedData); unlink($filePath); } @@ -73,9 +75,9 @@ public function testCacheInvalidationOnFileModification(): void private function clearCacheDir(): void { if (is_dir($this->cacheDir)) { - $files = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($this->cacheDir, \RecursiveDirectoryIterator::SKIP_DOTS), - \RecursiveIteratorIterator::CHILD_FIRST + $files = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($this->cacheDir, RecursiveDirectoryIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST, ); foreach ($files as $fileinfo) { diff --git a/tests/Commands/AnalyzeCommentCommandTest.php b/tests/Commands/AnalyzeCommentCommandTest.php index 88e86c5..7075a3d 100644 --- a/tests/Commands/AnalyzeCommentCommandTest.php +++ b/tests/Commands/AnalyzeCommentCommandTest.php @@ -5,7 +5,10 @@ namespace SavinMikhail\Tests\CommentsDensity\Commands; use FilesystemIterator; +use Generator; use PHPUnit\Framework\TestCase; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; use SavinMikhail\CommentsDensity\Analyzer\Analyzer; use SavinMikhail\CommentsDensity\Analyzer\AnalyzerFactory; use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CdsDTO; @@ -19,10 +22,11 @@ use SavinMikhail\CommentsDensity\Config\DTO\OutputDTO as InputOutputDTO; use SavinMikhail\CommentsDensity\Reporters\ConsoleReporter; use SavinMikhail\CommentsDensity\Reporters\ReporterFactory; +use SplFileInfo; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -class AnalyzeCommentCommandTest extends TestCase +final class AnalyzeCommentCommandTest extends TestCase { private string $tempCacheDir; @@ -32,7 +36,7 @@ protected function setUp(): void // Create a temporary cache directory for each test $this->tempCacheDir = sys_get_temp_dir() . '/cache_' . uniqid(); - mkdir($this->tempCacheDir, 0777, true); + mkdir($this->tempCacheDir, 0o777, true); } protected function tearDown(): void @@ -41,25 +45,6 @@ protected function tearDown(): void $this->removeDirectory($this->tempCacheDir); } - private function removeDirectory(string $dir): void - { - if (!is_dir($dir)) { - return; - } - - $files = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS), - \RecursiveIteratorIterator::CHILD_FIRST - ); - - foreach ($files as $fileinfo) { - $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink'); - $todo($fileinfo->getRealPath()); - } - - rmdir($dir); - } - public function testExecuteSuccess(): void { $docblockConfigDTO = new MissingDocblockConfigDTO( @@ -70,7 +55,7 @@ public function testExecuteSuccess(): void true, true, true, - true + true, ); $configDto = $this->createMock(ConfigDTO::class); @@ -94,7 +79,7 @@ public function testExecuteSuccess(): void new PerformanceMetricsDTO(0, 0), new ComToLocDTO(0, 'red'), new CdsDTO(0, 'red'), - false + false, ); $analyzer ->method('analyze') @@ -106,7 +91,7 @@ public function testExecuteSuccess(): void $reporter = $this->createMock(ConsoleReporter::class); $reporter ->method('report') - ->with($this->equalTo($outputDTO)); + ->with(self::equalTo($outputDTO)); $reporterFactory = $this->createMock(ReporterFactory::class); $reporterFactory->method('createReporter')->willReturn($reporter); @@ -118,7 +103,7 @@ public function testExecuteSuccess(): void $command->method('getConfigDto')->willReturn($configDto); $command ->method('getFilesFromDirectories') - ->willReturn($this->createGenerator([new \SplFileInfo(__FILE__)])); + ->willReturn($this->createGenerator([new SplFileInfo(__FILE__)])); $application = new Application(); $application->add($command); @@ -127,8 +112,8 @@ public function testExecuteSuccess(): void $result = $commandTester->execute([], ['interactive' => false]); - $this->assertSame(0, $result); - $this->assertStringContainsString('Comment thresholds are passed!', $commandTester->getDisplay()); + self::assertSame(0, $result); + self::assertStringContainsString('Comment thresholds are passed!', $commandTester->getDisplay()); } public function testExecuteFailure(): void @@ -141,7 +126,7 @@ public function testExecuteFailure(): void true, true, true, - true + true, ); $configDto = $this->createMock(ConfigDTO::class); $configDto->docblockConfigDTO = $docblockConfigDTO; @@ -163,7 +148,7 @@ public function testExecuteFailure(): void new PerformanceMetricsDTO(0, 0), new ComToLocDTO(0, 'red'), new CdsDTO(0, 'red'), - true + true, ); $analyzer = $this->createMock(Analyzer::class); @@ -177,7 +162,7 @@ public function testExecuteFailure(): void $reporter = $this->createMock(ConsoleReporter::class); $reporter ->method('report') - ->with($this->equalTo($outputDTO)); + ->with(self::equalTo($outputDTO)); $reporterFactory = $this->createMock(ReporterFactory::class); $reporterFactory->method('createReporter')->willReturn($reporter); @@ -187,7 +172,7 @@ public function testExecuteFailure(): void ->getMock(); $command->method('getConfigDto')->willReturn($configDto); - $command->method('getFilesFromDirectories')->willReturn($this->createGenerator([new \SplFileInfo(__FILE__)])); + $command->method('getFilesFromDirectories')->willReturn($this->createGenerator([new SplFileInfo(__FILE__)])); $application = new Application(); $application->add($command); @@ -196,11 +181,30 @@ public function testExecuteFailure(): void $result = $commandTester->execute([], ['interactive' => false]); - $this->assertSame(1, $result); - $this->assertStringContainsString('Comment thresholds were exceeded!', $commandTester->getDisplay()); + self::assertSame(1, $result); + self::assertStringContainsString('Comment thresholds were exceeded!', $commandTester->getDisplay()); + } + + private function removeDirectory(string $dir): void + { + if (!is_dir($dir)) { + return; + } + + $files = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST, + ); + + foreach ($files as $fileinfo) { + $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink'); + $todo($fileinfo->getRealPath()); + } + + rmdir($dir); } - private function createGenerator(array $items): \Generator + private function createGenerator(array $items): Generator { foreach ($items as $item) { yield $item; diff --git a/tests/Commands/AnalyzeFilesCommandTest.php b/tests/Commands/AnalyzeFilesCommandTest.php index 1580532..cbdf11c 100644 --- a/tests/Commands/AnalyzeFilesCommandTest.php +++ b/tests/Commands/AnalyzeFilesCommandTest.php @@ -5,7 +5,10 @@ namespace Commands; use FilesystemIterator; +use Generator; use PHPUnit\Framework\TestCase; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; use SavinMikhail\CommentsDensity\Analyzer\Analyzer; use SavinMikhail\CommentsDensity\Analyzer\AnalyzerFactory; use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CdsDTO; @@ -21,6 +24,7 @@ use SavinMikhail\CommentsDensity\Reporters\ReporterFactory; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; + use function ini_set; use function is_dir; use function mkdir; @@ -28,7 +32,7 @@ use function sys_get_temp_dir; use function uniqid; -final class AnalyzeFilesCommandTest extends TestCase +final class AnalyzeFilesCommandTest extends TestCase { private string $tempCacheDir; @@ -38,7 +42,7 @@ protected function setUp(): void // Create a temporary cache directory for each test $this->tempCacheDir = sys_get_temp_dir() . '/cache_' . uniqid(); - mkdir($this->tempCacheDir, 0777, true); + mkdir($this->tempCacheDir, 0o777, true); } protected function tearDown(): void @@ -47,32 +51,6 @@ protected function tearDown(): void $this->removeDirectory($this->tempCacheDir); } - private function removeDirectory(string $dir): void - { - if (!is_dir($dir)) { - return; - } - - $files = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS), - \RecursiveIteratorIterator::CHILD_FIRST - ); - - foreach ($files as $fileinfo) { - $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink'); - $todo($fileinfo->getRealPath()); - } - - rmdir($dir); - } - - private function createGenerator(array $items): \Generator - { - foreach ($items as $item) { - yield $item; - } - } - public function testExecuteSuccess(): void { $docblockConfigDTO = new MissingDocblockConfigDTO( @@ -83,7 +61,7 @@ public function testExecuteSuccess(): void true, true, true, - true + true, ); $configDto = $this->createMock(ConfigDTO::class); @@ -107,7 +85,7 @@ public function testExecuteSuccess(): void new PerformanceMetricsDTO(0, 0), new ComToLocDTO(0, 'red'), new CdsDTO(0, 'red'), - false + false, ); $analyzer ->method('analyze') @@ -119,7 +97,7 @@ public function testExecuteSuccess(): void $reporter = $this->createMock(ConsoleReporter::class); $reporter ->method('report') - ->with($this->equalTo($outputDTO)); + ->with(self::equalTo($outputDTO)); $reporterFactory = $this->createMock(ReporterFactory::class); $reporterFactory->method('createReporter')->willReturn($reporter); @@ -137,8 +115,8 @@ public function testExecuteSuccess(): void $result = $commandTester->execute(['files' => [__FILE__]], ['interactive' => false]); - $this->assertSame(0, $result); - $this->assertStringContainsString('Comment thresholds are passed!', $commandTester->getDisplay()); + self::assertSame(0, $result); + self::assertStringContainsString('Comment thresholds are passed!', $commandTester->getDisplay()); } public function testExecuteFailure(): void @@ -151,7 +129,7 @@ public function testExecuteFailure(): void true, true, true, - true + true, ); $configDto = $this->createMock(ConfigDTO::class); @@ -175,7 +153,7 @@ public function testExecuteFailure(): void new PerformanceMetricsDTO(0, 0), new ComToLocDTO(0, 'red'), new CdsDTO(0, 'red'), - true + true, ); $analyzer ->method('analyze') @@ -187,7 +165,7 @@ public function testExecuteFailure(): void $reporter = $this->createMock(ConsoleReporter::class); $reporter ->method('report') - ->with($this->equalTo($outputDTO)); + ->with(self::equalTo($outputDTO)); $reporterFactory = $this->createMock(ReporterFactory::class); $reporterFactory->method('createReporter')->willReturn($reporter); @@ -205,7 +183,33 @@ public function testExecuteFailure(): void $result = $commandTester->execute(['files' => [__FILE__]], ['interactive' => false]); - $this->assertSame(1, $result); - $this->assertStringContainsString('Comment thresholds were exceeded!', $commandTester->getDisplay()); + self::assertSame(1, $result); + self::assertStringContainsString('Comment thresholds were exceeded!', $commandTester->getDisplay()); + } + + private function removeDirectory(string $dir): void + { + if (!is_dir($dir)) { + return; + } + + $files = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST, + ); + + foreach ($files as $fileinfo) { + $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink'); + $todo($fileinfo->getRealPath()); + } + + rmdir($dir); + } + + private function createGenerator(array $items): Generator + { + foreach ($items as $item) { + yield $item; + } } -} \ No newline at end of file +} diff --git a/tests/Commands/BaselineCommandTest.php b/tests/Commands/BaselineCommandTest.php index 0b4746a..8bb75eb 100644 --- a/tests/Commands/BaselineCommandTest.php +++ b/tests/Commands/BaselineCommandTest.php @@ -5,7 +5,10 @@ namespace SavinMikhail\Tests\CommentsDensity\Commands; use FilesystemIterator; +use Generator; use PHPUnit\Framework\TestCase; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; use SavinMikhail\CommentsDensity\Analyzer\Analyzer; use SavinMikhail\CommentsDensity\Analyzer\AnalyzerFactory; use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CdsDTO; @@ -16,8 +19,10 @@ use SavinMikhail\CommentsDensity\Commands\BaselineCommand; use SavinMikhail\CommentsDensity\Config\DTO\ConfigDTO; use SavinMikhail\CommentsDensity\Config\DTO\MissingDocblockConfigDTO; +use SplFileInfo; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; + use function ini_set; use function is_dir; use function mkdir; @@ -35,7 +40,7 @@ protected function setUp(): void // Create a temporary cache directory for each test $this->tempCacheDir = sys_get_temp_dir() . '/cache_' . uniqid(); - mkdir($this->tempCacheDir, 0777, true); + mkdir($this->tempCacheDir, 0o777, true); } protected function tearDown(): void @@ -44,32 +49,6 @@ protected function tearDown(): void $this->removeDirectory($this->tempCacheDir); } - private function removeDirectory(string $dir): void - { - if (!is_dir($dir)) { - return; - } - - $files = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS), - \RecursiveIteratorIterator::CHILD_FIRST - ); - - foreach ($files as $fileinfo) { - $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink'); - $todo($fileinfo->getRealPath()); - } - - rmdir($dir); - } - - private function createGenerator(array $items): \Generator - { - foreach ($items as $item) { - yield $item; - } - } - public function testExecute(): void { $docblockConfigDTO = new MissingDocblockConfigDTO( @@ -80,7 +59,7 @@ public function testExecute(): void true, true, true, - true + true, ); $configDto = $this->createMock(ConfigDTO::class); @@ -104,7 +83,7 @@ public function testExecute(): void new PerformanceMetricsDTO(0, 0), new ComToLocDTO(0, 'red'), new CdsDTO(0, 'red'), - false + false, ); $analyzer ->method('analyze') @@ -123,7 +102,7 @@ public function testExecute(): void $command->method('getConfigDto')->willReturn($configDto); $command ->method('getFilesFromDirectories') - ->willReturn($this->createGenerator([new \SplFileInfo(__FILE__)])); + ->willReturn($this->createGenerator([new SplFileInfo(__FILE__)])); $application = new Application(); $application->add($command); @@ -132,7 +111,33 @@ public function testExecute(): void $result = $commandTester->execute([], ['interactive' => false]); - $this->assertSame(0, $result); - $this->assertStringContainsString('Baseline generated successfully!', $commandTester->getDisplay()); + self::assertSame(0, $result); + self::assertStringContainsString('Baseline generated successfully!', $commandTester->getDisplay()); + } + + private function removeDirectory(string $dir): void + { + if (!is_dir($dir)) { + return; + } + + $files = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST, + ); + + foreach ($files as $fileinfo) { + $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink'); + $todo($fileinfo->getRealPath()); + } + + rmdir($dir); + } + + private function createGenerator(array $items): Generator + { + foreach ($items as $item) { + yield $item; + } } } diff --git a/tests/Comments/CommentTest.php b/tests/Comments/CommentTest.php index afed820..87057f8 100755 --- a/tests/Comments/CommentTest.php +++ b/tests/Comments/CommentTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; +use ReflectionClass; use SavinMikhail\CommentsDensity\Comments\Comment; use SavinMikhail\CommentsDensity\Comments\CommentFactory; use SavinMikhail\CommentsDensity\Comments\DocBlockComment; @@ -14,14 +15,14 @@ use SavinMikhail\CommentsDensity\Comments\RegularComment; use SavinMikhail\CommentsDensity\Comments\TodoComment; -class CommentTest extends TestCase +final class CommentTest extends TestCase { public static function regularCommentRegexDataProvider(): array { return [ - ['//dd()', RegularComment::class], - ['#something', RegularComment::class], - ['/* bla bal */', RegularComment::class], + ['//dd()', RegularComment::class], + ['#something', RegularComment::class], + ['/* bla bal */', RegularComment::class], ['/** @var string $name */', DocBlockComment::class], ['//todo: asdf', TodoComment::class], ['// TODO asdf', TodoComment::class], @@ -31,14 +32,6 @@ public static function regularCommentRegexDataProvider(): array ]; } - #[DataProvider('regularCommentRegexDataProvider')] - public function testRegularCommentRegex(string $comment, string $class): void - { - $factory = new CommentFactory(); - $commentType = $factory->classifyComment($comment); - $this->assertTrue($commentType instanceof $class); - } - public static function isWithinThresholdDataProvider(): array { return [ @@ -55,15 +48,6 @@ public static function isWithinThresholdDataProvider(): array ]; } - #[DataProvider('isWithinThresholdDataProvider')] - public function testIsWithinThreshold(string $class, int $count, array $thresholds, bool $expected): void - { - /** @var Comment $comment */ - $comment = new $class(); - $result = $this->invokeMethod($comment, 'isWithinThreshold', [$count, $thresholds]); - $this->assertEquals($expected, $result); - } - public static function isExceededThresholdDataProvider(): array { return [ @@ -80,15 +64,6 @@ public static function isExceededThresholdDataProvider(): array ]; } - #[DataProvider('isExceededThresholdDataProvider')] - public function testIsExceededThreshold(string $class, int $count, array $thresholds, bool $expected): void - { - /** @var Comment $comment */ - $comment = new $class(); - $this->invokeMethod($comment, 'getStatColor', [$count, $thresholds]); - $this->assertEquals($expected, $comment->hasExceededThreshold()); - } - public static function getStatColorDataProvider(): array { return [ @@ -98,29 +73,55 @@ public static function getStatColorDataProvider(): array ]; } + #[DataProvider('regularCommentRegexDataProvider')] + public function testRegularCommentRegex(string $comment, string $class): void + { + $factory = new CommentFactory(); + $commentType = $factory->classifyComment($comment); + self::assertInstanceOf($class, $commentType); + } + + #[DataProvider('isWithinThresholdDataProvider')] + public function testIsWithinThreshold(string $class, int $count, array $thresholds, bool $expected): void + { + /** @var Comment $comment */ + $comment = new $class(); + $result = $this->invokeMethod($comment, 'isWithinThreshold', [$count, $thresholds]); + self::assertEquals($expected, $result); + } + + #[DataProvider('isExceededThresholdDataProvider')] + public function testIsExceededThreshold(string $class, int $count, array $thresholds, bool $expected): void + { + /** @var Comment $comment */ + $comment = new $class(); + $this->invokeMethod($comment, 'getStatColor', [$count, $thresholds]); + self::assertEquals($expected, $comment->hasExceededThreshold()); + } + #[DataProvider('getStatColorDataProvider')] public function testGetStatColor(string $class, int $count, array $thresholds, string $expectedColor): void { $comment = new $class(); $color = $comment->getStatColor($count, $thresholds); - $this->assertEquals($expectedColor, $color); + self::assertEquals($expectedColor, $color); } public function testToString(): void { $comment = new RegularComment(); - $this->assertEquals('regular', (string) $comment); + self::assertEquals('regular', (string) $comment); $comment = new DocBlockComment(); - $this->assertEquals('docBlock', (string) $comment); + self::assertEquals('docBlock', (string) $comment); } /** - * Helper method to invoke protected/private methods + * Helper method to invoke protected/private methods. */ private function invokeMethod(object $object, string $methodName, array $parameters = []) { - $reflection = new \ReflectionClass($object); + $reflection = new ReflectionClass($object); $method = $reflection->getMethod($methodName); $method->setAccessible(true); diff --git a/tests/Composer/CommentsDensityPluginTest.php b/tests/Composer/CommentsDensityPluginTest.php index 4668ba8..0637559 100644 --- a/tests/Composer/CommentsDensityPluginTest.php +++ b/tests/Composer/CommentsDensityPluginTest.php @@ -9,11 +9,12 @@ use Composer\Script\ScriptEvents; use Mockery; use PHPUnit\Framework\TestCase; +use ReflectionClass; use SavinMikhail\CommentsDensity\Composer\CommentsDensityPlugin; final class CommentsDensityPluginTest extends TestCase { - public function tearDown(): void + protected function tearDown(): void { Mockery::close(); } @@ -26,7 +27,7 @@ public function testActivate(): void $plugin = new CommentsDensityPlugin(); $plugin->activate($composer, $io); - $this->assertTrue(true); // No activation logic to test + self::assertTrue(true); // No activation logic to test } public function testDeactivate(): void @@ -37,7 +38,7 @@ public function testDeactivate(): void $plugin = new CommentsDensityPlugin(); $plugin->deactivate($composer, $io); - $this->assertTrue(true); // No deactivation logic to test + self::assertTrue(true); // No deactivation logic to test } public function testUninstall(): void @@ -48,7 +49,7 @@ public function testUninstall(): void $plugin = new CommentsDensityPlugin(); $plugin->uninstall($composer, $io); - $this->assertTrue(true); // No uninstallation logic to test + self::assertTrue(true); // No uninstallation logic to test } public function testGetSubscribedEvents(): void @@ -59,7 +60,7 @@ public function testGetSubscribedEvents(): void ScriptEvents::POST_UPDATE_CMD => 'promptForSetup', ]; - $this->assertSame($expectedEvents, $events); + self::assertSame($expectedEvents, $events); } public function testPromptForSetup(): void @@ -76,11 +77,10 @@ public function testPromptForSetup(): void $event->shouldReceive('getIO')->andReturn($io); CommentsDensityPlugin::promptForSetup($event); - //mockery assertions aint being counted by coverage - $this->assertTrue(true); + // mockery assertions aint being counted by coverage + self::assertTrue(true); } - public function testPromptForConfigFile(): void { $io = Mockery::mock(IOInterface::class); @@ -91,11 +91,11 @@ public function testPromptForConfigFile(): void $plugin = new CommentsDensityPlugin(); - $reflection = new \ReflectionClass($plugin); + $reflection = new ReflectionClass($plugin); $method = $reflection->getMethod('promptForConfigFile'); $method->setAccessible(true); $method->invoke($plugin, $io); - $this->assertFileExists('comments_density.php'); + self::assertFileExists('comments_density.php'); } } diff --git a/tests/ConfigLoaderTest.php b/tests/ConfigLoaderTest.php index 567b826..ec34330 100644 --- a/tests/ConfigLoaderTest.php +++ b/tests/ConfigLoaderTest.php @@ -6,12 +6,17 @@ use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; +use ReflectionClass; use SavinMikhail\CommentsDensity\Config\ConfigLoader; use SavinMikhail\CommentsDensity\Config\DTO\ConfigDTO; use SavinMikhail\CommentsDensity\Config\DTO\MissingDocblockConfigDTO; use SavinMikhail\CommentsDensity\Exception\CommentsDensityException; -class ConfigLoaderTest extends TestCase +use function define; + +use const DIRECTORY_SEPARATOR; + +final class ConfigLoaderTest extends TestCase { private ConfigLoader $configLoader; @@ -21,16 +26,7 @@ protected function setUp(): void $this->configLoader = new ConfigLoader(); } - private function invokeMethod(object $object, string $methodName, array $parameters = []) - { - $reflection = new \ReflectionClass($object); - $method = $reflection->getMethod($methodName); - $method->setAccessible(true); - - return $method->invokeArgs($object, $parameters); - } - - public function testParseConfigFileThrowsExceptionWhenFileDoesNotExist() + public function testParseConfigFileThrowsExceptionWhenFileDoesNotExist(): void { $this->expectException(CommentsDensityException::class); $this->expectExceptionMessage('Config file does not exists! Looking for non_existent_file.php'); @@ -38,74 +34,74 @@ public function testParseConfigFileThrowsExceptionWhenFileDoesNotExist() $this->invokeMethod($this->configLoader, 'parseConfigFile', ['non_existent_file.php']); } - public function testParseConfigFileReturnsArrayWhenFileExists() + public function testParseConfigFileReturnsArrayWhenFileExists(): void { vfsStream::setup('root', null, ['comments_density.php' => ' "value"];']); $filePath = vfsStream::url('root/comments_density.php'); $config = $this->invokeMethod($this->configLoader, 'parseConfigFile', [$filePath]); - $this->assertIsArray($config); - $this->assertArrayHasKey('key', $config); - $this->assertEquals('value', $config['key']); + self::assertIsArray($config); + self::assertArrayHasKey('key', $config); + self::assertEquals('value', $config['key']); } - public function testGetOutput() + public function testGetOutput(): void { $config = [ 'output' => [ - 'file' => 'tuptuo.html' - ] + 'file' => 'tuptuo.html', + ], ]; $outputConfig = $this->invokeMethod($this->configLoader, 'getOutput', [$config]); - $this->assertStringContainsString(DIRECTORY_SEPARATOR . 'tuptuo.html', $outputConfig->file); + self::assertStringContainsString(DIRECTORY_SEPARATOR . 'tuptuo.html', $outputConfig->file); } - public function testGetOnly() + public function testGetOnly(): void { $config = [ - 'only' => ['fixme', 'todo'] + 'only' => ['fixme', 'todo'], ]; $only = $this->invokeMethod($this->configLoader, 'getOnly', [$config]); - $this->assertEquals($config['only'], $only); + self::assertEquals($config['only'], $only); } - public function testGetOnlyReturnsEmptyArrayWhenNotSet() + public function testGetOnlyReturnsEmptyArrayWhenNotSet(): void { $config = []; $only = $this->invokeMethod($this->configLoader, 'getOnly', [$config]); - $this->assertEmpty($only); + self::assertEmpty($only); } - public function testGetThresholds() + public function testGetThresholds(): void { $config = [ - 'thresholds' => ['key' => 'value'] + 'thresholds' => ['key' => 'value'], ]; $thresholds = $this->invokeMethod($this->configLoader, 'getThresholds', [$config]); - $this->assertEquals($config['thresholds'], $thresholds); + self::assertEquals($config['thresholds'], $thresholds); } - public function testGetThresholdsReturnsEmptyArrayWhenNotSet() + public function testGetThresholdsReturnsEmptyArrayWhenNotSet(): void { $config = []; $thresholds = $this->invokeMethod($this->configLoader, 'getThresholds', [$config]); - $this->assertEmpty($thresholds); + self::assertEmpty($thresholds); } - public function testGetConfigDto() + public function testGetConfigDto(): void { - $this->markTestIncomplete(); + self::markTestIncomplete(); $root = vfsStream::setup('root', null, [ 'dir1' => [], 'dir2' => [], @@ -126,7 +122,7 @@ public function testGetConfigDto() "requireForAllMethods" => true, ], "use_baseline" => true, - ];' + ];', ]); $configFile = vfsStream::url('root/comments_density.php'); @@ -142,13 +138,13 @@ public function testGetConfigDto() $configDto = $configLoaderMock->getConfigDto(); - $this->assertInstanceOf(ConfigDTO::class, $configDto); + self::assertInstanceOf(ConfigDTO::class, $configDto); } - public function testGetDirectoriesThrowsExceptionWhenDirectoryDoesNotExist() + public function testGetDirectoriesThrowsExceptionWhenDirectoryDoesNotExist(): void { $config = [ - 'directories' => ['non_existent_directory'] + 'directories' => ['non_existent_directory'], ]; $this->expectException(CommentsDensityException::class); @@ -157,13 +153,13 @@ public function testGetDirectoriesThrowsExceptionWhenDirectoryDoesNotExist() $this->invokeMethod($this->configLoader, 'getDirectories', [$config]); } - public function testGetDirectories() + public function testGetDirectories(): void { - $this->markTestIncomplete(); + self::markTestIncomplete(); vfsStream::setup('root', null, ['dir1' => [], 'dir2' => []]); $config = [ - 'directories' => ['dir1', 'dir2'] + 'directories' => ['dir1', 'dir2'], ]; $configLoaderMock = $this->getMockBuilder(ConfigLoader::class) @@ -175,12 +171,12 @@ public function testGetDirectories() $directories = $this->invokeMethod($configLoaderMock, 'getDirectories', [$config]); - $this->assertCount(2, $directories); + self::assertCount(2, $directories); } - public function testGetProjectRoot() + public function testGetProjectRoot(): void { - $this->markTestIncomplete(); + self::markTestIncomplete(); $configLoaderMock = $this->getMockBuilder(ConfigLoader::class) ->onlyMethods(['getProjectRoot']) @@ -191,10 +187,10 @@ public function testGetProjectRoot() $projectRoot = $this->invokeMethod($configLoaderMock, 'getProjectRoot'); - $this->assertStringEndsWith(DIRECTORY_SEPARATOR . 'tests', $projectRoot); + self::assertStringEndsWith(DIRECTORY_SEPARATOR . 'tests', $projectRoot); } - public function testGetMissingDocblockConfig() + public function testGetMissingDocblockConfig(): void { $config = [ 'missingDocblock' => [ @@ -205,13 +201,22 @@ public function testGetMissingDocblockConfig() 'function' => true, 'property' => true, 'constant' => true, - 'requireForAllMethods' => true - ] + 'requireForAllMethods' => true, + ], ]; $missingDocblockConfigDTO = $this->invokeMethod($this->configLoader, 'getMissingDocblockConfig', [$config]); - $this->assertInstanceOf(MissingDocblockConfigDTO::class, $missingDocblockConfigDTO); - $this->assertTrue($missingDocblockConfigDTO->class); + self::assertInstanceOf(MissingDocblockConfigDTO::class, $missingDocblockConfigDTO); + self::assertTrue($missingDocblockConfigDTO->class); + } + + private function invokeMethod(object $object, string $methodName, array $parameters = []) + { + $reflection = new ReflectionClass($object); + $method = $reflection->getMethod($methodName); + $method->setAccessible(true); + + return $method->invokeArgs($object, $parameters); } } diff --git a/tests/Metrics/CDSTest.php b/tests/Metrics/CDSTest.php index 2480ec1..2041eac 100644 --- a/tests/Metrics/CDSTest.php +++ b/tests/Metrics/CDSTest.php @@ -5,6 +5,7 @@ namespace SavinMikhail\Tests\CommentsDensity\Metrics; use PHPUnit\Framework\TestCase; +use ReflectionClass; use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CdsDTO; use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\CommentStatisticsDTO; use SavinMikhail\CommentsDensity\Comments\CommentFactory; @@ -13,6 +14,7 @@ final class CDSTest extends TestCase { private CDS $cds; + private CommentFactory $commentFactory; protected function setUp(): void @@ -33,9 +35,9 @@ public function testCalculateCDS(): void ]; $cdsValue = $this->cds->calculateCDS($commentStatistics); - $this->assertIsFloat($cdsValue); - $this->assertGreaterThanOrEqual(0, $cdsValue); - $this->assertLessThanOrEqual(1, $cdsValue); + self::assertIsFloat($cdsValue); + self::assertGreaterThanOrEqual(0, $cdsValue); + self::assertLessThanOrEqual(1, $cdsValue); } public function testPrepareCDS(): void @@ -43,31 +45,31 @@ public function testPrepareCDS(): void $cdsValue = 0.75; $cdsDTO = $this->cds->prepareCDS($cdsValue); - $this->assertInstanceOf(CdsDTO::class, $cdsDTO); - $this->assertEquals(0.75, $cdsDTO->cds); - $this->assertEquals('green', $cdsDTO->color); + self::assertInstanceOf(CdsDTO::class, $cdsDTO); + self::assertEquals(0.75, $cdsDTO->cds); + self::assertEquals('green', $cdsDTO->color); } public function testGetColorForCDS(): void { - $reflection = new \ReflectionClass($this->cds); + $reflection = new ReflectionClass($this->cds); $method = $reflection->getMethod('getColorForCDS'); $method->setAccessible(true); - $this->assertEquals('green', $method->invokeArgs($this->cds, [0.75])); - $this->assertEquals('red', $method->invokeArgs($this->cds, [0.25])); + self::assertEquals('green', $method->invokeArgs($this->cds, [0.75])); + self::assertEquals('red', $method->invokeArgs($this->cds, [0.25])); $cds = new CDS([], new CommentFactory()); - $reflection = new \ReflectionClass($cds); + $reflection = new ReflectionClass($cds); $method = $reflection->getMethod('getColorForCDS'); $method->setAccessible(true); - $this->assertEquals('white', $method->invokeArgs($cds, [0.75])); + self::assertEquals('white', $method->invokeArgs($cds, [0.75])); } public function testHasExceededThreshold(): void { - $this->assertFalse($this->cds->hasExceededThreshold()); + self::assertFalse($this->cds->hasExceededThreshold()); $commentStatistics = [ new CommentStatisticsDTO('red', 'docBlock', 12, 'red', 1), @@ -77,6 +79,6 @@ public function testHasExceededThreshold(): void $cds = $this->cds->calculateCDS($commentStatistics); $this->cds->prepareCDS($cds); - $this->assertTrue($this->cds->hasExceededThreshold()); + self::assertTrue($this->cds->hasExceededThreshold()); } } diff --git a/tests/Metrics/ComToLocTest.php b/tests/Metrics/ComToLocTest.php index 7c8c225..37f9eba 100644 --- a/tests/Metrics/ComToLocTest.php +++ b/tests/Metrics/ComToLocTest.php @@ -17,8 +17,8 @@ public function testPrepareComToLocAboveThreshold(): void $comToLocDTO = $comToLoc->prepareComToLoc($commentStat, 2); - $this->assertEquals($comToLocDTO->comToLoc, 1); - $this->assertEquals($comToLocDTO->color, 'green'); + self::assertEquals($comToLocDTO->comToLoc, 1); + self::assertEquals($comToLocDTO->color, 'green'); } public function testPrepareComToLocWithoutThreshold(): void @@ -27,8 +27,8 @@ public function testPrepareComToLocWithoutThreshold(): void $commentStat = [new CommentStatisticsDTO('red', 'missingDocblock', 2, 'red', 3)]; $comToLocDTO = $comToLoc->prepareComToLoc($commentStat, 2); - $this->assertEquals($comToLocDTO->comToLoc, 1); - $this->assertEquals($comToLocDTO->color, 'white'); + self::assertEquals($comToLocDTO->comToLoc, 1); + self::assertEquals($comToLocDTO->color, 'white'); } public function testPrepareComToLocColorWhenExceedThreshold(): void @@ -38,8 +38,8 @@ public function testPrepareComToLocColorWhenExceedThreshold(): void $comToLocDTO = $comToLoc->prepareComToLoc($commentStat, 2); - $this->assertEquals($comToLocDTO->comToLoc, 0.5); - $this->assertEquals($comToLocDTO->color, 'red'); + self::assertEquals($comToLocDTO->comToLoc, 0.5); + self::assertEquals($comToLocDTO->color, 'red'); } public function testPrepareComToLocWithZeroLinesOfCode(): void @@ -49,8 +49,8 @@ public function testPrepareComToLocWithZeroLinesOfCode(): void $comToLocDTO = $comToLoc->prepareComToLoc($commentStat, 0); - $this->assertEquals($comToLocDTO->comToLoc, 0); - $this->assertEquals($comToLocDTO->color, 'red'); + self::assertEquals($comToLocDTO->comToLoc, 0); + self::assertEquals($comToLocDTO->color, 'red'); } public function testPrepareComToLocExceedThreshold(): void @@ -60,6 +60,6 @@ public function testPrepareComToLocExceedThreshold(): void $comToLoc->prepareComToLoc($commentStat, 2); $exceededThreshold = $comToLoc->hasExceededThreshold(); - $this->assertEquals(true, $exceededThreshold); + self::assertTrue($exceededThreshold); } -} \ No newline at end of file +} diff --git a/tests/Metrics/PerformanceMonitorTest.php b/tests/Metrics/PerformanceMonitorTest.php index 503eadc..3b37925 100644 --- a/tests/Metrics/PerformanceMonitorTest.php +++ b/tests/Metrics/PerformanceMonitorTest.php @@ -5,6 +5,7 @@ namespace SavinMikhail\Tests\CommentsDensity\Metrics; use PHPUnit\Framework\TestCase; +use ReflectionClass; use SavinMikhail\CommentsDensity\Analyzer\DTO\Output\PerformanceMetricsDTO; use SavinMikhail\CommentsDensity\Metrics\ResourceUtilization; @@ -13,19 +14,19 @@ final class PerformanceMonitorTest extends TestCase public function testStart(): void { $performanceMonitor = new ResourceUtilization(); - $reflection = new \ReflectionClass($performanceMonitor); + $reflection = new ReflectionClass($performanceMonitor); $startTimeProperty = $reflection->getProperty('startTime'); $startTimeProperty->setAccessible(true); $performanceMonitor->start(); - $this->assertNotNull($startTimeProperty->getValue($performanceMonitor)); + self::assertNotNull($startTimeProperty->getValue($performanceMonitor)); } public function testStop(): void { $performanceMonitor = new ResourceUtilization(); - $reflection = new \ReflectionClass($performanceMonitor); + $reflection = new ReflectionClass($performanceMonitor); $endTimeProperty = $reflection->getProperty('endTime'); $endTimeProperty->setAccessible(true); $peakMemoryUsageProperty = $reflection->getProperty('peakMemoryUsage'); @@ -35,8 +36,8 @@ public function testStop(): void usleep(50000); $performanceMonitor->stop(); - $this->assertNotNull($endTimeProperty->getValue($performanceMonitor)); - $this->assertNotNull($peakMemoryUsageProperty->getValue($performanceMonitor)); + self::assertNotNull($endTimeProperty->getValue($performanceMonitor)); + self::assertNotNull($peakMemoryUsageProperty->getValue($performanceMonitor)); } public function testGetPerformanceMetrics(): void @@ -48,15 +49,15 @@ public function testGetPerformanceMetrics(): void $performanceMetrics = $performanceMonitor->getPerformanceMetrics(); - $this->assertInstanceOf(PerformanceMetricsDTO::class, $performanceMetrics); + self::assertInstanceOf(PerformanceMetricsDTO::class, $performanceMetrics); - $reflection = new \ReflectionClass($performanceMetrics); + $reflection = new ReflectionClass($performanceMetrics); $executionTimeProperty = $reflection->getProperty('executionTime'); $executionTimeProperty->setAccessible(true); $peakMemoryUsageProperty = $reflection->getProperty('peakMemoryUsage'); $peakMemoryUsageProperty->setAccessible(true); - $this->assertGreaterThan(0, $executionTimeProperty->getValue($performanceMetrics)); - $this->assertGreaterThan(0, $peakMemoryUsageProperty->getValue($performanceMetrics)); + self::assertGreaterThan(0, $executionTimeProperty->getValue($performanceMetrics)); + self::assertGreaterThan(0, $peakMemoryUsageProperty->getValue($performanceMetrics)); } } diff --git a/tests/MissingDocblock/MDBAdvancedCheckForMethodTest.php b/tests/MissingDocblock/MDBAdvancedCheckForMethodTest.php index 72b00c3..8ceb6f8 100644 --- a/tests/MissingDocblock/MDBAdvancedCheckForMethodTest.php +++ b/tests/MissingDocblock/MDBAdvancedCheckForMethodTest.php @@ -9,7 +9,9 @@ use PHPUnit\Framework\TestCase; use SavinMikhail\CommentsDensity\Config\DTO\MissingDocblockConfigDTO; use SavinMikhail\CommentsDensity\MissingDocblock\MissingDocBlockAnalyzer; + use function file_get_contents; + use const DIRECTORY_SEPARATOR; final class MDBAdvancedCheckForMethodTest extends TestCase @@ -18,723 +20,689 @@ public static function templateGenericDataProvider(): Generator { yield 'method with templated class from sources' => [ <<<'CODE' - [ <<<'CODE' -getMissingDocblocks($code, 'test.php'); - $this->assertCount($expectedCount, $missingDocBlocks); - } - public static function genericDocblockDataProvider(): Generator { yield 'non iterable class' => [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - 12, - 'asdf' - ]; - } -} + class Foo + { + public function bar(): array + { + return [ + [], + 'asdf' => 12, + 'asdf' + ]; + } + } -CODE - , 1 + CODE, 1, ]; yield 'method with mixed array' => [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - new User(), - 'user2' => new User() - ]; - } -} + class Foo + { + public function associativeArray(): array + { + return [ + 'user1' => new User(), + 'user2' => new User() + ]; + } + } -CODE - , 1 + CODE, 1, ]; yield 'method with other iterable' => [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' -get(); + function foo(InterfaceExtendsIterable $array) + { + $user = $array->get(); - $name = $user->name; -} + $name = $user->name; + } -CODE, - 1 + CODE, + 1, ]; yield 'function with interface with template' => [ <<<'CODE' -get(); + function foo(InterfaceExtendsIterable $array) + { + $user = $array->get(); - $name = $user->name; -} + $name = $user->name; + } -CODE, - 1 + CODE, + 1, ]; yield 'function with class extended from class that implementing ArrayAccess' => [ <<<'CODE' -getMissingDocblocks($code, 'test.php'); - $this->assertCount($expectedCount, $missingDocBlocks); - } - public static function uncaughtExceptionDocblockDataProvider(): Generator { yield 'method with uncaught exception' => [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ - file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../TestFiles/ClassWithMethodThatThrowsAndHasTag.php') //made for class_exists() function work - , 1 + file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../TestFiles/ClassWithMethodThatThrowsAndHasTag.php') // made for class_exists() function work + , 1, ]; yield 'method without catching method that throws and has throws tag in the different class' => [ - file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../TestFiles/ClassWithCallForThrowingMethodInDifferentClass.php') //made for class_exists() function work - , 1 + file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../TestFiles/ClassWithCallForThrowingMethodInDifferentClass.php') // made for class_exists() function work + , 1, ]; yield 'method that catching method that throws and has throws tag in the different class' => [ - file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../TestFiles/ClassWithCallForThrowingMethodInDifferentClassInTryCatch.php') //made for class_exists() function work - , 0 + file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../TestFiles/ClassWithCallForThrowingMethodInDifferentClassInTryCatch.php') // made for class_exists() function work + , 0, ]; yield 'method that not catching method that throws and has throws tag in the different class' => [ - file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../TestFiles/ClassThatNotCatchingExceptionFromCallMethodOfAnotherClass.php') //made for class_exists() function work - , 1 + file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../TestFiles/ClassThatNotCatchingExceptionFromCallMethodOfAnotherClass.php') // made for class_exists() function work + , 1, ]; yield 'method that catching method that throws and does not have throws tag in the different class' => [ - file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../TestFiles/ClassThatCatchingMethodCallOfAnotherClassWhichDoesNotHaveDocblock.php') //made for class_exists() function work - , 0 + file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../TestFiles/ClassThatCatchingMethodCallOfAnotherClassWhichDoesNotHaveDocblock.php') // made for class_exists() function work + , 0, ]; } + #[DataProvider('templateGenericDataProvider')] + public function testTemplateGeneric(string $code, int $expectedCount): void + { + $analyzer = new MissingDocBlockAnalyzer( + new MissingDocblockConfigDTO( + false, + false, + false, + false, + true, + false, + false, + false, + ), + ); + + $missingDocBlocks = $analyzer->getMissingDocblocks($code, 'test.php'); + self::assertCount($expectedCount, $missingDocBlocks); + } + + #[DataProvider('genericDocblockDataProvider')] + public function testGenericDocblockDetection(string $code, int $expectedCount): void + { + $analyzer = new MissingDocBlockAnalyzer( + new MissingDocblockConfigDTO( + false, + false, + false, + false, + true, + false, + false, + false, + ), + ); + + $missingDocBlocks = $analyzer->getMissingDocblocks($code, 'test.php'); + self::assertCount($expectedCount, $missingDocBlocks); + } + #[DataProvider('uncaughtExceptionDocblockDataProvider')] public function testExceptionDocblockDetection(string $code, int $expectedCount): void { @@ -747,11 +715,11 @@ public function testExceptionDocblockDetection(string $code, int $expectedCount) true, false, false, - false - ) + false, + ), ); $missingDocBlocks = $analyzer->getMissingDocblocks($code, 'test.php'); - $this->assertCount($expectedCount, $missingDocBlocks); + self::assertCount($expectedCount, $missingDocBlocks); } -} \ No newline at end of file +} diff --git a/tests/MissingDocblock/MissingDocBlockAnalyzerTest.php b/tests/MissingDocblock/MissingDocBlockAnalyzerTest.php index 0d62ddf..e5a6572 100644 --- a/tests/MissingDocblock/MissingDocBlockAnalyzerTest.php +++ b/tests/MissingDocblock/MissingDocBlockAnalyzerTest.php @@ -25,103 +25,62 @@ protected function setUp(): void true, true, true, - true - ) + true, + ), ); } - public function testFunctionDeclaration(): void - { - $code = <<<'CODE' -analyzer->getMissingDocblocks($code, 'test.php'); - - $this->assertCount(1, $missingDocBlocks); - } - - #[DataProvider('methodDeclarationDataProvider')] - public function testMethodDeclaration(string $code, int $expectedCount): void - { - $missingDocBlocks = $this->analyzer->getMissingDocblocks($code, 'test.php'); - $this->assertCount($expectedCount, $missingDocBlocks); - } - public static function methodDeclarationDataProvider(): Generator { yield 'public method' => [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' -analyzer->getMissingDocblocks($code, 'test.php'); - - $this->assertCount(0, $missingDocBlocks); - } - public static function closureDataProvider(): array { return [ @@ -137,341 +96,360 @@ public static function closureDataProvider(): array ' 2;', - ] + ], ]; } - #[DataProvider('closureDataProvider')] - public function testClosuresAndArrowFunctions(string $code): void - { - $missingDocBlocks = $this->analyzer->getMissingDocblocks($code, 'test.php'); - $this->assertCount(0, $missingDocBlocks); - } - - #[DataProvider('classDeclarationDataProvider')] - public function testClassDeclaration(string $code, int $expectedCount): void - { - $missingDocBlocks = $this->analyzer->getMissingDocblocks($code, 'test.php'); - $this->assertCount($expectedCount, $missingDocBlocks); - } - public static function classDeclarationDataProvider(): Generator { yield 'simple class' => [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' -analyzer->getMissingDocblocks($code, 'test.php'); - $this->assertCount($expectedCount, $missingDocBlocks); - } - public static function traitDeclarationDataProvider(): Generator { yield 'simple trait' => [ <<<'CODE' -analyzer->getMissingDocblocks($code, 'test.php'); - $this->assertCount($expectedCount, $missingDocBlocks); - } - public static function interfaceDeclarationDataProvider(): Generator { yield 'simple interface' => [ <<<'CODE' -analyzer->getMissingDocblocks($code, 'test.php'); - $this->assertCount($expectedCount, $missingDocBlocks); - } - public static function anonymousClassDeclarationDataProvider(): Generator { yield 'simple anonymous class' => [ <<<'CODE' - [ <<<'CODE' -bindTo(new class() extends \Error { -}); -CODE - , 0 + bindTo(new class() extends \Error { + }); + CODE, 0, ]; } - #[DataProvider('enumDeclarationDataProvider')] - public function testEnumDeclaration(string $code, int $expectedCount): void - { - $missingDocBlocks = $this->analyzer->getMissingDocblocks($code, 'test.php'); - $this->assertCount($expectedCount, $missingDocBlocks); - } - public static function enumDeclarationDataProvider(): Generator { yield 'simple enum' => [ <<<'CODE' - [ <<<'CODE' -analyzer->getMissingDocblocks($code, 'test.php'); - $this->assertCount($expectedCount, $missingDocBlocks); - } - public static function propertyDataProvider(): Generator { yield 'public int property' => [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' - [ <<<'CODE' -analyzer->getMissingDocblocks($code, 'test.php'); -const METHOD = 'foo'; -/** -* - */ -class Foo -{ - final const FINAL = 2; - public const PUBLIC = 3; - protected const int TYPED = 4; - private const PRIVATE = 5; -} -CODE; + self::assertCount(1, $missingDocBlocks); + } + + #[DataProvider('methodDeclarationDataProvider')] + public function testMethodDeclaration(string $code, int $expectedCount): void + { + $missingDocBlocks = $this->analyzer->getMissingDocblocks($code, 'test.php'); + self::assertCount($expectedCount, $missingDocBlocks); + } + + public function testFunctionImport(): void + { + $code = <<<'CODE' + analyzer->getMissingDocblocks($code, 'test.php'); + + self::assertCount(0, $missingDocBlocks); + } + + #[DataProvider('closureDataProvider')] + public function testClosuresAndArrowFunctions(string $code): void + { + $missingDocBlocks = $this->analyzer->getMissingDocblocks($code, 'test.php'); + self::assertCount(0, $missingDocBlocks); + } + + #[DataProvider('classDeclarationDataProvider')] + public function testClassDeclaration(string $code, int $expectedCount): void + { + $missingDocBlocks = $this->analyzer->getMissingDocblocks($code, 'test.php'); + self::assertCount($expectedCount, $missingDocBlocks); + } + + #[DataProvider('traitDeclarationDataProvider')] + public function testTraitDeclaration(string $code, int $expectedCount): void + { + $missingDocBlocks = $this->analyzer->getMissingDocblocks($code, 'test.php'); + self::assertCount($expectedCount, $missingDocBlocks); + } + + #[DataProvider('interfaceDeclarationDataProvider')] + public function testInterfaceDeclaration(string $code, int $expectedCount): void + { + $missingDocBlocks = $this->analyzer->getMissingDocblocks($code, 'test.php'); + self::assertCount($expectedCount, $missingDocBlocks); + } + + #[DataProvider('anonymousClassDeclarationDataProvider')] + public function testAnonymousClassDeclaration(string $code, int $expectedCount): void + { + $missingDocBlocks = $this->analyzer->getMissingDocblocks($code, 'test.php'); + self::assertCount($expectedCount, $missingDocBlocks); + } + + #[DataProvider('enumDeclarationDataProvider')] + public function testEnumDeclaration(string $code, int $expectedCount): void + { + $missingDocBlocks = $this->analyzer->getMissingDocblocks($code, 'test.php'); + self::assertCount($expectedCount, $missingDocBlocks); + } + + #[DataProvider('propertyDataProvider')] + public function testProperties(string $code, int $expectedCount): void + { + $missingDocBlocks = $this->analyzer->getMissingDocblocks($code, 'test.php'); + self::assertCount($expectedCount, $missingDocBlocks); + } + + public function testConstant(): void + { + $code = <<<'CODE' + analyzer->getMissingDocblocks($code, 'test.php'); - $this->assertCount(4, $missingDocBlocks); + self::assertCount(4, $missingDocBlocks); } public function testGetColor(): void { - $this->assertEquals('red', $this->analyzer->getColor()); + self::assertEquals('red', $this->analyzer->getColor()); } public function testGetStatColor(): void { $thresholds = [ - 'missingDocBlock' => 10 + 'missingDocBlock' => 10, ]; // Case 1: Count below threshold - $this->assertEquals('green', $this->analyzer->getStatColor(5, $thresholds)); - $this->assertFalse($this->analyzer->hasExceededThreshold()); + self::assertEquals('green', $this->analyzer->getStatColor(5, $thresholds)); + self::assertFalse($this->analyzer->hasExceededThreshold()); // Case 2: Count at threshold - $this->assertEquals('green', $this->analyzer->getStatColor(10, $thresholds)); - $this->assertFalse($this->analyzer->hasExceededThreshold()); + self::assertEquals('green', $this->analyzer->getStatColor(10, $thresholds)); + self::assertFalse($this->analyzer->hasExceededThreshold()); // Case 3: Count above threshold - $this->assertEquals('red', $this->analyzer->getStatColor(15, $thresholds)); - $this->assertTrue($this->analyzer->hasExceededThreshold()); + self::assertEquals('red', $this->analyzer->getStatColor(15, $thresholds)); + self::assertTrue($this->analyzer->hasExceededThreshold()); // Case 4: Threshold not set - $this->assertEquals('white', $this->analyzer->getStatColor(15, [])); + self::assertEquals('white', $this->analyzer->getStatColor(15, [])); } public function testHasExceededThreshold(): void { $thresholds = [ - 'missingDocBlock' => 10 + 'missingDocBlock' => 10, ]; $this->analyzer->getStatColor(15, $thresholds); - $this->assertTrue($this->analyzer->hasExceededThreshold()); + self::assertTrue($this->analyzer->hasExceededThreshold()); } public function testGetName(): void { - $this->assertEquals('missingDocblock', $this->analyzer->getName()); + self::assertEquals('missingDocblock', $this->analyzer->getName()); } } diff --git a/tests/Reporters/HtmlReporterTest.php b/tests/Reporters/HtmlReporterTest.php index 57f0b84..9006805 100644 --- a/tests/Reporters/HtmlReporterTest.php +++ b/tests/Reporters/HtmlReporterTest.php @@ -48,14 +48,14 @@ public function testReportGeneration(): void $reporter->report($outputDTO); - $this->assertFileExists($this->reportPath); + self::assertFileExists($this->reportPath); $htmlContent = file_get_contents($this->reportPath); - $this->assertStringContainsString('Comment Density Report', $htmlContent); - $this->assertStringContainsString('

Comment Density Report

', $htmlContent); - $this->assertStringContainsString('

Execution Time: 123 ms

', $htmlContent); - $this->assertStringContainsString('

CDS: 0.45

', $htmlContent); - $this->assertStringContainsString('docblock', $htmlContent); - $this->assertStringContainsString('This is a docblock comment', $htmlContent); + self::assertStringContainsString('Comment Density Report', $htmlContent); + self::assertStringContainsString('

Comment Density Report

', $htmlContent); + self::assertStringContainsString('

Execution Time: 123 ms

', $htmlContent); + self::assertStringContainsString('

CDS: 0.45

', $htmlContent); + self::assertStringContainsString('docblock', $htmlContent); + self::assertStringContainsString('This is a docblock comment', $htmlContent); } } diff --git a/tests/TestFiles/ClassThatCatchingMethodCallOfAnotherClassWhichDoesNotHaveDocblock.php b/tests/TestFiles/ClassThatCatchingMethodCallOfAnotherClassWhichDoesNotHaveDocblock.php index 58663ed..5beb805 100644 --- a/tests/TestFiles/ClassThatCatchingMethodCallOfAnotherClassWhichDoesNotHaveDocblock.php +++ b/tests/TestFiles/ClassThatCatchingMethodCallOfAnotherClassWhichDoesNotHaveDocblock.php @@ -11,4 +11,4 @@ public function baz(): void $bar = new ClassWithThrowingMethodWithoutDocblock(); $bar->bar(); } -} \ No newline at end of file +} diff --git a/tests/TestFiles/ClassThatNotCatchingExceptionFromCallMethodOfAnotherClass.php b/tests/TestFiles/ClassThatNotCatchingExceptionFromCallMethodOfAnotherClass.php index 425d4d0..7720029 100644 --- a/tests/TestFiles/ClassThatNotCatchingExceptionFromCallMethodOfAnotherClass.php +++ b/tests/TestFiles/ClassThatNotCatchingExceptionFromCallMethodOfAnotherClass.php @@ -11,10 +11,10 @@ public function baz(): void { $bar = new ClassWithThrowingMethod(); + try { $bar->bar(); } catch (Exception) { - } } -} \ No newline at end of file +} diff --git a/tests/TestFiles/ClassWithCallForThrowingMethodInDifferentClassInTryCatch.php b/tests/TestFiles/ClassWithCallForThrowingMethodInDifferentClassInTryCatch.php index 2493c9f..7cfabed 100644 --- a/tests/TestFiles/ClassWithCallForThrowingMethodInDifferentClassInTryCatch.php +++ b/tests/TestFiles/ClassWithCallForThrowingMethodInDifferentClassInTryCatch.php @@ -11,10 +11,10 @@ public function baz(): void { $bar = new ClassWithThrowingMethod(); + try { $bar->bar(); } catch (Exception) { - } } -} \ No newline at end of file +} diff --git a/tests/TestFiles/ClassWithMethodThatThrowsAndHasTag.php b/tests/TestFiles/ClassWithMethodThatThrowsAndHasTag.php index 0385394..4094e38 100644 --- a/tests/TestFiles/ClassWithMethodThatThrowsAndHasTag.php +++ b/tests/TestFiles/ClassWithMethodThatThrowsAndHasTag.php @@ -14,7 +14,6 @@ public function baz(): never } /** - * @return void * @throws Exception */ public function bar(): never diff --git a/tests/TestFiles/ClassWithThrowingMethod.php b/tests/TestFiles/ClassWithThrowingMethod.php index 99083de..962fa72 100644 --- a/tests/TestFiles/ClassWithThrowingMethod.php +++ b/tests/TestFiles/ClassWithThrowingMethod.php @@ -9,7 +9,6 @@ final readonly class ClassWithThrowingMethod { /** - * @return void * @throws Exception */ public function bar(): never diff --git a/tests/TestFiles/ClassWithThrowingMethodWithoutDocblock.php b/tests/TestFiles/ClassWithThrowingMethodWithoutDocblock.php index a48daa6..0ad3c5a 100644 --- a/tests/TestFiles/ClassWithThrowingMethodWithoutDocblock.php +++ b/tests/TestFiles/ClassWithThrowingMethodWithoutDocblock.php @@ -8,11 +8,8 @@ final readonly class ClassWithThrowingMethodWithoutDocblock { - /** - * @return void - */ public function bar(): never { throw new Exception(); } -} \ No newline at end of file +} diff --git a/tests/TestFiles/InterfaceExtendsIterable.php b/tests/TestFiles/InterfaceExtendsIterable.php index 249e49e..b77c56d 100644 --- a/tests/TestFiles/InterfaceExtendsIterable.php +++ b/tests/TestFiles/InterfaceExtendsIterable.php @@ -1,10 +1,11 @@ container[] = $value; } else { $this->container[$offset] = $value; @@ -33,4 +33,4 @@ public function offsetGet($offset): mixed { return $this->container[$offset] ?? null; } -} \ No newline at end of file +} diff --git a/tests/TestFiles/UserCollection.php b/tests/TestFiles/UserCollection.php index c6cb5a3..8f945ac 100644 --- a/tests/TestFiles/UserCollection.php +++ b/tests/TestFiles/UserCollection.php @@ -6,13 +6,11 @@ use Iterator; -class UserCollection implements Iterator +final class UserCollection implements Iterator { private int $position = 0; - public function __construct(private array $users) - { - } + public function __construct(private array $users) {} public function current(): User { @@ -40,7 +38,4 @@ public function rewind(): void } } -class User -{ - -} \ No newline at end of file +final class User {}