From 2b5407d2fb9563bf6b95ca82640ae873d16e02de Mon Sep 17 00:00:00 2001 From: Jack Worman Date: Wed, 14 Dec 2022 20:26:17 -0600 Subject: [PATCH] Added SlevomatCodingStandard.TypeHints.ParameterTypeHint sniff and removed php-cs-fixer --- .github/workflows/ci.yml | 33 ------------------- .gitignore | 1 - .php-cs-fixer.dist.php | 21 ------------ composer.json | 7 ++-- phpcs.xml | 10 ++---- src/Psalm/Internal/Fork/PsalmRestarter.php | 1 + src/Psalm/Storage/FunctionLikeParameter.php | 4 +++ src/Psalm/Type/Atomic.php | 3 ++ src/Psalm/Type/MutableUnion.php | 3 ++ src/Psalm/Type/TypeNode.php | 1 + src/Psalm/Type/Union.php | 3 ++ tests/Config/ConfigFileTest.php | 4 +-- tests/DocumentationTest.php | 11 ++++--- tests/FileReferenceTest.php | 4 +-- tests/IncludeTest.php | 6 ++-- .../ClassLikeStorageInstanceCacheProvider.php | 5 +-- tests/TestCase.php | 22 +++---------- tests/Traits/ValidCodeAnalysisTestTrait.php | 5 ++- tests/TypeCombinationTest.php | 8 ++--- tests/TypeReconciliation/ReconcilerTest.php | 4 +-- tests/UnusedCodeTest.php | 7 ++-- tests/UnusedVariableTest.php | 7 ++-- 22 files changed, 45 insertions(+), 125 deletions(-) delete mode 100644 .php-cs-fixer.dist.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b6900230c7..b2a300e7a45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,39 +41,6 @@ jobs: - run: | git ls-files | grep \\\.php$ | grep -v ^dictionaries/scripts/* | ./vendor/bin/parallel-lint --stdin - php-cs-fixer: - name: php-cs-fixer - runs-on: ubuntu-latest - steps: - - name: Set up PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - tools: composer:v2 - coverage: none - - - uses: actions/checkout@v3 - - - name: Get Composer Cache Directories - id: composer-cache - run: | - echo "::set-output name=files_cache::$(composer config cache-files-dir)" - echo "::set-output name=vcs_cache::$(composer config cache-vcs-dir)" - - name: Cache composer cache - uses: actions/cache@v3 - with: - path: | - ${{ steps.composer-cache.outputs.files_cache }} - ${{ steps.composer-cache.outputs.vcs_cache }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - name: Run composer install - run: composer install -o - env: - COMPOSER_ROOT_VERSION: dev-master - - - run: vendor/bin/php-cs-fixer fix --diff --verbose --dry-run chunk-matrix: permissions: contents: none diff --git a/.gitignore b/.gitignore index da49e7db8f2..0d602a01f44 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ /vendor-bin/*/composer.lock /vendor-bin/*/vendor/ /tests/fixtures/symlinktest/* -/.php-cs-fixer.cache .idea/ .vscode/ diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php deleted file mode 100644 index bfd5a134baf..00000000000 --- a/.php-cs-fixer.dist.php +++ /dev/null @@ -1,21 +0,0 @@ -files() - ->name('/\.php$/') - ->contains('in(['bin', 'src', 'tests']); - -return (new PhpCsFixer\Config()) - ->setFinder($finder) - ->setRiskyAllowed(true) - // https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/rules/index.rst - ->setRules([ - 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true], - 'no_empty_phpdoc' => true, - 'phpdoc_trim' => true, - ]); diff --git a/composer.json b/composer.json index 66e642b0e2f..b41097d9115 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,6 @@ "ext-curl": "*", "bamarni/composer-bin-plugin": "^1.4", "brianium/paratest": "^6.0", - "friendsofphp/php-cs-fixer": "^3.13", "mockery/mockery": "^1.5", "nunomaduro/mock-final-classes": "^1.1", "php-parallel-lint/php-parallel-lint": "^1.2", @@ -107,10 +106,8 @@ "psalter" ], "scripts": { - "cs": "phpcs -p", - "cs-fix": "phpcbf -p", - "php-cs-fixer-dry-run": "vendor/bin/php-cs-fixer fix --diff --verbose --dry-run", - "php-cs-fixer": "vendor/bin/php-cs-fixer fix --diff --verbose", + "cs": "phpcs -ps", + "cs-fix": "phpcbf -ps", "lint": "parallel-lint ./src ./tests", "phpunit": "paratest --runner=WrapperRunner", "phpunit-std": "phpunit", diff --git a/phpcs.xml b/phpcs.xml index 6b522e0f691..bf29aa71589 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -182,13 +182,6 @@ https://github.com/slevomat/coding-standard#slevomatcodingstandardtypehintsreturntypehint- --> - - - - - - - @@ -262,4 +255,7 @@ + + + diff --git a/src/Psalm/Internal/Fork/PsalmRestarter.php b/src/Psalm/Internal/Fork/PsalmRestarter.php index 0342a89a25d..ebc2441afe8 100644 --- a/src/Psalm/Internal/Fork/PsalmRestarter.php +++ b/src/Psalm/Internal/Fork/PsalmRestarter.php @@ -32,6 +32,7 @@ public function disableExtension(string $disabledExtension): void * No type hint to allow xdebug-handler v1 and v2 usage * * @param bool $default + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint */ protected function requiresRestart($default): bool { diff --git a/src/Psalm/Storage/FunctionLikeParameter.php b/src/Psalm/Storage/FunctionLikeParameter.php index 3526dca3851..6c4a241080d 100644 --- a/src/Psalm/Storage/FunctionLikeParameter.php +++ b/src/Psalm/Storage/FunctionLikeParameter.php @@ -184,6 +184,10 @@ public function visit(TypeVisitor $visitor): bool return true; } + + /** + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint + */ public static function visitMutable(MutableTypeVisitor $visitor, &$node, bool $cloned): bool { foreach (['type', 'signature_type', 'out_type', 'default_type'] as $key) { diff --git a/src/Psalm/Type/Atomic.php b/src/Psalm/Type/Atomic.php index 05b933159c4..7e76f674f07 100644 --- a/src/Psalm/Type/Atomic.php +++ b/src/Psalm/Type/Atomic.php @@ -625,6 +625,9 @@ public function visit(TypeVisitor $visitor): bool return true; } + /** + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint + */ public static function visitMutable(MutableTypeVisitor $visitor, &$node, bool $cloned): bool { foreach ($node->getChildNodeKeys() as $key) { diff --git a/src/Psalm/Type/MutableUnion.php b/src/Psalm/Type/MutableUnion.php index e936f96633b..7f58f011d33 100644 --- a/src/Psalm/Type/MutableUnion.php +++ b/src/Psalm/Type/MutableUnion.php @@ -493,6 +493,9 @@ public function freeze(): Union return new Union($this->getAtomicTypes(), get_object_vars($this)); } + /** + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint + */ public static function visitMutable(MutableTypeVisitor $visitor, &$node, bool $cloned): bool { $result = true; diff --git a/src/Psalm/Type/TypeNode.php b/src/Psalm/Type/TypeNode.php index 978eace6954..f6eaa1a08c6 100644 --- a/src/Psalm/Type/TypeNode.php +++ b/src/Psalm/Type/TypeNode.php @@ -6,6 +6,7 @@ interface TypeNode { /** @internal Should only be used by the TypeVisitor */ public function visit(TypeVisitor $visitor): bool; + /** * @param static $node * @param-out static $node diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index e996ecc8db1..28feb978ac1 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -362,6 +362,9 @@ public function setFromDocblock(bool $fromDocblock = true): self return $cloned; } + /** + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint + */ public static function visitMutable(MutableTypeVisitor $visitor, &$node, bool $cloned): bool { $result = true; diff --git a/tests/Config/ConfigFileTest.php b/tests/Config/ConfigFileTest.php index 6516d044046..32d1fc570ff 100644 --- a/tests/Config/ConfigFileTest.php +++ b/tests/Config/ConfigFileTest.php @@ -262,11 +262,9 @@ public function testInvalidExtension(): void } /** - * @param string $expected_template - * @param string $contents * @psalm-pure */ - protected static function compareContentWithTemplateAndTrailingLineEnding($expected_template, $contents): bool + protected static function compareContentWithTemplateAndTrailingLineEnding(string $expected_template, string $contents): bool { $passed = false; diff --git a/tests/DocumentationTest.php b/tests/DocumentationTest.php index b1ad8e9a24d..99616bbac55 100644 --- a/tests/DocumentationTest.php +++ b/tests/DocumentationTest.php @@ -200,12 +200,9 @@ public function testAllIssuesCovered(): void /** * @dataProvider providerInvalidCodeParse * @small - * @param string $code - * @param string $error_message * @param array $ignored_issues - * @param bool $check_references */ - public function testInvalidCode($code, $error_message, $ignored_issues = [], $check_references = false, string $php_version = '8.0'): void + public function testInvalidCode(string $code, string $error_message, array $ignored_issues = [], bool $check_references = false, string $php_version = '8.0'): void { if (strpos($this->getTestName(), 'SKIPPED-') !== false) { $this->markTestSkipped(); @@ -405,11 +402,17 @@ public function toString(): string return $this->inner->toString(); } + /** + * @param mixed $other + */ protected function matches($other): bool { return $this->inner->matches($other); } + /** + * @param mixed $other + */ protected function failureDescription($other): string { return $this->exporter()->shortenedExport($other) . ' ' . $this->toString(); diff --git a/tests/FileReferenceTest.php b/tests/FileReferenceTest.php index 9b650717310..42d7d959780 100644 --- a/tests/FileReferenceTest.php +++ b/tests/FileReferenceTest.php @@ -38,11 +38,9 @@ public function setUp(): void /** * @dataProvider providerReferenceLocations - * @param string $input_code - * @param string $symbol * @param array $expected_locations */ - public function testReferenceLocations($input_code, $symbol, $expected_locations): void + public function testReferenceLocations(string $input_code, string $symbol, array $expected_locations): void { $test_name = $this->getTestName(); if (strpos($test_name, 'SKIPPED-') !== false) { diff --git a/tests/IncludeTest.php b/tests/IncludeTest.php index db8fef7c452..fafebbce394 100644 --- a/tests/IncludeTest.php +++ b/tests/IncludeTest.php @@ -18,13 +18,12 @@ class IncludeTest extends TestCase * @dataProvider providerTestValidIncludes * @param array $files_to_check * @param array $files - * @param bool $hoist_constants * @param list $ignored_issues */ public function testValidInclude( array $files, array $files_to_check, - $hoist_constants = false, + bool $hoist_constants = false, array $ignored_issues = [] ): void { $codebase = $this->project_analyzer->getCodebase(); @@ -59,12 +58,11 @@ public function testValidInclude( * @dataProvider providerTestInvalidIncludes * @param array $files_to_check * @param array $files - * @param string $error_message */ public function testInvalidInclude( array $files, array $files_to_check, - $error_message + string $error_message ): void { if (strpos($this->getTestName(), 'SKIPPED-') !== false) { $this->markTestSkipped(); diff --git a/tests/Internal/Provider/ClassLikeStorageInstanceCacheProvider.php b/tests/Internal/Provider/ClassLikeStorageInstanceCacheProvider.php index 4c2fa1f9c73..d68083af077 100644 --- a/tests/Internal/Provider/ClassLikeStorageInstanceCacheProvider.php +++ b/tests/Internal/Provider/ClassLikeStorageInstanceCacheProvider.php @@ -34,10 +34,7 @@ public function getLatestFromCache(string $fq_classlike_name_lc, ?string $file_p return $cached_value; } - /** - * @param string $fq_classlike_name_lc - */ - private function loadFromCache($fq_classlike_name_lc): ?ClassLikeStorage + private function loadFromCache(string $fq_classlike_name_lc): ?ClassLikeStorage { return $this->cache[$fq_classlike_name_lc] ?? null; } diff --git a/tests/TestCase.php b/tests/TestCase.php index a87cb520531..bca0036a1e8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -92,30 +92,19 @@ public function tearDown(): void RuntimeCaches::clearAll(); } - /** - * @param string $file_path - * @param string $contents - */ - public function addFile($file_path, $contents): void + public function addFile(string $file_path, string $contents): void { $this->file_provider->registerFile($file_path, $contents); $this->project_analyzer->getCodebase()->scanner->addFileToShallowScan($file_path); } - /** - * @param string $file_path - * @param string $contents - */ - public function addStubFile($file_path, $contents): void + public function addStubFile(string $file_path, string $contents): void { $this->file_provider->registerFile($file_path, $contents); $this->project_analyzer->getConfig()->addStubFile($file_path); } - /** - * @param string $file_path - */ - public function analyzeFile($file_path, Context $context, bool $track_unused_suppressions = true, bool $taint_flow_tracking = false): void + public function analyzeFile(string $file_path, Context $context, bool $track_unused_suppressions = true, bool $taint_flow_tracking = false): void { $codebase = $this->project_analyzer->getCodebase(); @@ -151,10 +140,7 @@ public function analyzeFile($file_path, Context $context, bool $track_unused_sup } } - /** - * @param bool $withDataSet - */ - protected function getTestName($withDataSet = true): string + protected function getTestName(bool $withDataSet = true): string { return $this->getName($withDataSet); } diff --git a/tests/Traits/ValidCodeAnalysisTestTrait.php b/tests/Traits/ValidCodeAnalysisTestTrait.php index 30676cd3612..f5f710ecbaa 100644 --- a/tests/Traits/ValidCodeAnalysisTestTrait.php +++ b/tests/Traits/ValidCodeAnalysisTestTrait.php @@ -24,14 +24,13 @@ abstract public function providerValidCodeParse(): iterable; /** * @dataProvider providerValidCodeParse - * @param string $code * @param array $assertions * @param list $ignored_issues * @small */ public function testValidCode( - $code, - $assertions = [], + string $code, + array $assertions = [], $ignored_issues = [], string $php_version = '7.3' ): void { diff --git a/tests/TypeCombinationTest.php b/tests/TypeCombinationTest.php index 8e788af676e..b2219e92007 100644 --- a/tests/TypeCombinationTest.php +++ b/tests/TypeCombinationTest.php @@ -13,10 +13,9 @@ class TypeCombinationTest extends TestCase /** * @dataProvider providerTestValidTypeCombination - * @param string $expected * @param non-empty-list $types */ - public function testValidTypeCombination($expected, $types): void + public function testValidTypeCombination(string $expected, array $types): void { $converted_types = []; @@ -821,10 +820,7 @@ public function providerTestValidTypeCombination(): array ]; } - /** - * @param string $string - */ - private static function getAtomic($string): Atomic + private static function getAtomic(string $string): Atomic { return Type::parseString($string)->getSingleAtomic(); } diff --git a/tests/TypeReconciliation/ReconcilerTest.php b/tests/TypeReconciliation/ReconcilerTest.php index 1a2e12e996e..44363d6f20b 100644 --- a/tests/TypeReconciliation/ReconcilerTest.php +++ b/tests/TypeReconciliation/ReconcilerTest.php @@ -89,10 +89,8 @@ public function testReconcilation(string $expected_type, Assertion $assertion, s /** * @dataProvider providerTestTypeIsContainedBy - * @param string $input - * @param string $container */ - public function testTypeIsContainedBy($input, $container): void + public function testTypeIsContainedBy(string $input, string $container): void { $this->assertTrue( UnionTypeComparator::isContainedBy( diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index 46062e95bb7..bb061f0330a 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -43,10 +43,9 @@ public function setUp(): void /** * @dataProvider providerValidCodeParse - * @param string $code * @param array $ignored_issues */ - public function testValidCode($code, array $ignored_issues = []): void + public function testValidCode(string $code, array $ignored_issues = []): void { $test_name = $this->getTestName(); if (strpos($test_name, 'SKIPPED-') !== false) { @@ -75,11 +74,9 @@ public function testValidCode($code, array $ignored_issues = []): void /** * @dataProvider providerInvalidCodeParse - * @param string $code - * @param string $error_message * @param array $ignored_issues */ - public function testInvalidCode($code, $error_message, $ignored_issues = []): void + public function testInvalidCode(string $code, string $error_message, array $ignored_issues = []): void { if (strpos($this->getTestName(), 'SKIPPED-') !== false) { $this->markTestSkipped(); diff --git a/tests/UnusedVariableTest.php b/tests/UnusedVariableTest.php index e5405c5d940..8ea31daa19d 100644 --- a/tests/UnusedVariableTest.php +++ b/tests/UnusedVariableTest.php @@ -40,10 +40,9 @@ public function setUp(): void /** * @dataProvider providerValidCodeParse - * @param string $code * @param array $ignored_issues */ - public function testValidCode($code, array $ignored_issues = [], string $php_version = '7.4'): void + public function testValidCode(string $code, array $ignored_issues = [], string $php_version = '7.4'): void { $test_name = $this->getTestName(); if (strpos($test_name, 'SKIPPED-') !== false) { @@ -68,11 +67,9 @@ public function testValidCode($code, array $ignored_issues = [], string $php_ver /** * @dataProvider providerInvalidCodeParse - * @param string $code - * @param string $error_message * @param array $ignored_issues */ - public function testInvalidCode($code, $error_message, $ignored_issues = []): void + public function testInvalidCode(string $code, string $error_message, array $ignored_issues = []): void { if (strpos($this->getTestName(), 'SKIPPED-') !== false) { $this->markTestSkipped();