Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify test case for TypeHintSniff #355

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
Expand All @@ -57,7 +57,7 @@ jobs:

- name: Configure PHPUnit matcher
if: matrix.php-version == '7.4'
uses: mheap/phpunit-matcher-action@master
uses: mheap/phpunit-matcher-action@v1

- name: Run PHPUnit
run: |
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
Expand Down
7 changes: 4 additions & 3 deletions CakePHP/Sniffs/Commenting/TypeHintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,12 @@ protected function getSortedTypeHint(array $types): string
{
static $shouldSort = [
'\\Closure',
'\\Traversable',
'\\ArrayAccess',
'\\Generator',
'\\ArrayObject',
'\\ArrayAccess',
'\\Traversable',
'\\Stringable',
'\\Generator',
'\\Countable',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds Countable. Hard to read with the sort fix.

'$this',
'self',
'mixed',
Expand Down
35 changes: 12 additions & 23 deletions CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,28 @@ namespace Beakman;
class Foo
{
/** @var string[] */
protected $testVar;
protected $convertToGeneric;

/** @var null|string[]|class-string<\Cake\I18n\Number> $testVar2 */
protected $testVar2;
/** @var null|string[]|class-string<\Cake\I18n\Number>|\Generator<int> $testVar2 */
protected $sortGenerics;

/** @var string|array|array<int, string>|array{0: string, 1: int} */
protected $sortArrayShape

/** @var \Stringable|\Countable|\Traversable|\ArrayObject|\ArrayAccess|\Closure|\Generator|\CustomClass|string */
protected $sortSpecificClassesLast

/**
* @param \Test|\Closure|mixed|array<string|int>|string|int|false $test
* @psalm-param \Test|array<int, string>|array{0: string, 1: int}|string $test2
* @return string|int|void
*/
public function testSortedCompound()
{
}

/**
* @param \Closure|\Test|mixed|int|false|string[]|array<string|int>|string $test
* @psalm-param string|list<int>|array{0: string, 1: int}|\Test $test2
* @return false|true|void|int|\Test|array<string>|int[]|null
* @psalm-return false|true|void|int|\Test|array<string>|int[]|null
*/
public function testUnsortedCompound()
public function testFunctionAnotations()
{
}
}

function test()
{
/** @var class-string<\Cake\I18n\Number>|null */
$testVar;

/** @psalm-var null|scalar|class-string<\Cake\I18n\Number>|array $testVar2 */
$testVar2;

/** @var string|null|array<string|int, array<mixed, array<string>|string|null>|string|null> */
$arrays;
/** @var null|string|int|float */
$testInlineVar;
}
35 changes: 12 additions & 23 deletions CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,28 @@ namespace Beakman;
class Foo
{
/** @var array<string> */
protected $testVar;
protected $convertToGeneric;

/** @var array<string>|class-string<\Cake\I18n\Number>|null $testVar2 */
protected $testVar2;
/** @var \Generator<int>|array<string>|class-string<\Cake\I18n\Number>|null $testVar2 */
protected $sortGenerics;

/** @var array|array<int, string>|array{0: string, 1: int}|string */
protected $sortArrayShape

/** @var \CustomClass|\Closure|\Generator|\ArrayObject|\ArrayAccess|\Traversable|\Stringable|\Countable|string */
protected $sortSpecificClassesLast

/**
* @param \Test|\Closure|mixed|array<string|int>|string|int|false $test
* @psalm-param \Test|array<int, string>|array{0: string, 1: int}|string $test2
* @return string|int|void
*/
public function testSortedCompound()
{
}

/**
* @param \Test|\Closure|mixed|array<string>|array<string|int>|string|int|false $test
* @psalm-param \Test|list<int>|array{0: string, 1: int}|string $test2
* @return \Test|array<string>|array<int>|int|true|false|null|void
* @psalm-return \Test|array<string>|array<int>|int|true|false|null|void
*/
public function testUnsortedCompound()
public function testFunctionAnotations()
{
}
}

function test()
{
/** @var class-string<\Cake\I18n\Number>|null */
$testVar;

/** @psalm-var array|class-string<\Cake\I18n\Number>|scalar|null $testVar2 */
$testVar2;

/** @var array<string|int, array<mixed, array<string>|string|null>|string|null>|string|null */
$arrays;
/** @var string|float|int|null */
$testInlineVar;
}
9 changes: 3 additions & 6 deletions CakePHP/Tests/Commenting/TypeHintUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ public function getWarningList($testFile = '')
return [
6 => 1,
9 => 1,
22 => 1,
23 => 1,
24 => 1,
25 => 1,
37 => 1,
40 => 1,
12 => 1,
15 => 1,
29 => 1,
];

default:
Expand Down