From fdaed941ad2cdebc587dad4013bec9998997058b Mon Sep 17 00:00:00 2001 From: ralila <> Date: Fri, 26 Nov 2021 20:59:41 +0100 Subject: [PATCH 1/2] use return type hints instead of php doc "@return void" --- src/Psalm/Internal/Analyzer/ClassAnalyzer.php | 3 -- .../AfterClassLikeVisitInterface.php | 5 +-- .../AfterCodebasePopulatedInterface.php | 4 +-- .../Event/AfterClassLikeVisitEvent.php | 2 -- .../Hook/AfterClassLikeVisitInterface.php | 4 +-- .../Hook/AfterCodebasePopulatedInterface.php | 4 +-- tests/BinaryOperationTest.php | 5 +-- tests/ClassTest.php | 5 +-- tests/CodebaseTest.php | 5 +-- tests/Config/ConfigTest.php | 8 ++--- tests/Config/PluginTest.php | 3 +- tests/ErrorBaselineTest.php | 35 ++++--------------- tests/MethodCallTest.php | 5 +-- tests/MethodSignatureTest.php | 20 +++-------- tests/ProjectCheckerTest.php | 3 +- tests/Traits/InvalidCodeAnalysisTestTrait.php | 4 +-- tests/Traits/ValidCodeAnalysisTestTrait.php | 4 +-- 17 files changed, 25 insertions(+), 94 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php index b7f4e5471a6..4f933239c07 100644 --- a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php @@ -119,9 +119,6 @@ public static function getAnonymousClassName(PhpParser\Node\Stmt\Class_ $class, . '_' . $class->getLine() . '_' . (int)$class->getAttribute('startFilePos'); } - /** - * @return void - */ public function analyze( ?Context $class_context = null, ?Context $global_context = null diff --git a/src/Psalm/Plugin/EventHandler/AfterClassLikeVisitInterface.php b/src/Psalm/Plugin/EventHandler/AfterClassLikeVisitInterface.php index 99b110ec526..e12d86ed5af 100644 --- a/src/Psalm/Plugin/EventHandler/AfterClassLikeVisitInterface.php +++ b/src/Psalm/Plugin/EventHandler/AfterClassLikeVisitInterface.php @@ -5,8 +5,5 @@ interface AfterClassLikeVisitInterface { - /** - * @return void - */ - public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event); + public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void; } diff --git a/src/Psalm/Plugin/EventHandler/AfterCodebasePopulatedInterface.php b/src/Psalm/Plugin/EventHandler/AfterCodebasePopulatedInterface.php index 21977bf40c6..e898e359356 100644 --- a/src/Psalm/Plugin/EventHandler/AfterCodebasePopulatedInterface.php +++ b/src/Psalm/Plugin/EventHandler/AfterCodebasePopulatedInterface.php @@ -7,8 +7,6 @@ interface AfterCodebasePopulatedInterface { /** * Called after codebase has been populated - * - * @return void */ - public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event); + public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event): void; } diff --git a/src/Psalm/Plugin/EventHandler/Event/AfterClassLikeVisitEvent.php b/src/Psalm/Plugin/EventHandler/Event/AfterClassLikeVisitEvent.php index 27b98ef8238..c478a5bede1 100644 --- a/src/Psalm/Plugin/EventHandler/Event/AfterClassLikeVisitEvent.php +++ b/src/Psalm/Plugin/EventHandler/Event/AfterClassLikeVisitEvent.php @@ -34,8 +34,6 @@ class AfterClassLikeVisitEvent /** * @param FileManipulation[] $file_replacements - * - * @return void */ public function __construct( ClassLike $stmt, diff --git a/src/Psalm/Plugin/Hook/AfterClassLikeVisitInterface.php b/src/Psalm/Plugin/Hook/AfterClassLikeVisitInterface.php index aaeb3265b5d..5afbc7f39cc 100644 --- a/src/Psalm/Plugin/Hook/AfterClassLikeVisitInterface.php +++ b/src/Psalm/Plugin/Hook/AfterClassLikeVisitInterface.php @@ -12,8 +12,6 @@ interface AfterClassLikeVisitInterface { /** * @param FileManipulation[] $file_replacements - * - * @return void */ public static function afterClassLikeVisit( ClassLike $stmt, @@ -21,5 +19,5 @@ public static function afterClassLikeVisit( FileSource $statements_source, Codebase $codebase, array &$file_replacements = [] - ); + ): void; } diff --git a/src/Psalm/Plugin/Hook/AfterCodebasePopulatedInterface.php b/src/Psalm/Plugin/Hook/AfterCodebasePopulatedInterface.php index e43e74b24d5..df344976f0f 100644 --- a/src/Psalm/Plugin/Hook/AfterCodebasePopulatedInterface.php +++ b/src/Psalm/Plugin/Hook/AfterCodebasePopulatedInterface.php @@ -8,8 +8,6 @@ interface AfterCodebasePopulatedInterface { /** * Called after codebase has been populated - * - * @return void */ - public static function afterCodebasePopulated(Codebase $codebase); + public static function afterCodebasePopulated(Codebase $codebase): void; } diff --git a/tests/BinaryOperationTest.php b/tests/BinaryOperationTest.php index baaf581d434..e663c6cac30 100644 --- a/tests/BinaryOperationTest.php +++ b/tests/BinaryOperationTest.php @@ -10,10 +10,7 @@ class BinaryOperationTest extends TestCase use Traits\InvalidCodeAnalysisTestTrait; use Traits\ValidCodeAnalysisTestTrait; - /** - * @return void - */ - public function testGMPOperations() + public function testGMPOperations(): void { if (class_exists('GMP') === false) { $this->markTestSkipped('Cannot run test, base class "GMP" does not exist!'); diff --git a/tests/ClassTest.php b/tests/ClassTest.php index 7ea1f0595b2..e9cfeb3d9bf 100644 --- a/tests/ClassTest.php +++ b/tests/ClassTest.php @@ -8,10 +8,7 @@ class ClassTest extends TestCase use Traits\InvalidCodeAnalysisTestTrait; use Traits\ValidCodeAnalysisTestTrait; - /** - * @return void - */ - public function testExtendsMysqli() + public function testExtendsMysqli(): void { if (class_exists('mysqli') === false) { $this->markTestSkipped('Cannot run test, base class "mysqli" does not exist!'); diff --git a/tests/CodebaseTest.php b/tests/CodebaseTest.php index 747a8dfa7ea..a8a7623d3da 100644 --- a/tests/CodebaseTest.php +++ b/tests/CodebaseTest.php @@ -143,10 +143,7 @@ public function m(int $_i = 1) {} ' ); $hook = new class implements AfterClassLikeVisitInterface { - /** - * @return void - */ - public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event) + public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void { $stmt = $event->getStmt(); $storage = $event->getStorage(); diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php index 3c5050a9268..ef353744a12 100644 --- a/tests/Config/ConfigTest.php +++ b/tests/Config/ConfigTest.php @@ -140,10 +140,7 @@ public function testIgnoreMissingProjectDirectory(): void $this->assertFalse($config->isInProjectDirs(realpath('examples/StringAnalyzer.php'))); } - /** - * @return void - */ - public function testIgnoreSymlinkedProjectDirectory() + public function testIgnoreSymlinkedProjectDirectory(): void { @unlink(dirname(__DIR__, 1) . '/fixtures/symlinktest/ignored/b'); @@ -1378,8 +1375,7 @@ public function testSetsUsePhpStormMetaPath(): void $this->assertFalse($this->project_analyzer->getConfig()->use_phpstorm_meta_path); } - /** @return void */ - public function testSetsUniversalObjectCrates() + public function testSetsUniversalObjectCrates(): void { $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( diff --git a/tests/Config/PluginTest.php b/tests/Config/PluginTest.php index 64eda8a895a..815d588bf51 100644 --- a/tests/Config/PluginTest.php +++ b/tests/Config/PluginTest.php @@ -540,8 +540,7 @@ public function testAfterCodebasePopulatedHookIsLoaded(): void ); $hook = new class implements AfterCodebasePopulatedInterface { - /** @return void */ - public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event) + public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event): void { } }; diff --git a/tests/ErrorBaselineTest.php b/tests/ErrorBaselineTest.php index 56be18758f3..845af5f7a32 100644 --- a/tests/ErrorBaselineTest.php +++ b/tests/ErrorBaselineTest.php @@ -24,10 +24,7 @@ public function setUp() : void $this->fileProvider = $this->prophesize(FileProvider::class); } - /** - * @return void - */ - public function testLoadShouldParseXmlBaselineToPhpArray() + public function testLoadShouldParseXmlBaselineToPhpArray(): void { $baselineFilePath = 'baseline.xml'; @@ -95,10 +92,7 @@ public function testLoadShouldIgnoreLineEndingsInIssueSnippet(): void ); } - /** - * @return void - */ - public function testLoadShouldThrowExceptionWhenFilesAreNotDefinedInBaselineFile() + public function testLoadShouldThrowExceptionWhenFilesAreNotDefinedInBaselineFile(): void { $this->expectException(ConfigException::class); @@ -115,10 +109,7 @@ public function testLoadShouldThrowExceptionWhenFilesAreNotDefinedInBaselineFile ErrorBaseline::read($this->fileProvider->reveal(), $baselineFile); } - /** - * @return void - */ - public function testLoadShouldThrowExceptionWhenBaselineFileDoesNotExist() + public function testLoadShouldThrowExceptionWhenBaselineFileDoesNotExist(): void { $this->expectException(ConfigException::class); @@ -129,10 +120,7 @@ public function testLoadShouldThrowExceptionWhenBaselineFileDoesNotExist() ErrorBaseline::read($this->fileProvider->reveal(), $baselineFile); } - /** - * @return void - */ - public function testCountTotalIssuesShouldReturnCorrectNumber() + public function testCountTotalIssuesShouldReturnCorrectNumber(): void { $existingIssues = [ 'sample/sample-file.php' => [ @@ -149,10 +137,7 @@ public function testCountTotalIssuesShouldReturnCorrectNumber() $this->assertSame($totalIssues, 5); } - /** - * @return void - */ - public function testCreateShouldAggregateIssuesPerFile() + public function testCreateShouldAggregateIssuesPerFile(): void { $baselineFile = 'baseline.xml'; @@ -342,10 +327,7 @@ public function testCreateShouldAggregateIssuesPerFile() $this->assertSame('1', $file2Issues[1]->getAttribute('occurrences')); } - /** - * @return void - */ - public function testUpdateShouldRemoveExistingIssuesWithoutAddingNewOnes() + public function testUpdateShouldRemoveExistingIssuesWithoutAddingNewOnes(): void { $baselineFile = 'baseline.xml'; @@ -481,10 +463,7 @@ public function testUpdateShouldRemoveExistingIssuesWithoutAddingNewOnes() ], $remainingBaseline); } - /** - * @return void - */ - public function testAddingACommentInBaselineDoesntTriggerNotice() + public function testAddingACommentInBaselineDoesntTriggerNotice(): void { $baselineFilePath = 'baseline.xml'; diff --git a/tests/MethodCallTest.php b/tests/MethodCallTest.php index deab0ad3587..49dfcebee24 100644 --- a/tests/MethodCallTest.php +++ b/tests/MethodCallTest.php @@ -10,10 +10,7 @@ class MethodCallTest extends TestCase use Traits\InvalidCodeAnalysisTestTrait; use Traits\ValidCodeAnalysisTestTrait; - /** - * @return void - */ - public function testExtendDocblockParamType() + public function testExtendDocblockParamType(): void { if (class_exists('SoapClient') === false) { $this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); diff --git a/tests/MethodSignatureTest.php b/tests/MethodSignatureTest.php index 13b700fa0a2..4d89bdc89a6 100644 --- a/tests/MethodSignatureTest.php +++ b/tests/MethodSignatureTest.php @@ -12,10 +12,7 @@ class MethodSignatureTest extends TestCase use Traits\ValidCodeAnalysisTestTrait; use Traits\InvalidCodeAnalysisTestTrait; - /** - * @return void - */ - public function testExtendSoapClientWithDocblockTypes() + public function testExtendSoapClientWithDocblockTypes(): void { if (class_exists('SoapClient') === false) { $this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); @@ -49,10 +46,7 @@ public function __soapCall( $this->analyzeFile('somefile.php', new Context()); } - /** - * @return void - */ - public function testExtendSoapClientWithNoDocblockTypes() + public function testExtendSoapClientWithNoDocblockTypes(): void { if (class_exists('SoapClient') === false) { $this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); @@ -78,10 +72,7 @@ public function __soapCall( $this->analyzeFile('somefile.php', new Context()); } - /** - * @return void - */ - public function testExtendSoapClientWithParamType() + public function testExtendSoapClientWithParamType(): void { if (class_exists('SoapClient') === false) { $this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); @@ -250,10 +241,7 @@ class D extends C {}' $this->analyzeFile('somefile.php', new Context()); } - /** - * @return void - */ - public function testExtendDocblockParamTypeWithWrongDocblockParam() + public function testExtendDocblockParamTypeWithWrongDocblockParam(): void { $this->expectExceptionMessage('ImplementedParamTypeMismatch'); $this->expectException(\Psalm\Exception\CodeException::class); diff --git a/tests/ProjectCheckerTest.php b/tests/ProjectCheckerTest.php index 1945e923323..c5199a8fe28 100644 --- a/tests/ProjectCheckerTest.php +++ b/tests/ProjectCheckerTest.php @@ -108,8 +108,7 @@ public function testAfterCodebasePopulatedIsInvoked(): void /** @var bool */ public static $called = false; - /** @return void */ - public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event) + public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event): void { self::$called = true; } diff --git a/tests/Traits/InvalidCodeAnalysisTestTrait.php b/tests/Traits/InvalidCodeAnalysisTestTrait.php index 6a744ae140e..9efd6876294 100644 --- a/tests/Traits/InvalidCodeAnalysisTestTrait.php +++ b/tests/Traits/InvalidCodeAnalysisTestTrait.php @@ -26,8 +26,6 @@ abstract public function providerInvalidCodeParse(): iterable; * @param string $error_message * @param array $error_levels * @param bool $strict_mode - * - * @return void */ public function testInvalidCode( $code, @@ -35,7 +33,7 @@ public function testInvalidCode( $error_levels = [], $strict_mode = false, string $php_version = '7.3' - ) { + ): void { $test_name = $this->getTestName(); if (strpos($test_name, 'PHP71-') !== false) { if (version_compare(PHP_VERSION, '7.1.0', '<')) { diff --git a/tests/Traits/ValidCodeAnalysisTestTrait.php b/tests/Traits/ValidCodeAnalysisTestTrait.php index f5db49b5064..2769e58bbcd 100644 --- a/tests/Traits/ValidCodeAnalysisTestTrait.php +++ b/tests/Traits/ValidCodeAnalysisTestTrait.php @@ -27,15 +27,13 @@ abstract public function providerValidCodeParse(): iterable; * @param array $error_levels * * @small - * - * @return void */ public function testValidCode( $code, $assertions = [], $error_levels = [], string $php_version = '7.3' - ) { + ): void { $test_name = $this->getTestName(); if (strpos($test_name, 'PHP73-') !== false) { if (version_compare(PHP_VERSION, '7.3.0', '<')) { From 7279f00e05a085f33019ab1d81cdf3fb35255128 Mon Sep 17 00:00:00 2001 From: ralila <> Date: Fri, 26 Nov 2021 21:41:01 +0100 Subject: [PATCH 2/2] fix failing test --- .../Plugin/EventHandler/AfterClassLikeVisitInterface.php | 5 ++++- .../Plugin/EventHandler/AfterCodebasePopulatedInterface.php | 4 +++- src/Psalm/Plugin/Hook/AfterClassLikeVisitInterface.php | 4 +++- src/Psalm/Plugin/Hook/AfterCodebasePopulatedInterface.php | 4 +++- tests/CodebaseTest.php | 5 ++++- tests/Config/PluginTest.php | 3 ++- tests/ProjectCheckerTest.php | 3 ++- 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Psalm/Plugin/EventHandler/AfterClassLikeVisitInterface.php b/src/Psalm/Plugin/EventHandler/AfterClassLikeVisitInterface.php index e12d86ed5af..99b110ec526 100644 --- a/src/Psalm/Plugin/EventHandler/AfterClassLikeVisitInterface.php +++ b/src/Psalm/Plugin/EventHandler/AfterClassLikeVisitInterface.php @@ -5,5 +5,8 @@ interface AfterClassLikeVisitInterface { - public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void; + /** + * @return void + */ + public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event); } diff --git a/src/Psalm/Plugin/EventHandler/AfterCodebasePopulatedInterface.php b/src/Psalm/Plugin/EventHandler/AfterCodebasePopulatedInterface.php index e898e359356..21977bf40c6 100644 --- a/src/Psalm/Plugin/EventHandler/AfterCodebasePopulatedInterface.php +++ b/src/Psalm/Plugin/EventHandler/AfterCodebasePopulatedInterface.php @@ -7,6 +7,8 @@ interface AfterCodebasePopulatedInterface { /** * Called after codebase has been populated + * + * @return void */ - public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event): void; + public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event); } diff --git a/src/Psalm/Plugin/Hook/AfterClassLikeVisitInterface.php b/src/Psalm/Plugin/Hook/AfterClassLikeVisitInterface.php index 5afbc7f39cc..aaeb3265b5d 100644 --- a/src/Psalm/Plugin/Hook/AfterClassLikeVisitInterface.php +++ b/src/Psalm/Plugin/Hook/AfterClassLikeVisitInterface.php @@ -12,6 +12,8 @@ interface AfterClassLikeVisitInterface { /** * @param FileManipulation[] $file_replacements + * + * @return void */ public static function afterClassLikeVisit( ClassLike $stmt, @@ -19,5 +21,5 @@ public static function afterClassLikeVisit( FileSource $statements_source, Codebase $codebase, array &$file_replacements = [] - ): void; + ); } diff --git a/src/Psalm/Plugin/Hook/AfterCodebasePopulatedInterface.php b/src/Psalm/Plugin/Hook/AfterCodebasePopulatedInterface.php index df344976f0f..e43e74b24d5 100644 --- a/src/Psalm/Plugin/Hook/AfterCodebasePopulatedInterface.php +++ b/src/Psalm/Plugin/Hook/AfterCodebasePopulatedInterface.php @@ -8,6 +8,8 @@ interface AfterCodebasePopulatedInterface { /** * Called after codebase has been populated + * + * @return void */ - public static function afterCodebasePopulated(Codebase $codebase): void; + public static function afterCodebasePopulated(Codebase $codebase); } diff --git a/tests/CodebaseTest.php b/tests/CodebaseTest.php index a8a7623d3da..747a8dfa7ea 100644 --- a/tests/CodebaseTest.php +++ b/tests/CodebaseTest.php @@ -143,7 +143,10 @@ public function m(int $_i = 1) {} ' ); $hook = new class implements AfterClassLikeVisitInterface { - public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void + /** + * @return void + */ + public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event) { $stmt = $event->getStmt(); $storage = $event->getStorage(); diff --git a/tests/Config/PluginTest.php b/tests/Config/PluginTest.php index 815d588bf51..64eda8a895a 100644 --- a/tests/Config/PluginTest.php +++ b/tests/Config/PluginTest.php @@ -540,7 +540,8 @@ public function testAfterCodebasePopulatedHookIsLoaded(): void ); $hook = new class implements AfterCodebasePopulatedInterface { - public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event): void + /** @return void */ + public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event) { } }; diff --git a/tests/ProjectCheckerTest.php b/tests/ProjectCheckerTest.php index c5199a8fe28..1945e923323 100644 --- a/tests/ProjectCheckerTest.php +++ b/tests/ProjectCheckerTest.php @@ -108,7 +108,8 @@ public function testAfterCodebasePopulatedIsInvoked(): void /** @var bool */ public static $called = false; - public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event): void + /** @return void */ + public static function afterCodebasePopulated(AfterCodebasePopulatedEvent $event) { self::$called = true; }