Skip to content

Commit

Permalink
Added SlevomatCodingStandard.TypeHints.ParameterTypeHint sniff and re…
Browse files Browse the repository at this point in the history
…moved php-cs-fixer
  • Loading branch information
jack-worman committed Dec 15, 2022
1 parent 69658e8 commit 2b5407d
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 125 deletions.
33 changes: 0 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
/vendor-bin/*/composer.lock
/vendor-bin/*/vendor/
/tests/fixtures/symlinktest/*
/.php-cs-fixer.cache

.idea/
.vscode/
Expand Down
21 changes: 0 additions & 21 deletions .php-cs-fixer.dist.php

This file was deleted.

7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 3 additions & 7 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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>
1 change: 1 addition & 0 deletions src/Psalm/Internal/Fork/PsalmRestarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 4 additions & 0 deletions src/Psalm/Storage/FunctionLikeParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/Psalm/Type/Atomic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/Psalm/Type/MutableUnion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Type/TypeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Psalm/Type/Union.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions tests/Config/ConfigFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 7 additions & 4 deletions tests/DocumentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,9 @@ public function testAllIssuesCovered(): void
/**
* @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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions tests/FileReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ public function setUp(): void

/**
* @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) {
Expand Down
6 changes: 2 additions & 4 deletions tests/IncludeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -59,12 +58,11 @@ public function testValidInclude(
* @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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 4 additions & 18 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 2 additions & 3 deletions tests/Traits/ValidCodeAnalysisTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ abstract public function providerValidCodeParse(): iterable;

/**
* @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 {
Expand Down
8 changes: 2 additions & 6 deletions tests/TypeCombinationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 1 addition & 3 deletions tests/TypeReconciliation/ReconcilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 2 additions & 5 deletions tests/UnusedCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ public function setUp(): void

/**
* @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) {
Expand Down Expand Up @@ -75,11 +74,9 @@ public function testValidCode($code, array $ignored_issues = []): void

/**
* @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();
Expand Down
Loading

0 comments on commit 2b5407d

Please sign in to comment.