1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Added SlevomatCodingStandard.TypeHints.ParameterTypeHint sniff and removed php-cs-fixer

This commit is contained in:
Jack Worman 2022-12-14 20:26:17 -06:00
parent 69658e8315
commit 2b5407d2fb
22 changed files with 45 additions and 125 deletions

View File

@ -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

1
.gitignore vendored
View File

@ -10,7 +10,6 @@
/vendor-bin/*/composer.lock
/vendor-bin/*/vendor/
/tests/fixtures/symlinktest/*
/.php-cs-fixer.cache
.idea/
.vscode/

View File

@ -1,21 +0,0 @@
<?php
declare(strict_types=1);
use Symfony\Component\Finder\Finder;
$finder = (new Finder())
->files()
->name('/\.php$/')
->contains('<?php')
->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,
]);

View File

@ -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",

View File

@ -182,13 +182,6 @@
https://github.com/slevomat/coding-standard#slevomatcodingstandardtypehintsreturntypehint-
-->
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<properties>
<property name="enableObjectTypeHint" type="bool" value="false"/>
<property name="enableStaticTypeHint" type="bool" value="false"/>
<property name="enableMixedTypeHint" type="bool" value="false"/>
<property name="enableUnionTypeHint" type="bool" value="false"/>
</properties>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
</rule>
@ -262,4 +255,7 @@
<!-- Disallows empty comments. -->
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
</rule>
</ruleset>

View File

@ -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
{

View File

@ -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) {

View File

@ -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) {

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -200,12 +200,9 @@ class DocumentationTest extends TestCase
/**
* @dataProvider providerInvalidCodeParse
* @small
* @param string $code
* @param string $error_message
* @param array<string> $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();

View File

@ -38,11 +38,9 @@ class FileReferenceTest extends TestCase
/**
* @dataProvider providerReferenceLocations
* @param string $input_code
* @param string $symbol
* @param array<int, string> $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) {

View File

@ -18,13 +18,12 @@ class IncludeTest extends TestCase
* @dataProvider providerTestValidIncludes
* @param array<int, string> $files_to_check
* @param array<string, string> $files
* @param bool $hoist_constants
* @param list<string> $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<int, string> $files_to_check
* @param array<string, string> $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();

View File

@ -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;
}

View File

@ -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);
}

View File

@ -24,14 +24,13 @@ trait ValidCodeAnalysisTestTrait
/**
* @dataProvider providerValidCodeParse
* @param string $code
* @param array<string, string> $assertions
* @param list<string> $ignored_issues
* @small
*/
public function testValidCode(
$code,
$assertions = [],
string $code,
array $assertions = [],
$ignored_issues = [],
string $php_version = '7.3'
): void {

View File

@ -13,10 +13,9 @@ class TypeCombinationTest extends TestCase
/**
* @dataProvider providerTestValidTypeCombination
* @param string $expected
* @param non-empty-list<string> $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();
}

View File

@ -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(

View File

@ -43,10 +43,9 @@ class UnusedCodeTest extends TestCase
/**
* @dataProvider providerValidCodeParse
* @param string $code
* @param array<string> $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<string> $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();

View File

@ -40,10 +40,9 @@ class UnusedVariableTest extends TestCase
/**
* @dataProvider providerValidCodeParse
* @param string $code
* @param array<string> $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<string> $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();