From 3bb9b976f358e18677d8916c7981838287d34343 Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Fri, 15 Mar 2024 15:34:11 +1300 Subject: [PATCH] CS: enable `no_superfluous_phpdoc_tags` rule and updated deprecated ones --- .php-cs-fixer.dist.php | 37 +++++++++---------- src/Analysers/DocBlockParser.php | 3 +- src/Annotations/AbstractAnnotation.php | 9 ----- src/Annotations/Link.php | 2 - src/Annotations/MediaType.php | 2 - src/Annotations/Parameter.php | 2 - src/Annotations/Schema.php | 6 --- src/Attributes/OperationTrait.php | 1 - src/Attributes/Schema.php | 1 - src/Generator.php | 3 -- src/Processors/AugmentParameters.php | 2 - src/Processors/OperationId.php | 2 - src/Serializer.php | 4 -- tests/Annotations/AttributesSyncTest.php | 2 +- .../Fixtures/Annotations/CustomAttachable.php | 2 - .../Fixtures/Attributes/CustomAttachable.php | 2 - .../Scratch/ComplexCustomAttributes.php | 4 -- tests/Fixtures/Scratch/MergeTraits.php | 2 - tests/Fixtures/Scratch/PromotedProperty.php | 2 - tests/Fixtures/TypedProperties.php | 2 - tests/OpenApiTestCase.php | 5 --- 21 files changed, 19 insertions(+), 76 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 438004aa9..e26c5c3b4 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,23 +1,22 @@ path('src')->name('*.php') ->path('tests')->name('*.php') - // ContextTest::testFullyQualifiedName relies on the 'use Exception' statement... - ->filter(function (\SplFileInfo $file) { - return !strpos($file->getPathname(), 'tests/Fixtures/Customer.php'); - }) + // ContextTest::testFullyQualifiedName relies on the 'use Exception' statement... + ->filter(function (\SplFileInfo $file) { + return !strpos($file->getPathname(), 'tests/Fixtures/Customer.php'); + }) ->path('Examples')->name('*.php') - ->filter(function (\SplFileInfo $file) { - return !strpos($file->getPathname(), 'Examples/petstore-3.0/Petstore.php') - && !strpos($file->getPathname(), 'Examples/misc/OpenApiSpec.php'); - }) + ->filter(function (\SplFileInfo $file) { + return !strpos($file->getPathname(), 'Examples/petstore-3.0/Petstore.php') + && !strpos($file->getPathname(), 'Examples/misc/OpenApiSpec.php'); + }) ->path('tools')->name('*.php') - ->in(__DIR__) -; + ->in(__DIR__); return (new PhpCsFixer\Config()) ->registerCustomFixers([ @@ -35,11 +34,11 @@ 'visibility_required' => true, 'cast_spaces' => ['space' => 'single'], 'concat_space' => ['spacing' => 'one'], - 'function_typehint_space' => true, + 'type_declaration_spaces' => true, 'lowercase_cast' => true, 'magic_constant_casing' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], - 'single_blank_line_before_namespace' => true, + 'blank_lines_before_namespace' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_around_offset' => true, 'no_whitespace_before_comma_in_array' => true, @@ -49,16 +48,15 @@ 'no_blank_lines_after_phpdoc' => true, 'no_extra_blank_lines' => true, 'return_type_declaration' => ['space_before' => 'none'], - 'no_trailing_comma_in_list_call' => true, - 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_comma_in_singleline' => true, 'no_unneeded_control_parentheses' => true, - 'no_unneeded_curly_braces' => true, + 'no_unneeded_braces' => true, 'short_scalar_cast' => true, 'space_after_semicolon' => true, 'ternary_operator_spaces' => true, 'trailing_comma_in_multiline' => true, 'trim_array_spaces' => true, - 'single_space_after_construct' => true, + 'single_space_around_construct' => true, 'single_line_comment_spacing' => true, 'fully_qualified_strict_types' => true, 'global_namespace_import' => ['import_classes' => false, 'import_constants' => null, 'import_functions' => null], @@ -66,7 +64,7 @@ 'nullable_type_declaration_for_default_null_value' => true, 'no_empty_phpdoc' => true, - // 7.3 only 'no_superfluous_phpdoc_tags' => true, + 'no_superfluous_phpdoc_tags' => true, 'phpdoc_align' => true, 'general_phpdoc_tag_rename' => true, 'phpdoc_inline_tag_normalizer' => true, @@ -85,5 +83,4 @@ 'phpdoc_no_empty_return' => true, 'phpdoc_no_alias_tag' => true, ]) - ->setFinder($finder) -; + ->setFinder($finder); diff --git a/src/Analysers/DocBlockParser.php b/src/Analysers/DocBlockParser.php index 3f0c4a52c..c8e24549b 100644 --- a/src/Analysers/DocBlockParser.php +++ b/src/Analysers/DocBlockParser.php @@ -53,8 +53,7 @@ public function setAliases(array $aliases): void /** * Use doctrine to parse the comment block and return the detected annotations. * - * @param string $comment a T_DOC_COMMENT - * @param Context $context + * @param string $comment a T_DOC_COMMENT * * @return array */ diff --git a/src/Annotations/AbstractAnnotation.php b/src/Annotations/AbstractAnnotation.php index c23dfdf32..f0fe751dc 100644 --- a/src/Annotations/AbstractAnnotation.php +++ b/src/Annotations/AbstractAnnotation.php @@ -156,9 +156,6 @@ public function __get(string $property) $this->_context->logger->warning('Property "' . $property . '" doesn\'t exist in a ' . $this->identity() . ', existing properties: "' . implode('", "', array_keys($properties)) . '" in ' . $this->_context); } - /** - * @param mixed $value - */ public function __set(string $property, $value): void { $fields = get_object_vars($this); @@ -287,9 +284,6 @@ public function __debugInfo() return $properties; } - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function jsonSerialize() { @@ -741,8 +735,6 @@ private function validateDefaultTypes(string $type, $value): bool /** * Validate array type. - * - * @param mixed $value */ private function validateArrayType($value): bool { @@ -764,7 +756,6 @@ private function validateArrayType($value): bool /** * Wrap the context with a reference to the annotation it is nested in. * - * @param AbstractAnnotation $annotation * * @return AbstractAnnotation */ diff --git a/src/Annotations/Link.php b/src/Annotations/Link.php index a4bec3bfa..30be649f5 100644 --- a/src/Annotations/Link.php +++ b/src/Annotations/Link.php @@ -75,8 +75,6 @@ class Link extends AbstractAnnotation /** * A literal value or {expression} to use as a request body when calling the target operation. - * - * @var mixed */ public $requestBody = Generator::UNDEFINED; diff --git a/src/Annotations/MediaType.php b/src/Annotations/MediaType.php index 624fe69a9..76348a4a0 100644 --- a/src/Annotations/MediaType.php +++ b/src/Annotations/MediaType.php @@ -39,8 +39,6 @@ class MediaType extends AbstractAnnotation * * Furthermore, if referencing a schema which contains an example, * the example value shall override the example provided by the schema. - * - * @var mixed */ public $example = Generator::UNDEFINED; diff --git a/src/Annotations/Parameter.php b/src/Annotations/Parameter.php index ccb3ab8e2..6e8334dbe 100644 --- a/src/Annotations/Parameter.php +++ b/src/Annotations/Parameter.php @@ -143,8 +143,6 @@ class Parameter extends AbstractAnnotation * The example object is mutually exclusive of the examples object. * Furthermore, if referencing a schema which contains an example, the example value shall override the example provided by the schema. * To represent examples of media types that cannot naturally be represented in JSON or YAML, a string value can contain the example with escaping where necessary. - * - * @var mixed */ public $example = Generator::UNDEFINED; diff --git a/src/Annotations/Schema.php b/src/Annotations/Schema.php index a668a22af..610263e82 100644 --- a/src/Annotations/Schema.php +++ b/src/Annotations/Schema.php @@ -133,8 +133,6 @@ class Schema extends AbstractAnnotation * Sets a default value to the parameter. The type of the value depends on the defined type. * * @see [JSON schema validation](http://json-schema.org/latest/json-schema-validation.html#anchor101) - * - * @var mixed */ public $default = Generator::UNDEFINED; @@ -318,8 +316,6 @@ class Schema extends AbstractAnnotation * * To represent examples that cannot naturally be represented in JSON or YAML, a string value can be used to * contain the example with escaping where necessary. - * - * @var mixed */ public $example = Generator::UNDEFINED; @@ -407,8 +403,6 @@ class Schema extends AbstractAnnotation /** * http://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.6.1.3. - * - * @var mixed */ public $const = Generator::UNDEFINED; diff --git a/src/Attributes/OperationTrait.php b/src/Attributes/OperationTrait.php index 40d26fe82..ae337014c 100644 --- a/src/Attributes/OperationTrait.php +++ b/src/Attributes/OperationTrait.php @@ -11,7 +11,6 @@ trait OperationTrait { /** - * @param array $security * @param Server[] $servers * @param string[] $tags * @param Parameter[] $parameters diff --git a/src/Attributes/Schema.php b/src/Attributes/Schema.php index 4de75533a..ee55639b0 100644 --- a/src/Attributes/Schema.php +++ b/src/Attributes/Schema.php @@ -22,7 +22,6 @@ class Schema extends \OpenApi\Annotations\Schema * @param array $allOf * @param array $anyOf * @param array $oneOf - * @param mixed $const * @param array|null $x * @param Attachable[]|null $attachables */ diff --git a/src/Generator.php b/src/Generator.php index 61cf7d418..9f4f8a485 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -124,9 +124,6 @@ public function pop(): void }; } - /** - * @param mixed $value - */ public static function isDefault($value): bool { return $value === Generator::UNDEFINED; diff --git a/src/Processors/AugmentParameters.php b/src/Processors/AugmentParameters.php index fc4f510c9..cb5818e16 100644 --- a/src/Processors/AugmentParameters.php +++ b/src/Processors/AugmentParameters.php @@ -29,8 +29,6 @@ public function isAugmentOperationParameters(): bool /** * If set to true try to find operation parameter descriptions in the operation docblock. - * - * @param bool $augmentOperationParameters */ public function setAugmentOperationParameters(bool $augmentOperationParameters): void { diff --git a/src/Processors/OperationId.php b/src/Processors/OperationId.php index 22522ab2b..0e799b079 100644 --- a/src/Processors/OperationId.php +++ b/src/Processors/OperationId.php @@ -29,8 +29,6 @@ public function isHash(): bool /** * If set to true generate ids (md5) instead of clear text operation ids. - * - * @param bool $hash */ public function setHash(bool $hash): OperationId { diff --git a/src/Serializer.php b/src/Serializer.php index 52af18056..739461585 100644 --- a/src/Serializer.php +++ b/src/Serializer.php @@ -128,10 +128,6 @@ protected function doDeserialize(\stdClass $c, string $class, Context $context): /** * Deserialize the annotation's property. - * - * @param mixed $value - * - * @return mixed */ protected function doDeserializeProperty(OA\AbstractAnnotation $annotation, string $property, $value, Context $context) { diff --git a/tests/Annotations/AttributesSyncTest.php b/tests/Annotations/AttributesSyncTest.php index c19869b5b..16675d69e 100644 --- a/tests/Annotations/AttributesSyncTest.php +++ b/tests/Annotations/AttributesSyncTest.php @@ -116,7 +116,7 @@ protected function prepDocComment(string $docComment): array protected function propertyType(\ReflectionProperty $property): ?string { - $var = null; + $var = 'mixed'; foreach ($this->prepDocComment($property->getDocComment()) as $line) { if (substr($line, 0, 5) === '@var ') { $var = trim(substr($line, 5)); diff --git a/tests/Fixtures/Annotations/CustomAttachable.php b/tests/Fixtures/Annotations/CustomAttachable.php index 0681fd610..da3f5ce63 100644 --- a/tests/Fixtures/Annotations/CustomAttachable.php +++ b/tests/Fixtures/Annotations/CustomAttachable.php @@ -16,8 +16,6 @@ class CustomAttachable extends OA\Attachable { /** * The attribute value. - * - * @var mixed */ public $value = Generator::UNDEFINED; diff --git a/tests/Fixtures/Attributes/CustomAttachable.php b/tests/Fixtures/Attributes/CustomAttachable.php index 55f559f72..0ab59d77d 100644 --- a/tests/Fixtures/Attributes/CustomAttachable.php +++ b/tests/Fixtures/Attributes/CustomAttachable.php @@ -14,8 +14,6 @@ class CustomAttachable extends OAT\Attachable { /** * The attribute value. - * - * @var mixed */ public $value = Generator::UNDEFINED; diff --git a/tests/Fixtures/Scratch/ComplexCustomAttributes.php b/tests/Fixtures/Scratch/ComplexCustomAttributes.php index 76064de59..cf1794487 100644 --- a/tests/Fixtures/Scratch/ComplexCustomAttributes.php +++ b/tests/Fixtures/Scratch/ComplexCustomAttributes.php @@ -23,10 +23,6 @@ class Schema extends OAT\Schema { /** * @param class-string $of - * @param string|null $description - * @param array $optional - * @param int|null $minLength - * @param int|null $maxLength * * @throws \ReflectionException */ diff --git a/tests/Fixtures/Scratch/MergeTraits.php b/tests/Fixtures/Scratch/MergeTraits.php index 5a99f49c6..0e7f594ab 100644 --- a/tests/Fixtures/Scratch/MergeTraits.php +++ b/tests/Fixtures/Scratch/MergeTraits.php @@ -15,8 +15,6 @@ trait HasId * format="int64", * readOnly=true, * ) - * - * @var int */ public int $id; } diff --git a/tests/Fixtures/Scratch/PromotedProperty.php b/tests/Fixtures/Scratch/PromotedProperty.php index 4453f8732..f0733ccea 100644 --- a/tests/Fixtures/Scratch/PromotedProperty.php +++ b/tests/Fixtures/Scratch/PromotedProperty.php @@ -14,8 +14,6 @@ class PromotedPropertyDescription { /** * Property name. - * - * @var string */ #[OAT\Property(property: 'thename')] public string $name = ''; diff --git a/tests/Fixtures/TypedProperties.php b/tests/Fixtures/TypedProperties.php index 4b06f25b6..501b2643e 100644 --- a/tests/Fixtures/TypedProperties.php +++ b/tests/Fixtures/TypedProperties.php @@ -72,8 +72,6 @@ class TypedProperties public string $annotationTrumpsNative; /** - * @var string - * * @OA\Property( * type="integer", * ) diff --git a/tests/OpenApiTestCase.php b/tests/OpenApiTestCase.php index ab5d16e94..601803e60 100644 --- a/tests/OpenApiTestCase.php +++ b/tests/OpenApiTestCase.php @@ -118,7 +118,6 @@ public function assertOpenApiLogEntryContains(string $needle, string $message = * * @param array|OA\OpenApi|\stdClass|string $actual The generated output * @param array|OA\OpenApi|\stdClass|string $expected The specification - * @param string $message * @param bool $normalized flag indicating whether the inputs are already normalized or * not */ @@ -255,8 +254,6 @@ protected function annotationsFromDocBlockParser(string $docBlock, array $extraA /** * Collect list of all non-abstract annotation classes. - * - * @return array */ public function allAnnotationClasses(): array { @@ -278,8 +275,6 @@ public function allAnnotationClasses(): array /** * Collect list of all non-abstract attribute classes. - * - * @return array */ public function allAttributeClasses(): array {