From ef4682c03638bcfb90caf66e1a03a0cfa9f2f677 Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Mon, 21 Feb 2022 04:45:24 -0600 Subject: [PATCH] Simplify test case for TypeHintSniff --- .github/workflows/ci.yml | 6 ++-- CakePHP/Sniffs/Commenting/TypeHintSniff.php | 7 ++-- .../Tests/Commenting/TypeHintUnitTest.1.inc | 35 +++++++------------ .../Commenting/TypeHintUnitTest.1.inc.fixed | 35 +++++++------------ CakePHP/Tests/Commenting/TypeHintUnitTest.php | 9 ++--- 5 files changed, 34 insertions(+), 58 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 268c9e4..630421f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} @@ -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: | @@ -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 }} diff --git a/CakePHP/Sniffs/Commenting/TypeHintSniff.php b/CakePHP/Sniffs/Commenting/TypeHintSniff.php index 6db0423..42756b7 100644 --- a/CakePHP/Sniffs/Commenting/TypeHintSniff.php +++ b/CakePHP/Sniffs/Commenting/TypeHintSniff.php @@ -160,11 +160,12 @@ protected function getSortedTypeHint(array $types): string { static $shouldSort = [ '\\Closure', - '\\Traversable', - '\\ArrayAccess', + '\\Generator', '\\ArrayObject', + '\\ArrayAccess', + '\\Traversable', '\\Stringable', - '\\Generator', + '\\Countable', '$this', 'self', 'mixed', diff --git a/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc b/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc index 5cd9b09..99f09ec 100644 --- a/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc +++ b/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc @@ -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 $testVar2 */ + protected $sortGenerics; + + /** @var string|array|array|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|false $test - * @psalm-param \Test|array|array{0: string, 1: int}|string $test2 * @return string|int|void */ - public function testSortedCompound() - { - } - - /** - * @param \Closure|\Test|mixed|int|false|string[]|array|string $test - * @psalm-param string|list|array{0: string, 1: int}|\Test $test2 - * @return false|true|void|int|\Test|array|int[]|null - * @psalm-return false|true|void|int|\Test|array|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|null>|string|null> */ - $arrays; + /** @var null|string|int|float */ + $testInlineVar; } diff --git a/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc.fixed b/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc.fixed index b5b1e4d..f359fa5 100644 --- a/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc.fixed +++ b/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc.fixed @@ -4,39 +4,28 @@ namespace Beakman; class Foo { /** @var array */ - protected $testVar; + protected $convertToGeneric; - /** @var array|class-string<\Cake\I18n\Number>|null $testVar2 */ - protected $testVar2; + /** @var \Generator|array|class-string<\Cake\I18n\Number>|null $testVar2 */ + protected $sortGenerics; + + /** @var array|array|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|false $test - * @psalm-param \Test|array|array{0: string, 1: int}|string $test2 * @return string|int|void */ - public function testSortedCompound() - { - } - - /** - * @param \Test|\Closure|mixed|array|array|string|int|false $test - * @psalm-param \Test|list|array{0: string, 1: int}|string $test2 - * @return \Test|array|array|int|true|false|null|void - * @psalm-return \Test|array|array|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|null>|string|null>|string|null */ - $arrays; + /** @var string|float|int|null */ + $testInlineVar; } diff --git a/CakePHP/Tests/Commenting/TypeHintUnitTest.php b/CakePHP/Tests/Commenting/TypeHintUnitTest.php index e316348..2734793 100644 --- a/CakePHP/Tests/Commenting/TypeHintUnitTest.php +++ b/CakePHP/Tests/Commenting/TypeHintUnitTest.php @@ -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: