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 6b6900230..b2a300e7a 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 da49e7db8..0d602a01f 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 bfd5a134b..000000000 --- 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 66e642b0e..b41097d91 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 6b522e0f6..bf29aa715 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 0342a89a2..ebc2441af 100644 --- a/src/Psalm/Internal/Fork/PsalmRestarter.php +++ b/src/Psalm/Internal/Fork/PsalmRestarter.php @@ -32,6 +32,7 @@ class PsalmRestarter extends XdebugHandler * 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 3526dca38..6c4a24108 100644 --- a/src/Psalm/Storage/FunctionLikeParameter.php +++ b/src/Psalm/Storage/FunctionLikeParameter.php @@ -184,6 +184,10 @@ final class FunctionLikeParameter implements HasAttributesInterface, TypeNode 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 05b933159..7e76f674f 100644 --- a/src/Psalm/Type/Atomic.php +++ b/src/Psalm/Type/Atomic.php @@ -625,6 +625,9 @@ abstract class Atomic implements TypeNode 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 e936f9663..7f58f011d 100644 --- a/src/Psalm/Type/MutableUnion.php +++ b/src/Psalm/Type/MutableUnion.php @@ -493,6 +493,9 @@ final class MutableUnion implements TypeNode, Stringable 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 978eace69..f6eaa1a08 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 e996ecc8d..28feb978a 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -362,6 +362,9 @@ final class Union implements TypeNode, Stringable 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 6516d0440..32d1fc570 100644 --- a/tests/Config/ConfigFileTest.php +++ b/tests/Config/ConfigFileTest.php @@ -262,11 +262,9 @@ class ConfigFileTest extends TestCase } /** - * @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 b1ad8e9a2..99616bbac 100644 --- a/tests/DocumentationTest.php +++ b/tests/DocumentationTest.php @@ -200,12 +200,9 @@ class DocumentationTest extends TestCase /** * @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 @@ class DocumentationTest extends TestCase 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 9b6507173..42d7d9597 100644 --- a/tests/FileReferenceTest.php +++ b/tests/FileReferenceTest.php @@ -38,11 +38,9 @@ class FileReferenceTest extends TestCase /** * @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 db8fef7c4..fafebbce3 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 @@ class IncludeTest extends TestCase * @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 4c2fa1f9c..d68083af0 100644 --- a/tests/Internal/Provider/ClassLikeStorageInstanceCacheProvider.php +++ b/tests/Internal/Provider/ClassLikeStorageInstanceCacheProvider.php @@ -34,10 +34,7 @@ class ClassLikeStorageInstanceCacheProvider extends ClassLikeStorageCacheProvide 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 a87cb5205..bca0036a1 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -92,30 +92,19 @@ class TestCase extends BaseTestCase 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 @@ class TestCase extends BaseTestCase } } - /** - * @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 30676cd36..f5f710ecb 100644 --- a/tests/Traits/ValidCodeAnalysisTestTrait.php +++ b/tests/Traits/ValidCodeAnalysisTestTrait.php @@ -24,14 +24,13 @@ trait ValidCodeAnalysisTestTrait /** * @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 8e788af67..b2219e920 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 @@ class TypeCombinationTest extends TestCase ]; } - /** - * @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 1a2e12e99..44363d6f2 100644 --- a/tests/TypeReconciliation/ReconcilerTest.php +++ b/tests/TypeReconciliation/ReconcilerTest.php @@ -89,10 +89,8 @@ class ReconcilerTest extends TestCase /** * @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 46062e95b..bb061f033 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -43,10 +43,9 @@ class UnusedCodeTest extends TestCase /** * @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 @@ class UnusedCodeTest extends TestCase /** * @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 e5405c5d9..8ea31daa1 100644 --- a/tests/UnusedVariableTest.php +++ b/tests/UnusedVariableTest.php @@ -40,10 +40,9 @@ class UnusedVariableTest extends TestCase /** * @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 @@ class UnusedVariableTest extends TestCase /** * @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();