From c6d49fc451c8e04501650c67474df943cbbb5547 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 12 Mar 2024 22:28:53 +0100 Subject: [PATCH] Fix code style and bump to php 7.4 --- composer.json | 2 +- composer.lock | 73 +++++++++++++++---- examples/04-adding-your-own-tag.php | 2 +- src/DocBlock.php | 14 ++-- src/DocBlock/Description.php | 5 +- src/DocBlock/DescriptionFactory.php | 3 +- src/DocBlock/ExampleFinder.php | 5 +- src/DocBlock/Serializer.php | 13 ++-- src/DocBlock/StandardTagFactory.php | 11 ++- src/DocBlock/Tags/Author.php | 6 +- src/DocBlock/Tags/BaseTag.php | 4 +- src/DocBlock/Tags/Covers.php | 6 +- src/DocBlock/Tags/Deprecated.php | 5 +- src/DocBlock/Tags/Example.php | 13 ++-- .../Tags/Formatter/AlignFormatter.php | 2 +- src/DocBlock/Tags/InvalidTag.php | 9 +-- src/DocBlock/Tags/Link.php | 6 +- src/DocBlock/Tags/Method.php | 15 ++-- src/DocBlock/Tags/MethodParameter.php | 15 ++-- src/DocBlock/Tags/Param.php | 7 +- src/DocBlock/Tags/Property.php | 3 +- src/DocBlock/Tags/PropertyRead.php | 3 +- src/DocBlock/Tags/PropertyWrite.php | 3 +- src/DocBlock/Tags/Reference/Fqsen.php | 3 +- src/DocBlock/Tags/Reference/Url.php | 3 +- src/DocBlock/Tags/See.php | 6 +- src/DocBlock/Tags/Since.php | 5 +- src/DocBlock/Tags/Source.php | 7 +- src/DocBlock/Tags/TagWithType.php | 2 +- src/DocBlock/Tags/Uses.php | 6 +- src/DocBlock/Tags/Var_.php | 3 +- src/DocBlock/Tags/Version.php | 5 +- src/DocBlockFactory.php | 6 +- .../ReconstitutingADocBlockTest.php | 42 +++++++++++ tests/unit/DocBlock/DescriptionTest.php | 2 +- tests/unit/DocBlock/ExampleFinderTest.php | 3 +- 36 files changed, 181 insertions(+), 137 deletions(-) diff --git a/composer.json b/composer.json index 86c5beee..63e65fd8 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": "^7.2 || ^8.0", + "php": "^7.4 || ^8.0", "phpdocumentor/type-resolver": "^1.7", "webmozart/assert": "^1.9.1", "phpdocumentor/reflection-common": "^2.2", diff --git a/composer.lock b/composer.lock index 51a4e55f..b74c7d5f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,55 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "829061026cc6b2284953cbe816406760", + "content-hash": "e85fae7945bde2c4a84d94d4ca572202", "packages": [ + { + "name": "doctrine/deprecations", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/doctrine/deprecations.git", + "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", + "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^9", + "phpstan/phpstan": "1.4.10 || 1.10.15", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "0.18.4", + "psr/log": "^1 || ^2 || ^3", + "vimeo/psalm": "4.30.0 || 5.12.0" + }, + "suggest": { + "psr/log": "Allows logging deprecations via PSR-3 logger implementation" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.", + "homepage": "https://www.doctrine-project.org/", + "support": { + "issues": "https://github.com/doctrine/deprecations/issues", + "source": "https://github.com/doctrine/deprecations/tree/1.1.3" + }, + "time": "2024-01-30T19:34:25+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "2.2.0", @@ -61,20 +108,21 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.x-dev", + "version": "1.8.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "2dc9aff0e6ca4e4600355c68c4a38bfaeccf54e2" + "reference": "153ae662783729388a584b4361f2545e4d841e3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2dc9aff0e6ca4e4600355c68c4a38bfaeccf54e2", - "reference": "2dc9aff0e6ca4e4600355c68c4a38bfaeccf54e2", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/153ae662783729388a584b4361f2545e4d841e3c", + "reference": "153ae662783729388a584b4361f2545e4d841e3c", "shasum": "" }, "require": { - "php": "^7.4 || ^8.0", + "doctrine/deprecations": "^1.0", + "php": "^7.3 || ^8.0", "phpdocumentor/reflection-common": "^2.0", "phpstan/phpdoc-parser": "^1.13" }, @@ -88,7 +136,6 @@ "rector/rector": "^0.13.9", "vimeo/psalm": "^4.25" }, - "default-branch": true, "type": "library", "extra": { "branch-alias": { @@ -113,9 +160,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.x" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.8.2" }, - "time": "2022-11-19T20:09:31+00:00" + "time": "2024-02-23T11:10:43+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -4057,18 +4104,16 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "phpdocumentor/type-resolver": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^7.2 || ^8.0", + "php": "^7.4 || ^8.0", "ext-filter": "*" }, "platform-dev": [], "platform-overrides": { "php": "7.4.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/examples/04-adding-your-own-tag.php b/examples/04-adding-your-own-tag.php index 49f751d9..38ab7248 100644 --- a/examples/04-adding-your-own-tag.php +++ b/examples/04-adding-your-own-tag.php @@ -42,7 +42,7 @@ final class MyTag extends BaseTag * * @var string */ - protected $name = 'my-tag'; + protected string $name = 'my-tag'; /** * The constructor for this Tag; this should contain all properties for this object. diff --git a/src/DocBlock.php b/src/DocBlock.php index cc33e60e..90d8066d 100644 --- a/src/DocBlock.php +++ b/src/DocBlock.php @@ -20,25 +20,25 @@ final class DocBlock { /** @var string The opening line for this docblock. */ - private $summary; + private string $summary; /** @var DocBlock\Description The actual description for this docblock. */ - private $description; + private DocBlock\Description $description; /** @var Tag[] An array containing all the tags in this docblock; except inline. */ - private $tags = []; + private array $tags = []; /** @var Types\Context|null Information about the context of this DocBlock. */ - private $context; + private ?Types\Context $context = null; /** @var Location|null Information about the location of this DocBlock. */ - private $location; + private ?Location $location = null; /** @var bool Is this DocBlock (the start of) a template? */ - private $isTemplateStart; + private bool $isTemplateStart; /** @var bool Does this DocBlock signify the end of a DocBlock template? */ - private $isTemplateEnd; + private bool $isTemplateEnd; /** * @param DocBlock\Tag[] $tags diff --git a/src/DocBlock/Description.php b/src/DocBlock/Description.php index fcbaede7..a188ae30 100644 --- a/src/DocBlock/Description.php +++ b/src/DocBlock/Description.php @@ -52,11 +52,10 @@ */ class Description { - /** @var string */ - private $bodyTemplate; + private string $bodyTemplate; /** @var Tag[] */ - private $tags; + private array $tags; /** * Initializes a Description with its body (template) and a listing of the tags used in the body template. diff --git a/src/DocBlock/DescriptionFactory.php b/src/DocBlock/DescriptionFactory.php index d0180184..e7bc616d 100644 --- a/src/DocBlock/DescriptionFactory.php +++ b/src/DocBlock/DescriptionFactory.php @@ -48,8 +48,7 @@ */ class DescriptionFactory { - /** @var Factory */ - private $tagFactory; + private Factory $tagFactory; /** * Initializes this factory with the means to construct (inline) tags. diff --git a/src/DocBlock/ExampleFinder.php b/src/DocBlock/ExampleFinder.php index 6a6b4729..7136e28f 100644 --- a/src/DocBlock/ExampleFinder.php +++ b/src/DocBlock/ExampleFinder.php @@ -31,11 +31,10 @@ */ class ExampleFinder { - /** @var string */ - private $sourceDirectory = ''; + private string $sourceDirectory = ''; /** @var string[] */ - private $exampleDirectories = []; + private array $exampleDirectories = []; /** * Attempts to find the example contents for the given descriptor. diff --git a/src/DocBlock/Serializer.php b/src/DocBlock/Serializer.php index 77e5fb5f..31ca29c5 100644 --- a/src/DocBlock/Serializer.php +++ b/src/DocBlock/Serializer.php @@ -29,21 +29,20 @@ class Serializer { /** @var string The string to indent the comment with. */ - protected $indentString = ' '; + protected string $indentString = ' '; /** @var int The number of times the indent string is repeated. */ - protected $indent = 0; + protected int $indent = 0; /** @var bool Whether to indent the first line with the given indent amount and string. */ - protected $isFirstLineIndented = true; + protected bool $isFirstLineIndented = true; /** @var int|null The max length of a line. */ - protected $lineLength; + protected ?int $lineLength = null; /** @var Formatter A custom tag formatter. */ - protected $tagFormatter; - /** @var string */ - private $lineEnding; + protected Formatter $tagFormatter; + private string $lineEnding; /** * Create a Serializer instance. diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index e5c071c1..7360a707 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -79,7 +79,7 @@ final class StandardTagFactory implements TagFactory * @var array|Factory> An array with a tag as a key, and an * FQCN to a class that handles it as an array value. */ - private $tagHandlerMappings = [ + private array $tagHandlerMappings = [ 'author' => Author::class, 'covers' => Covers::class, 'deprecated' => Deprecated::class, @@ -105,22 +105,21 @@ final class StandardTagFactory implements TagFactory * @var array> An array with a anotation s a key, and an * FQCN to a class that handles it as an array value. */ - private $annotationMappings = []; + private array $annotationMappings = []; /** * @var ReflectionParameter[][] a lazy-loading cache containing parameters * for each tagHandler that has been used. */ - private $tagHandlerParameterCache = []; + private array $tagHandlerParameterCache = []; - /** @var FqsenResolver */ - private $fqsenResolver; + private FqsenResolver $fqsenResolver; /** * @var mixed[] an array representing a simple Service Locator where we can store parameters and * services that can be inserted into the Factory Methods of Tag Handlers. */ - private $serviceLocator = []; + private array $serviceLocator = []; /** * Initialize this tag factory with the means to resolve an FQSEN and optionally a list of tag handlers. diff --git a/src/DocBlock/Tags/Author.php b/src/DocBlock/Tags/Author.php index ae09ecf4..290e5a95 100644 --- a/src/DocBlock/Tags/Author.php +++ b/src/DocBlock/Tags/Author.php @@ -27,13 +27,13 @@ final class Author extends BaseTag implements Factory\StaticMethod { /** @var string register that this is the author tag. */ - protected $name = 'author'; + protected string $name = 'author'; /** @var string The name of the author */ - private $authorName; + private string $authorName; /** @var string The email of the author */ - private $authorEmail; + private string $authorEmail; /** * Initializes this tag with the author name and e-mail. diff --git a/src/DocBlock/Tags/BaseTag.php b/src/DocBlock/Tags/BaseTag.php index a28d5bf9..98b0d881 100644 --- a/src/DocBlock/Tags/BaseTag.php +++ b/src/DocBlock/Tags/BaseTag.php @@ -22,10 +22,10 @@ abstract class BaseTag implements DocBlock\Tag { /** @var string Name of the tag */ - protected $name = ''; + protected string $name = ''; /** @var Description|null Description of the tag. */ - protected $description; + protected ?Description $description = null; /** * Gets the name of this tag. diff --git a/src/DocBlock/Tags/Covers.php b/src/DocBlock/Tags/Covers.php index 3eff9d8b..022594e2 100644 --- a/src/DocBlock/Tags/Covers.php +++ b/src/DocBlock/Tags/Covers.php @@ -29,11 +29,9 @@ */ final class Covers extends BaseTag implements Factory\StaticMethod { - /** @var string */ - protected $name = 'covers'; + protected string $name = 'covers'; - /** @var Fqsen */ - private $refers; + private Fqsen $refers; /** * Initializes this tag. diff --git a/src/DocBlock/Tags/Deprecated.php b/src/DocBlock/Tags/Deprecated.php index dbcad28c..a55cd914 100644 --- a/src/DocBlock/Tags/Deprecated.php +++ b/src/DocBlock/Tags/Deprecated.php @@ -25,8 +25,7 @@ */ final class Deprecated extends BaseTag implements Factory\StaticMethod { - /** @var string */ - protected $name = 'deprecated'; + protected string $name = 'deprecated'; /** * PCRE regular expression matching a version vector. @@ -45,7 +44,7 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod )'; /** @var string|null The version vector. */ - private $version; + private ?string $version = null; public function __construct(?string $version = null, ?Description $description = null) { diff --git a/src/DocBlock/Tags/Example.php b/src/DocBlock/Tags/Example.php index 825355aa..fd9ef6eb 100644 --- a/src/DocBlock/Tags/Example.php +++ b/src/DocBlock/Tags/Example.php @@ -29,22 +29,19 @@ final class Example implements Tag, Factory\StaticMethod { /** @var string Path to a file to use as an example. May also be an absolute URI. */ - private $filePath; + private string $filePath; /** * @var bool Whether the file path component represents an URI. This determines how the file portion * appears at {@link getContent()}. */ - private $isURI; + private bool $isURI; - /** @var int */ - private $startingLine; + private int $startingLine; - /** @var int */ - private $lineCount; + private int $lineCount; - /** @var string|null */ - private $content; + private ?string $content = null; public function __construct( string $filePath, diff --git a/src/DocBlock/Tags/Formatter/AlignFormatter.php b/src/DocBlock/Tags/Formatter/AlignFormatter.php index 94644343..ea5c16f5 100644 --- a/src/DocBlock/Tags/Formatter/AlignFormatter.php +++ b/src/DocBlock/Tags/Formatter/AlignFormatter.php @@ -23,7 +23,7 @@ class AlignFormatter implements Formatter { /** @var int The maximum tag name length. */ - protected $maxLen = 0; + protected int $maxLen = 0; /** * @param Tag[] $tags All tags that should later be aligned with the formatter. diff --git a/src/DocBlock/Tags/InvalidTag.php b/src/DocBlock/Tags/InvalidTag.php index 4e6abb8c..c7d3cd54 100644 --- a/src/DocBlock/Tags/InvalidTag.php +++ b/src/DocBlock/Tags/InvalidTag.php @@ -32,14 +32,11 @@ */ final class InvalidTag implements Tag { - /** @var string */ - private $name; + private string $name; - /** @var string */ - private $body; + private string $body; - /** @var Throwable|null */ - private $throwable; + private ?Throwable $throwable = null; private function __construct(string $name, string $body) { diff --git a/src/DocBlock/Tags/Link.php b/src/DocBlock/Tags/Link.php index ee242e3b..fcb6ec19 100644 --- a/src/DocBlock/Tags/Link.php +++ b/src/DocBlock/Tags/Link.php @@ -24,11 +24,9 @@ */ final class Link extends BaseTag implements Factory\StaticMethod { - /** @var string */ - protected $name = 'link'; + protected string $name = 'link'; - /** @var string */ - private $link; + private string $link; /** * Initializes a link to a URL. diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index 02aa2b47..471ebe95 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -43,20 +43,15 @@ */ final class Method extends BaseTag implements Factory\StaticMethod { - /** @var string */ - protected $name = 'method'; + protected string $name = 'method'; - /** @var string */ - private $methodName; + private string $methodName; - /** @var bool */ - private $isStatic; + private bool $isStatic; - /** @var Type */ - private $returnType; + private Type $returnType; - /** @var bool */ - private $returnsReference; + private bool $returnsReference; /** @var MethodParameter[] */ private array $parameters; diff --git a/src/DocBlock/Tags/MethodParameter.php b/src/DocBlock/Tags/MethodParameter.php index 15780a6f..0c85d41d 100644 --- a/src/DocBlock/Tags/MethodParameter.php +++ b/src/DocBlock/Tags/MethodParameter.php @@ -16,20 +16,15 @@ final class MethodParameter { - /** @var Type */ - private $type; + private Type $type; - /** @var bool */ - private $isReference; + private bool $isReference; - /** @var bool */ - private $isVariadic; + private bool $isVariadic; - /** @var string */ - private $name; + private string $name; - /** @var string|null */ - private $defaultValue; + private ?string $defaultValue = null; public function __construct( string $name, diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index cb14abeb..9915ede0 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -36,14 +36,13 @@ */ final class Param extends TagWithType implements Factory\StaticMethod { - /** @var string|null */ - private $variableName; + private ?string $variableName = null; /** @var bool determines whether this is a variadic argument */ - private $isVariadic; + private bool $isVariadic; /** @var bool determines whether this is passed by reference */ - private $isReference; + private bool $isReference; public function __construct( ?string $variableName, diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php index b3d9df42..cc88c07e 100644 --- a/src/DocBlock/Tags/Property.php +++ b/src/DocBlock/Tags/Property.php @@ -36,8 +36,7 @@ */ final class Property extends TagWithType implements Factory\StaticMethod { - /** @var string|null */ - protected $variableName; + protected ?string $variableName = null; public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) { diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php index ccffde63..404592ce 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -36,8 +36,7 @@ */ final class PropertyRead extends TagWithType implements Factory\StaticMethod { - /** @var string|null */ - protected $variableName; + protected ?string $variableName = null; public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) { diff --git a/src/DocBlock/Tags/PropertyWrite.php b/src/DocBlock/Tags/PropertyWrite.php index 35dac201..03cfc64e 100644 --- a/src/DocBlock/Tags/PropertyWrite.php +++ b/src/DocBlock/Tags/PropertyWrite.php @@ -36,8 +36,7 @@ */ final class PropertyWrite extends TagWithType implements Factory\StaticMethod { - /** @var string */ - protected $variableName; + protected string $variableName; public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) { diff --git a/src/DocBlock/Tags/Reference/Fqsen.php b/src/DocBlock/Tags/Reference/Fqsen.php index 532003dd..e4e7e31c 100644 --- a/src/DocBlock/Tags/Reference/Fqsen.php +++ b/src/DocBlock/Tags/Reference/Fqsen.php @@ -20,8 +20,7 @@ */ final class Fqsen implements Reference { - /** @var RealFqsen */ - private $fqsen; + private RealFqsen $fqsen; public function __construct(RealFqsen $fqsen) { diff --git a/src/DocBlock/Tags/Reference/Url.php b/src/DocBlock/Tags/Reference/Url.php index edfba3fd..5954a471 100644 --- a/src/DocBlock/Tags/Reference/Url.php +++ b/src/DocBlock/Tags/Reference/Url.php @@ -20,8 +20,7 @@ */ final class Url implements Reference { - /** @var string */ - private $uri; + private string $uri; public function __construct(string $uri) { diff --git a/src/DocBlock/Tags/See.php b/src/DocBlock/Tags/See.php index a194c7de..e7330e88 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -33,11 +33,9 @@ */ final class See extends BaseTag implements Factory\StaticMethod { - /** @var string */ - protected $name = 'see'; + protected string $name = 'see'; - /** @var Reference */ - protected $refers; + protected Reference $refers; /** * Initializes this tag. diff --git a/src/DocBlock/Tags/Since.php b/src/DocBlock/Tags/Since.php index 54af43cd..24400fa1 100644 --- a/src/DocBlock/Tags/Since.php +++ b/src/DocBlock/Tags/Since.php @@ -25,8 +25,7 @@ */ final class Since extends BaseTag implements Factory\StaticMethod { - /** @var string */ - protected $name = 'since'; + protected string $name = 'since'; /** * PCRE regular expression matching a version vector. @@ -45,7 +44,7 @@ final class Since extends BaseTag implements Factory\StaticMethod )'; /** @var string|null The version vector. */ - private $version; + private ?string $version = null; public function __construct(?string $version = null, ?Description $description = null) { diff --git a/src/DocBlock/Tags/Source.php b/src/DocBlock/Tags/Source.php index 8b8c0fb4..f6b4f57f 100644 --- a/src/DocBlock/Tags/Source.php +++ b/src/DocBlock/Tags/Source.php @@ -25,14 +25,13 @@ */ final class Source extends BaseTag implements Factory\StaticMethod { - /** @var string */ - protected $name = 'source'; + protected string $name = 'source'; /** @var int The starting line, relative to the structural element's location. */ - private $startingLine; + private int $startingLine; /** @var int|null The number of lines, relative to the starting line. NULL means "to the end". */ - private $lineCount; + private ?int $lineCount = null; /** * @param int|string $startingLine should be a to int convertible value diff --git a/src/DocBlock/Tags/TagWithType.php b/src/DocBlock/Tags/TagWithType.php index 158578bd..60067b2a 100644 --- a/src/DocBlock/Tags/TagWithType.php +++ b/src/DocBlock/Tags/TagWithType.php @@ -23,7 +23,7 @@ abstract class TagWithType extends BaseTag { /** @var ?Type */ - protected $type; + protected ?Type $type = null; /** * Returns the type section of the variable. diff --git a/src/DocBlock/Tags/Uses.php b/src/DocBlock/Tags/Uses.php index b72f4034..d9aa3608 100644 --- a/src/DocBlock/Tags/Uses.php +++ b/src/DocBlock/Tags/Uses.php @@ -29,11 +29,9 @@ */ final class Uses extends BaseTag implements Factory\StaticMethod { - /** @var string */ - protected $name = 'uses'; + protected string $name = 'uses'; - /** @var Fqsen */ - protected $refers; + protected Fqsen $refers; /** * Initializes this tag. diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php index d8e75b99..c041649a 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -36,8 +36,7 @@ */ final class Var_ extends TagWithType implements Factory\StaticMethod { - /** @var string|null */ - protected $variableName = ''; + protected ?string $variableName = ''; public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) { diff --git a/src/DocBlock/Tags/Version.php b/src/DocBlock/Tags/Version.php index f46e4b8c..1ed25d17 100644 --- a/src/DocBlock/Tags/Version.php +++ b/src/DocBlock/Tags/Version.php @@ -25,8 +25,7 @@ */ final class Version extends BaseTag implements Factory\StaticMethod { - /** @var string */ - protected $name = 'version'; + protected string $name = 'version'; /** * PCRE regular expression matching a version vector. @@ -45,7 +44,7 @@ final class Version extends BaseTag implements Factory\StaticMethod )'; /** @var string|null The version vector. */ - private $version; + private ?string $version = null; public function __construct(?string $version = null, ?Description $description = null) { diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index 507a4ec0..1f7faf1a 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -44,11 +44,9 @@ final class DocBlockFactory implements DocBlockFactoryInterface { - /** @var DocBlock\DescriptionFactory */ - private $descriptionFactory; + private DocBlock\DescriptionFactory $descriptionFactory; - /** @var TagFactory */ - private $tagFactory; + private TagFactory $tagFactory; /** * Initializes this factory with the required subcontractors. diff --git a/tests/integration/ReconstitutingADocBlockTest.php b/tests/integration/ReconstitutingADocBlockTest.php index 02da4def..aef6598c 100644 --- a/tests/integration/ReconstitutingADocBlockTest.php +++ b/tests/integration/ReconstitutingADocBlockTest.php @@ -14,6 +14,9 @@ namespace phpDocumentor\Reflection; use Mockery as m; +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\Tags\Generic; +use phpDocumentor\Reflection\Types\ContextFactory; use PHPUnit\Framework\TestCase; /** @@ -40,4 +43,43 @@ public function testReconstituteADocBlock(): void $this->assertSame($docComment, $reconstitutedDocComment); } + + + /** + * Method + * + * Method which contains a modulo sign (%) in its description. + * + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * + * @covers ::__construct + * @covers ::render + * @covers ::__toString + */ + public function testDescriptionCanContainPercent(): void + { + $factory = DocBlockFactory::createInstance(); + $contextFactory = new ContextFactory(); + + $method = new \ReflectionMethod(self::class, 'testDescriptionCanContainPercent'); + + $docblock = $factory->create( + $method, + $contextFactory->createFromReflector($method->getDeclaringClass()) + ); + + $tag1 = new Generic('JoinColumn', new Description('(name="column_id", referencedColumnName="id")')); + $tag2 = new Generic('JoinColumn', new Description('(name="column_id_2", referencedColumnName="id")')); + + $tags = [ + $tag1, + $tag2, + ]; + + $fixture = $docblock->getDescription(); + $expected = 'Method which contains a modulo sign (%) in its description.'; + $this->assertSame($expected, (string) $fixture); + } } diff --git a/tests/unit/DocBlock/DescriptionTest.php b/tests/unit/DocBlock/DescriptionTest.php index 76e6049e..e1ddbd6c 100644 --- a/tests/unit/DocBlock/DescriptionTest.php +++ b/tests/unit/DocBlock/DescriptionTest.php @@ -165,7 +165,7 @@ public function testDescriptionWithEscapedCharactersAndNoTagsCanBeCastToString() {% endfor %}'; EOT; - $fixture = new Description($body, []); + $fixture = new Description($body, []); $this->assertSame($expected, (string) $fixture); } diff --git a/tests/unit/DocBlock/ExampleFinderTest.php b/tests/unit/DocBlock/ExampleFinderTest.php index c45337cb..6bc17ec4 100644 --- a/tests/unit/DocBlock/ExampleFinderTest.php +++ b/tests/unit/DocBlock/ExampleFinderTest.php @@ -14,8 +14,7 @@ */ class ExampleFinderTest extends TestCase { - /** @var ExampleFinder */ - private $fixture; + private ExampleFinder $fixture; /** * Call Mockery::close after each test.