From cf4d6228b633a423b1301833bc2a04c8bcfcc876 Mon Sep 17 00:00:00 2001 From: webimpress Date: Sat, 18 May 2019 16:40:27 +0100 Subject: [PATCH] Fixes sorting types in doc-block tags --- src/WebimpressCodingStandard/Helper/MethodsTrait.php | 11 +++++++---- test/Sniffs/Commenting/TagWithTypeUnitTest.inc | 5 +++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/WebimpressCodingStandard/Helper/MethodsTrait.php b/src/WebimpressCodingStandard/Helper/MethodsTrait.php index b78bb0b5..bc693eae 100644 --- a/src/WebimpressCodingStandard/Helper/MethodsTrait.php +++ b/src/WebimpressCodingStandard/Helper/MethodsTrait.php @@ -93,10 +93,10 @@ trait MethodsTrait '?callable', 'float', '?float', - 'iterable', - '?iterable', 'int', '?int', + 'iterable', + '?iterable', 'object', '?object', 'resource', @@ -164,10 +164,13 @@ public function sortTypes(string $a, string $b) : int return 1; } - $aIsSimple = array_filter($this->simpleReturnTypes, function ($v) use ($a) { + $types = $this->simpleReturnTypes + + ['parent' => 'parent', 'self' => 'self', 'static' => 'static']; + + $aIsSimple = array_filter($types, static function (string $v) use ($a) { return $v === $a || strpos($a, $v . '[') === 0; }); - $bIsSimple = array_filter($this->simpleReturnTypes, function ($v) use ($b) { + $bIsSimple = array_filter($types, static function (string $v) use ($b) { return $v === $b || strpos($b, $v . '[') === 0; }); diff --git a/test/Sniffs/Commenting/TagWithTypeUnitTest.inc b/test/Sniffs/Commenting/TagWithTypeUnitTest.inc index 5b1cb82c..5722344e 100644 --- a/test/Sniffs/Commenting/TagWithTypeUnitTest.inc +++ b/test/Sniffs/Commenting/TagWithTypeUnitTest.inc @@ -4,6 +4,11 @@ namespace MyNamespace\Test; class TagWithType { + /** + * @var array|bool|callable|float|int|iterable|object|parent|resource|self|static|string|MyClass + */ + public $typesOrder; + /** @var \Property_Type */ public $className;