diff --git a/composer.json b/composer.json index 11b7942e..fb069e2d 100644 --- a/composer.json +++ b/composer.json @@ -5,9 +5,6 @@ "homepage": "http://www.phpdoc.org", "license": "MIT", "autoload": { - "files": [ - "src/php-parser/Modifiers.php" - ], "psr-4": { "phpDocumentor\\": "src/phpDocumentor" } @@ -26,7 +23,7 @@ "require": { "php": "8.2.*|8.3.*|8.4.*|8.5.*", "composer-runtime-api": "^2", - "nikic/php-parser": "~4.18 || ^5.0", + "nikic/php-parser": "^5.0", "phpdocumentor/reflection-common": "^2.1", "phpdocumentor/reflection-docblock": "^6.0", "phpdocumentor/type-resolver": "^2.0", @@ -39,12 +36,11 @@ "mikey179/vfsstream": "~1.2", "mockery/mockery": "~1.6.0", "phpspec/prophecy-phpunit": "^2.4", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.8", - "phpstan/phpstan-webmozart-assert": "^1.2", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "^10.5.53", "psalm/phar": "^6.0", - "rector/rector": "^1.0.0", "squizlabs/php_codesniffer": "^3.8" }, "config": { diff --git a/composer.lock b/composer.lock index a77ec10d..1b956d34 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cfe51f5a85e10b88abd431aec95b3f22", + "content-hash": "079fb9744ea6bd4d536a99bbe5d13266", "packages": [ { "name": "doctrine/deprecations", @@ -1219,20 +1219,15 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.9", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpstan.git", - "reference": "ceb937fb39a92deabc02d20709cf14b2c452502c" - }, + "version": "2.1.55", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/ceb937fb39a92deabc02d20709cf14b2c452502c", - "reference": "ceb937fb39a92deabc02d20709cf14b2c452502c", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/9eaac3826ed5e9b8427350a43cac825eeca3f566", + "reference": "9eaac3826ed5e9b8427350a43cac825eeca3f566", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -1273,33 +1268,33 @@ "type": "github" } ], - "time": "2024-11-10T17:10:04+00:00" + "time": "2026-05-18T11:57:34+00:00" }, { "name": "phpstan/phpstan-webmozart-assert", - "version": "1.2.11", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-webmozart-assert.git", - "reference": "960dd44e8466191590dd0d7940d3e9496eebebbd" + "reference": "0c641817d2a8f05c7157f92d91986e74d3c8ab0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-webmozart-assert/zipball/960dd44e8466191590dd0d7940d3e9496eebebbd", - "reference": "960dd44e8466191590dd0d7940d3e9496eebebbd", + "url": "https://api.github.com/repos/phpstan/phpstan-webmozart-assert/zipball/0c641817d2a8f05c7157f92d91986e74d3c8ab0c", + "reference": "0c641817d2a8f05c7157f92d91986e74d3c8ab0c", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12" + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.0" }, "require-dev": { - "nikic/php-parser": "^4.13.0", + "nikic/php-parser": "^5.1", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-deprecation-rules": "^1.2", - "phpstan/phpstan-phpunit": "^1.4", - "phpstan/phpstan-strict-rules": "^1.6", - "phpunit/phpunit": "^9.5", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^9.6", "webmozart/assert": "^1.11.0" }, "type": "phpstan-extension", @@ -1322,9 +1317,9 @@ "description": "PHPStan webmozart/assert extension", "support": { "issues": "https://github.com/phpstan/phpstan-webmozart-assert/issues", - "source": "https://github.com/phpstan/phpstan-webmozart-assert/tree/1.2.11" + "source": "https://github.com/phpstan/phpstan-webmozart-assert/tree/2.0.0" }, - "time": "2024-09-11T15:48:08+00:00" + "time": "2024-10-14T03:45:26+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1791,65 +1786,6 @@ }, "time": "2026-03-19T11:11:23+00:00" }, - { - "name": "rector/rector", - "version": "1.2.10", - "source": { - "type": "git", - "url": "https://github.com/rectorphp/rector.git", - "reference": "40f9cf38c05296bd32f444121336a521a293fa61" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/40f9cf38c05296bd32f444121336a521a293fa61", - "reference": "40f9cf38c05296bd32f444121336a521a293fa61", - "shasum": "" - }, - "require": { - "php": "^7.2|^8.0", - "phpstan/phpstan": "^1.12.5" - }, - "conflict": { - "rector/rector-doctrine": "*", - "rector/rector-downgrade-php": "*", - "rector/rector-phpunit": "*", - "rector/rector-symfony": "*" - }, - "suggest": { - "ext-dom": "To manipulate phpunit.xml via the custom-rule command" - }, - "bin": [ - "bin/rector" - ], - "type": "library", - "autoload": { - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Instant Upgrade and Automated Refactoring of any PHP code", - "keywords": [ - "automation", - "dev", - "migration", - "refactoring" - ], - "support": { - "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/1.2.10" - }, - "funding": [ - { - "url": "https://github.com/tomasvotruba", - "type": "github" - } - ], - "time": "2024-11-08T13:59:10+00:00" - }, { "name": "sebastian/cli-parser", "version": "2.0.1", diff --git a/phpstan.neon b/phpstan.neon index 63041f70..381c7ad2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,19 +3,4 @@ parameters: - src level: max - ignoreErrors: - - '#Method phpDocumentor\\Reflection\\File\\LocalFile::md5\(\) should return string but returns string\|false\.#' - # - # all these $fqsen errors indicate the need for a decorator class around PhpParser\Node to hold the public $fqsen that Reflection is giving it) - # - # src/phpDocumentor/Reflection/NodeVisitor/ElementNameResolver.php - - '#Method phpDocumentor\\Reflection\\Php\\Factory\\(.*)::getFqsen\(\) should return phpDocumentor\\Reflection\\Fqsen but returns mixed\.#' - - '#Parameter \#1 \$fqsen of class phpDocumentor\\Reflection\\Php\\(.*) constructor expects phpDocumentor\\Reflection\\Fqsen, mixed given\.#' - - '#Parameter \#1 \$fqsen of method phpDocumentor\\Reflection\\Php\\File::addNamespace\(\) expects phpDocumentor\\Reflection\\Fqsen, mixed given\.#' - # - # Type hint in php-parser is incorrect. - - '#Cannot cast PhpParser\\Node\\Expr\|string to string.#' - - - '#Parameter \#2 \$object of method phpDocumentor\\Reflection\\Php\\ProjectFactoryStrategy::matches\(\) expects object, mixed given.#' - - '#Method phpDocumentor\\Reflection\\Php\\ValueEvaluator\\ConstantEvaluator::evaluate\(\) should return string but returns mixed.#' diff --git a/src/php-parser/Modifiers.php b/src/php-parser/Modifiers.php deleted file mode 100644 index 69ac740b..00000000 --- a/src/php-parser/Modifiers.php +++ /dev/null @@ -1,31 +0,0 @@ -path); + $hash = md5_file($this->path); + Assert::string($hash); + + return $hash; } /** diff --git a/src/phpDocumentor/Reflection/Middleware/ChainFactory.php b/src/phpDocumentor/Reflection/Middleware/ChainFactory.php index 08529722..3054b6e7 100644 --- a/src/phpDocumentor/Reflection/Middleware/ChainFactory.php +++ b/src/phpDocumentor/Reflection/Middleware/ChainFactory.php @@ -25,6 +25,7 @@ final class ChainFactory public static function createExecutionChain(array $middlewareList, callable $lastCallable): callable { while ($middleware = array_pop($middlewareList)) { + // @phpstan-ignore instanceof.alwaysTrue (runtime guard for invalid callers despite @param Middleware[]) if (!$middleware instanceof Middleware) { throw new InvalidArgumentException( sprintf( @@ -35,7 +36,7 @@ public static function createExecutionChain(array $middlewareList, callable $las ); } - $lastCallable = static fn ($command): object => $middleware->execute($command, $lastCallable); + $lastCallable = static fn (Command $command): object => $middleware->execute($command, $lastCallable); } return $lastCallable; diff --git a/src/phpDocumentor/Reflection/Php/Argument.php b/src/phpDocumentor/Reflection/Php/Argument.php index 2551553b..b229a490 100644 --- a/src/phpDocumentor/Reflection/Php/Argument.php +++ b/src/phpDocumentor/Reflection/Php/Argument.php @@ -16,11 +16,6 @@ use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Types\Mixed_; -use function is_string; -use function trigger_error; - -use const E_USER_DEPRECATED; - /** * Descriptor representing a single Argument of a method or function. * @@ -38,8 +33,8 @@ public function __construct( /** @var string name of the Argument */ private readonly string $name, Type|null $type = null, - /** @var Expression|string|null the default value for an argument or null if none is provided */ - private Expression|string|null $default = null, + /** @var Expression|null the default value for an argument or null if none is provided */ + private Expression|null $default = null, /** @var bool whether the argument passes the parameter by reference instead of by value */ private readonly bool $byReference = false, /** @var bool Determines if this Argument represents a variadic argument */ @@ -49,15 +44,6 @@ public function __construct( $type = new Mixed_(); } - if (is_string($this->default)) { - trigger_error( - 'Default values for arguments should be of type Expression, support for strings will be ' - . 'removed in 7.x', - E_USER_DEPRECATED, - ); - $this->default = new Expression($this->default, []); - } - $this->type = $type; } @@ -69,26 +55,13 @@ public function getName(): string return $this->name; } - public function getType(): Type|null + public function getType(): Type { return $this->type; } - public function getDefault(bool $asString = true): Expression|string|null + public function getDefault(): Expression|null { - if ($this->default === null) { - return null; - } - - if ($asString) { - trigger_error( - 'The Default value will become of type Expression by default', - E_USER_DEPRECATED, - ); - - return (string) $this->default; - } - return $this->default; } diff --git a/src/phpDocumentor/Reflection/Php/Constant.php b/src/phpDocumentor/Reflection/Php/Constant.php index 736dcdd0..12e97253 100644 --- a/src/phpDocumentor/Reflection/Php/Constant.php +++ b/src/phpDocumentor/Reflection/Php/Constant.php @@ -21,11 +21,6 @@ use phpDocumentor\Reflection\Metadata\MetaDataContainer as MetaDataContainerInterface; use phpDocumentor\Reflection\Type; -use function is_string; -use function trigger_error; - -use const E_USER_DEPRECATED; - /** * Descriptor representing a constant * @@ -48,7 +43,7 @@ final class Constant implements Element, MetaDataContainerInterface, AttributeCo public function __construct( private readonly Fqsen $fqsen, private readonly DocBlock|null $docBlock = null, - private Expression|string|null $value = null, + private Expression|null $value = null, Location|null $location = null, Location|null $endLocation = null, Visibility|null $visibility = null, @@ -58,37 +53,13 @@ public function __construct( $this->location = $location ?: new Location(-1); $this->endLocation = $endLocation ?: new Location(-1); $this->visibility = $visibility ?: new Visibility(Visibility::PUBLIC_); - - if (!is_string($this->value)) { - return; - } - - trigger_error( - 'Constant values should be of type Expression, support for strings will be ' - . 'removed in 6.x', - E_USER_DEPRECATED, - ); - $this->value = new Expression($this->value, []); } /** * Returns the expression value for this constant. */ - public function getValue(bool $asString = true): Expression|string|null + public function getValue(): Expression|null { - if ($this->value === null) { - return null; - } - - if ($asString) { - trigger_error( - 'The expression value will become of type Expression by default', - E_USER_DEPRECATED, - ); - - return (string) $this->value; - } - return $this->value; } diff --git a/src/phpDocumentor/Reflection/Php/EnumCase.php b/src/phpDocumentor/Reflection/Php/EnumCase.php index f70934ff..7ee17304 100644 --- a/src/phpDocumentor/Reflection/Php/EnumCase.php +++ b/src/phpDocumentor/Reflection/Php/EnumCase.php @@ -11,11 +11,6 @@ use phpDocumentor\Reflection\Location; use phpDocumentor\Reflection\Metadata\MetaDataContainer as MetaDataContainerInterface; -use function is_string; -use function trigger_error; - -use const E_USER_DEPRECATED; - /** * Represents a case in an Enum. * @@ -35,7 +30,7 @@ public function __construct( private readonly DocBlock|null $docBlock, Location|null $location = null, Location|null $endLocation = null, - private Expression|string|null $value = null, + private Expression|null $value = null, ) { if ($location === null) { $location = new Location(-1); @@ -47,16 +42,6 @@ public function __construct( $this->location = $location; $this->endLocation = $endLocation; - if (!is_string($this->value)) { - return; - } - - trigger_error( - 'Expression values for enum cases should be of type Expression, support for strings will be ' - . 'removed in 7.x', - E_USER_DEPRECATED, - ); - $this->value = new Expression($this->value, []); } #[Override] @@ -89,21 +74,8 @@ public function getEndLocation(): Location /** * Returns the value for this enum case. */ - public function getValue(bool $asString = true): Expression|string|null + public function getValue(): Expression|null { - if ($this->value === null) { - return null; - } - - if ($asString) { - trigger_error( - 'The enum case value will become of type Expression by default', - E_USER_DEPRECATED, - ); - - return (string) $this->value; - } - return $this->value; } } diff --git a/src/phpDocumentor/Reflection/Php/Expression.php b/src/phpDocumentor/Reflection/Php/Expression.php index d1e12d41..fcd4cf6c 100644 --- a/src/phpDocumentor/Reflection/Php/Expression.php +++ b/src/phpDocumentor/Reflection/Php/Expression.php @@ -88,6 +88,7 @@ public static function generatePlaceholder(string $name): string public function __construct(string $expression, array $parts = []) { Assert::stringNotEmpty($expression); + // @phpstan-ignore staticMethod.alreadyNarrowedType (runtime guard for invalid callers despite @param annotation) Assert::allIsInstanceOfAny($parts, [Fqsen::class, Type::class]); $this->expression = $expression; diff --git a/src/phpDocumentor/Reflection/Php/Factory/ClassConstantIterator.php b/src/phpDocumentor/Reflection/Php/Factory/ClassConstantIterator.php index 278d21ae..63e293cc 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/ClassConstantIterator.php +++ b/src/phpDocumentor/Reflection/Php/Factory/ClassConstantIterator.php @@ -22,6 +22,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\Stmt\ClassConst; +use Webmozart\Assert\Assert; /** * This class acts like a combination of a ClassConst and Const_ @@ -74,7 +75,10 @@ public function getName(): string */ public function getFqsen(): Fqsen { - return $this->classConstants->consts[$this->index]->getAttribute('fqsen'); + $fqsen = $this->classConstants->consts[$this->index]->getAttribute('fqsen'); + Assert::isInstanceOf($fqsen, Fqsen::class); + + return $fqsen; } /** @@ -150,7 +154,7 @@ public function next(): void /** @link http://php.net/manual/en/iterator.key.php */ #[Override] - public function key(): int|null + public function key(): int { return $this->index; } diff --git a/src/phpDocumentor/Reflection/Php/Factory/Class_.php b/src/phpDocumentor/Reflection/Php/Factory/Class_.php index 9c0f825e..7437610e 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Class_.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Class_.php @@ -20,6 +20,7 @@ use phpDocumentor\Reflection\Php\File as FileElement; use phpDocumentor\Reflection\Php\StrategyContainer; use PhpParser\Node\Stmt\Class_ as ClassNode; +use Webmozart\Assert\Assert; use function assert; @@ -44,12 +45,15 @@ public function matches(ContextStack $context, object $object): bool * @param ClassNode $object */ #[Override] - protected function doCreate(ContextStack $context, object $object, StrategyContainer $strategies): object|null + protected function doCreate(ContextStack $context, object $object, StrategyContainer $strategies): object { $docBlock = $this->createDocBlock($object->getDocComment(), $context->getTypeContext()); + $fqsen = $object->getAttribute('fqsen'); + Assert::isInstanceOf($fqsen, Fqsen::class); + $classElement = new ClassElement( - $object->getAttribute('fqsen'), + $fqsen, $docBlock, isset($object->extends) ? new Fqsen('\\' . $object->extends) : null, $object->isAbstract(), diff --git a/src/phpDocumentor/Reflection/Php/Factory/ConstructorPromotion.php b/src/phpDocumentor/Reflection/Php/Factory/ConstructorPromotion.php index 69c709bd..0893d56e 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/ConstructorPromotion.php +++ b/src/phpDocumentor/Reflection/Php/Factory/ConstructorPromotion.php @@ -46,7 +46,7 @@ public function matches(ContextStack $context, object $object): bool /** @param ClassMethod $object */ #[Override] - protected function doCreate(ContextStack $context, object $object, StrategyContainer $strategies): object|null + protected function doCreate(ContextStack $context, object $object, StrategyContainer $strategies): object { $this->methodStrategy->create($context, $object, $strategies); @@ -67,12 +67,15 @@ private function promoteParameterToProperty(ContextStack $context, StrategyConta Assert::isInstanceOf($methodContainer, ClassElement::class); Assert::isInstanceOf($param->var, Variable::class); + $varName = $param->var->name; + Assert::string($varName); + $property = PropertyBuilder::create( $this->valueConverter, $this->docBlockFactory, $strategies, $this->reducers, - )->fqsen(new Fqsen($methodContainer->getFqsen() . '::$' . (string) $param->var->name)) + )->fqsen(new Fqsen($methodContainer->getFqsen() . '::$' . $varName)) ->visibility($param) ->type($param->type) ->docblock($param->getDocComment()) diff --git a/src/phpDocumentor/Reflection/Php/Factory/EnumCase.php b/src/phpDocumentor/Reflection/Php/Factory/EnumCase.php index 8e1fc9bc..222244e9 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/EnumCase.php +++ b/src/phpDocumentor/Reflection/Php/Factory/EnumCase.php @@ -6,6 +6,7 @@ use Override; use phpDocumentor\Reflection\DocBlockFactoryInterface; +use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\Location; use phpDocumentor\Reflection\Php\Enum_ as EnumElement; use phpDocumentor\Reflection\Php\EnumCase as EnumCaseElement; @@ -15,6 +16,7 @@ use phpDocumentor\Reflection\Php\StrategyContainer; use PhpParser\Node\Stmt\EnumCase as EnumCaseNode; use PhpParser\PrettyPrinter\Standard as PrettyPrinter; +use Webmozart\Assert\Assert; use function assert; use function is_string; @@ -38,14 +40,17 @@ public function matches(ContextStack $context, object $object): bool /** @param EnumCaseNode $object */ #[Override] - protected function doCreate(ContextStack $context, object $object, StrategyContainer $strategies): object|null + protected function doCreate(ContextStack $context, object $object, StrategyContainer $strategies): object { $docBlock = $this->createDocBlock($object->getDocComment(), $context->getTypeContext()); $enum = $context->peek(); assert($enum instanceof EnumElement); + $fqsen = $object->getAttribute('fqsen'); + Assert::isInstanceOf($fqsen, Fqsen::class); + $case = new EnumCaseElement( - $object->getAttribute('fqsen'), + $fqsen, $docBlock, new Location($object->getLine()), new Location($object->getEndLine()), diff --git a/src/phpDocumentor/Reflection/Php/Factory/Enum_.php b/src/phpDocumentor/Reflection/Php/Factory/Enum_.php index 4a8d7b46..2faed6ce 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Enum_.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Enum_.php @@ -19,6 +19,7 @@ use phpDocumentor\Reflection\Php\File as FileElement; use phpDocumentor\Reflection\Php\StrategyContainer; use PhpParser\Node\Stmt\Enum_ as EnumNode; +use Webmozart\Assert\Assert; use function assert; @@ -32,12 +33,15 @@ public function matches(ContextStack $context, object $object): bool /** @param EnumNode $object */ #[Override] - protected function doCreate(ContextStack $context, object $object, StrategyContainer $strategies): object|null + protected function doCreate(ContextStack $context, object $object, StrategyContainer $strategies): object { $docBlock = $this->createDocBlock($object->getDocComment(), $context->getTypeContext()); + $fqsen = $object->getAttribute('fqsen'); + Assert::isInstanceOf($fqsen, Fqsen::class); + $enum = new \phpDocumentor\Reflection\Php\Enum_( - $object->getAttribute('fqsen'), + $fqsen, (new Type())->fromPhpParser($object->scalarType), $docBlock, new Location($object->getLine()), diff --git a/src/phpDocumentor/Reflection/Php/Factory/File.php b/src/phpDocumentor/Reflection/Php/Factory/File.php index 1f36584d..c3f57cef 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/File.php +++ b/src/phpDocumentor/Reflection/Php/Factory/File.php @@ -34,6 +34,7 @@ use PhpParser\Node\Stmt\InlineHTML; use PhpParser\Node\Stmt\Interface_ as InterfaceNode; use PhpParser\Node\Stmt\Trait_ as TraitNode; +use Webmozart\Assert\Assert; use function array_merge; use function in_array; @@ -64,7 +65,7 @@ public function __construct( ) { parent::__construct($docBlockFactory); - $lastCallable = fn ($command): FileElement => $this->createFile($command); + $lastCallable = fn (CreateCommand $command): FileElement => $this->createFile($command); $this->middlewareChain = ChainFactory::createExecutionChain($middleware, $lastCallable); } @@ -96,6 +97,7 @@ protected function doCreate(ContextStack $context, object $object, StrategyConta return null; } + Assert::isInstanceOf($file, FileElement::class); $context->getProject()->addFile($file); return $file; diff --git a/src/phpDocumentor/Reflection/Php/Factory/Function_.php b/src/phpDocumentor/Reflection/Php/Factory/Function_.php index fc771552..7273a64f 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Function_.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Function_.php @@ -14,6 +14,7 @@ namespace phpDocumentor\Reflection\Php\Factory; use Override; +use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\Location; use phpDocumentor\Reflection\Php\File as FileElement; use phpDocumentor\Reflection\Php\Function_ as FunctionDescriptor; @@ -47,12 +48,15 @@ protected function doCreate( ContextStack $context, object $object, StrategyContainer $strategies, - ): object|null { + ): object { $file = $context->peek(); Assert::isInstanceOf($file, FileElement::class); + $fqsen = $object->getAttribute('fqsen'); + Assert::isInstanceOf($fqsen, Fqsen::class); + $function = new FunctionDescriptor( - $object->getAttribute('fqsen'), + $fqsen, $this->createDocBlock($object->getDocComment(), $context->getTypeContext()), new Location($object->getLine()), new Location($object->getEndLine()), diff --git a/src/phpDocumentor/Reflection/Php/Factory/GlobalConstantIterator.php b/src/phpDocumentor/Reflection/Php/Factory/GlobalConstantIterator.php index ccbf11c8..f58dda1c 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/GlobalConstantIterator.php +++ b/src/phpDocumentor/Reflection/Php/Factory/GlobalConstantIterator.php @@ -19,6 +19,7 @@ use PhpParser\Comment\Doc; use PhpParser\Node\Expr; use PhpParser\Node\Stmt\Const_; +use Webmozart\Assert\Assert; /** @implements Iterator */ final class GlobalConstantIterator implements Iterator @@ -66,7 +67,10 @@ public function getName(): string */ public function getFqsen(): Fqsen { - return $this->constant->consts[$this->index]->getAttribute('fqsen'); + $fqsen = $this->constant->consts[$this->index]->getAttribute('fqsen'); + Assert::isInstanceOf($fqsen, Fqsen::class); + + return $fqsen; } /** @@ -105,7 +109,7 @@ public function next(): void /** @link http://php.net/manual/en/iterator.key.php */ #[Override] - public function key(): int|null + public function key(): int { return $this->index; } diff --git a/src/phpDocumentor/Reflection/Php/Factory/Interface_.php b/src/phpDocumentor/Reflection/Php/Factory/Interface_.php index bc4fbc0a..70b05d25 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Interface_.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Interface_.php @@ -49,15 +49,18 @@ protected function doCreate( ContextStack $context, object $object, StrategyContainer $strategies, - ): object|null { + ): object { $docBlock = $this->createDocBlock($object->getDocComment(), $context->getTypeContext()); $parents = []; foreach ($object->extends as $extend) { $parents['\\' . (string) $extend] = new Fqsen('\\' . (string) $extend); } + $fqsen = $object->getAttribute('fqsen'); + Assert::isInstanceOf($fqsen, Fqsen::class); + $interface = new InterfaceElement( - $object->getAttribute('fqsen'), + $fqsen, $parents, $docBlock, new Location($object->getLine()), diff --git a/src/phpDocumentor/Reflection/Php/Factory/Method.php b/src/phpDocumentor/Reflection/Php/Factory/Method.php index 2ffe0a8b..caa2cb6a 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Method.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Method.php @@ -14,6 +14,7 @@ namespace phpDocumentor\Reflection\Php\Factory; use Override; +use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\Location; use phpDocumentor\Reflection\Php\Class_; use phpDocumentor\Reflection\Php\Enum_; @@ -49,7 +50,7 @@ protected function doCreate( ContextStack $context, object $object, StrategyContainer $strategies, - ): object|null { + ): object { $methodContainer = $context->peek(); Assert::isInstanceOfAny( $methodContainer, @@ -61,8 +62,11 @@ protected function doCreate( ], ); + $fqsen = $object->getAttribute('fqsen'); + Assert::isInstanceOf($fqsen, Fqsen::class); + $method = new MethodDescriptor( - $object->getAttribute('fqsen'), + $fqsen, $this->buildVisibility($object), $this->createDocBlock($object->getDocComment(), $context->getTypeContext()), $object->isAbstract(), diff --git a/src/phpDocumentor/Reflection/Php/Factory/Namespace_.php b/src/phpDocumentor/Reflection/Php/Factory/Namespace_.php index 788b5b42..9998ec7f 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Namespace_.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Namespace_.php @@ -41,7 +41,8 @@ public function create(ContextStack $context, object $object, StrategyContainer $file = $context->peek(); Assert::isInstanceOf($file, FileElement::class); - $file->addNamespace($object->getAttribute('fqsen') ?? new Fqsen('\\')); + $rawFqsen = $object->getAttribute('fqsen'); + $file->addNamespace($rawFqsen instanceof Fqsen ? $rawFqsen : new Fqsen('\\')); $typeContext = (new NamespaceNodeToContext())($object); foreach ($object->stmts as $stmt) { $strategy = $strategies->findMatching($context, $stmt); diff --git a/src/phpDocumentor/Reflection/Php/Factory/PropertyBuilder.php b/src/phpDocumentor/Reflection/Php/Factory/PropertyBuilder.php index d0e10994..91337c6b 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/PropertyBuilder.php +++ b/src/phpDocumentor/Reflection/Php/Factory/PropertyBuilder.php @@ -18,7 +18,6 @@ use phpDocumentor\Reflection\Php\Visibility; use phpDocumentor\Reflection\Types\Context; use PhpParser\Comment\Doc; -use PhpParser\Modifiers; use PhpParser\Node; use PhpParser\Node\ComplexType; use PhpParser\Node\Expr; @@ -36,7 +35,6 @@ use function array_map; use function count; use function is_string; -use function method_exists; /** * This class is responsible for building a property element from a PhpParser node. @@ -182,10 +180,6 @@ public function build(ContextStack $context): PropertyElement */ private function isAsymmetric(Param|PropertyIterator $node): bool { - if (method_exists($node, 'isPrivateSet') === false) { - return false; - } - return $node->isPublicSet() || $node->isProtectedSet() || $node->isPrivateSet(); } @@ -210,10 +204,6 @@ private function buildVisibility(Param|PropertyIterator $node): Visibility private function buildReadVisibility(Param|PropertyIterator $node): Visibility { - if ($node instanceof Param && method_exists($node, 'isPublic') === false) { - return $this->buildVisibilityFromFlags($node->flags); - } - if ($node->isPrivate()) { return new Visibility(Visibility::PRIVATE_); } @@ -225,19 +215,6 @@ private function buildReadVisibility(Param|PropertyIterator $node): Visibility return new Visibility(Visibility::PUBLIC_); } - private function buildVisibilityFromFlags(int $flags): Visibility - { - if ((bool) ($flags & Modifiers::PRIVATE) === true) { - return new Visibility(Visibility::PRIVATE_); - } - - if ((bool) ($flags & Modifiers::PROTECTED) === true) { - return new Visibility(Visibility::PROTECTED_); - } - - return new Visibility(Visibility::PUBLIC_); - } - private function buildWriteVisibility(Param|PropertyIterator $node): Visibility { if ($node->isPrivateSet()) { diff --git a/src/phpDocumentor/Reflection/Php/Factory/PropertyIterator.php b/src/phpDocumentor/Reflection/Php/Factory/PropertyIterator.php index ea0c5cac..8933bd78 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/PropertyIterator.php +++ b/src/phpDocumentor/Reflection/Php/Factory/PropertyIterator.php @@ -23,9 +23,7 @@ use PhpParser\Node\Name; use PhpParser\Node\PropertyHook; use PhpParser\Node\Stmt\Property as PropertyNode; - -use function method_exists; -use function property_exists; +use Webmozart\Assert\Assert; /** * This class acts like a combination of a PropertyNode and PropertyProperty to @@ -118,10 +116,6 @@ public function isPrivateSet(): bool */ public function isAsymmetric(): bool { - if (method_exists($this->property, 'isPrivateSet') === false) { - return false; - } - return $this->property->isPublicSet() || $this->property->isProtectedSet() || $this->property->isPrivateSet(); } @@ -201,16 +195,15 @@ public function getDefault(): Expr|null */ public function getFqsen(): Fqsen { - return $this->property->props[$this->index]->getAttribute('fqsen'); + $fqsen = $this->property->props[$this->index]->getAttribute('fqsen'); + Assert::isInstanceOf($fqsen, Fqsen::class); + + return $fqsen; } /** @return PropertyHook[] */ public function getHooks(): array { - if (property_exists($this->property, 'hooks') === false) { - return []; - } - return $this->property->hooks; } @@ -230,7 +223,7 @@ public function next(): void /** @link http://php.net/manual/en/iterator.key.php */ #[Override] - public function key(): int|null + public function key(): int { return $this->index; } diff --git a/src/phpDocumentor/Reflection/Php/Factory/Reducer/Attribute.php b/src/phpDocumentor/Reflection/Php/Factory/Reducer/Attribute.php index ed448610..f90f4e49 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Reducer/Attribute.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Reducer/Attribute.php @@ -14,6 +14,7 @@ use PhpParser\Node\Arg; use PhpParser\Node\AttributeGroup; use PhpParser\PrettyPrinter\Standard; +use Webmozart\Assert\Assert; use function array_map; use function assert; @@ -48,6 +49,7 @@ public function reduce( throw new InvalidArgumentException(sprintf('Attribute can not be added on %s', $carry::class)); } + Assert::isArray($object->attrGroups); foreach ($object->attrGroups as $attrGroup) { assert($attrGroup instanceof AttributeGroup); foreach ($attrGroup->attrs as $attr) { diff --git a/src/phpDocumentor/Reflection/Php/Factory/Trait_.php b/src/phpDocumentor/Reflection/Php/Factory/Trait_.php index 41245877..51a15f2f 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Trait_.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Trait_.php @@ -14,6 +14,7 @@ namespace phpDocumentor\Reflection\Php\Factory; use Override; +use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\Location; use phpDocumentor\Reflection\Php\File as FileElement; use phpDocumentor\Reflection\Php\StrategyContainer; @@ -39,10 +40,13 @@ public function matches(ContextStack $context, object $object): bool * @param TraitNode $object */ #[Override] - protected function doCreate(ContextStack $context, object $object, StrategyContainer $strategies): object|null + protected function doCreate(ContextStack $context, object $object, StrategyContainer $strategies): object { + $fqsen = $object->getAttribute('fqsen'); + Assert::isInstanceOf($fqsen, Fqsen::class); + $trait = new TraitElement( - $object->getAttribute('fqsen'), + $fqsen, $this->createDocBlock($object->getDocComment(), $context->getTypeContext()), new Location($object->getLine()), new Location($object->getEndLine()), diff --git a/src/phpDocumentor/Reflection/Php/Interface_.php b/src/phpDocumentor/Reflection/Php/Interface_.php index 64ce1ac6..5ed74aed 100644 --- a/src/phpDocumentor/Reflection/Php/Interface_.php +++ b/src/phpDocumentor/Reflection/Php/Interface_.php @@ -57,6 +57,7 @@ public function __construct( Location|null $location = null, Location|null $endLocation = null, ) { + // @phpstan-ignore staticMethod.alreadyNarrowedType (runtime guard for invalid callers despite @param annotation) Assert::allIsInstanceOf($parents, Fqsen::class); $this->location = $location ?: new Location(-1); $this->endLocation = $endLocation ?: new Location(-1); diff --git a/src/phpDocumentor/Reflection/Php/ProjectFactoryStrategies.php b/src/phpDocumentor/Reflection/Php/ProjectFactoryStrategies.php index 00c3af7c..3c13d253 100644 --- a/src/phpDocumentor/Reflection/Php/ProjectFactoryStrategies.php +++ b/src/phpDocumentor/Reflection/Php/ProjectFactoryStrategies.php @@ -19,6 +19,7 @@ use SplPriorityQueue; use function get_debug_type; +use function is_object; use function sprintf; final class ProjectFactoryStrategies implements StrategyContainer @@ -49,9 +50,11 @@ public function __construct(array $strategies) #[Override] public function findMatching(ContextStack $context, mixed $object): ProjectFactoryStrategy { - foreach (clone $this->strategies as $strategy) { - if ($strategy->matches($context, $object)) { - return $strategy; + if (is_object($object)) { + foreach (clone $this->strategies as $strategy) { + if ($strategy->matches($context, $object)) { + return $strategy; + } } } diff --git a/src/phpDocumentor/Reflection/Php/Property.php b/src/phpDocumentor/Reflection/Php/Property.php index 7f0c00c5..792514cf 100644 --- a/src/phpDocumentor/Reflection/Php/Property.php +++ b/src/phpDocumentor/Reflection/Php/Property.php @@ -21,11 +21,6 @@ use phpDocumentor\Reflection\Metadata\MetaDataContainer as MetaDataContainerInterface; use phpDocumentor\Reflection\Type; -use function is_string; -use function trigger_error; - -use const E_USER_DEPRECATED; - /** * Descriptor representing a property. * @@ -53,7 +48,7 @@ public function __construct( private readonly Fqsen $fqsen, Visibility|null $visibility = null, private readonly DocBlock|null $docBlock = null, - private Expression|string|null $default = null, + private Expression|null $default = null, private readonly bool $static = false, Location|null $location = null, Location|null $endLocation = null, @@ -65,37 +60,13 @@ public function __construct( $this->visibility = $visibility ?: new Visibility('public'); $this->location = $location ?: new Location(-1); $this->endLocation = $endLocation ?: new Location(-1); - - if (!is_string($this->default)) { - return; - } - - trigger_error( - 'Default values for properties should be of type Expression, support for strings will be ' - . 'removed in 7.x', - E_USER_DEPRECATED, - ); - $this->default = new Expression($this->default, []); } /** * Returns the default value for this property. */ - public function getDefault(bool $asString = true): Expression|string|null + public function getDefault(): Expression|null { - if ($this->default === null) { - return null; - } - - if ($asString) { - trigger_error( - 'The Default value will become of type Expression by default', - E_USER_DEPRECATED, - ); - - return (string) $this->default; - } - return $this->default; } diff --git a/src/phpDocumentor/Reflection/Php/PropertyHook.php b/src/phpDocumentor/Reflection/Php/PropertyHook.php index 9def360b..5ae73925 100644 --- a/src/phpDocumentor/Reflection/Php/PropertyHook.php +++ b/src/phpDocumentor/Reflection/Php/PropertyHook.php @@ -44,7 +44,7 @@ public function isFinal(): bool /** * Returns the Visibility of this hook. */ - public function getVisibility(): Visibility|null + public function getVisibility(): Visibility { return $this->visibility; } diff --git a/src/phpDocumentor/Reflection/Php/ValueEvaluator/ConstantEvaluator.php b/src/phpDocumentor/Reflection/Php/ValueEvaluator/ConstantEvaluator.php index 02834ea1..777fb5c1 100644 --- a/src/phpDocumentor/Reflection/Php/ValueEvaluator/ConstantEvaluator.php +++ b/src/phpDocumentor/Reflection/Php/ValueEvaluator/ConstantEvaluator.php @@ -9,6 +9,7 @@ use PhpParser\ConstExprEvaluator; use PhpParser\Node\Expr; use PhpParser\Node\Scalar\MagicConst\Namespace_; +use Webmozart\Assert\Assert; use function sprintf; @@ -21,7 +22,10 @@ public function evaluate(Expr $expr, ContextStack $contextStack): string // @codeCoverageIgnoreStart $evaluator = new ConstExprEvaluator(fn (Expr $expr): string => $this->evaluateFallback($expr, $contextStack)); - return $evaluator->evaluateSilently($expr); + $result = $evaluator->evaluateSilently($expr); + Assert::string($result); + + return $result; // @codeCoverageIgnoreEnd } diff --git a/tests/integration/EnumTest.php b/tests/integration/EnumTest.php index bf3d12e6..470f9b60 100644 --- a/tests/integration/EnumTest.php +++ b/tests/integration/EnumTest.php @@ -63,7 +63,7 @@ public function testEnumWithConstant(): void self::assertInstanceOf(Enum_::class, $enum); self::assertCount(2, $enum->getConstants()); self::assertArrayHasKey('\MyNamespace\MyEnumWithConstant::MYCONST', $enum->getConstants()); - self::assertSame("'MyConstValue'", $enum->getConstants()['\MyNamespace\MyEnumWithConstant::MYCONST']->getValue()); + self::assertSame("'MyConstValue'", (string) $enum->getConstants()['\MyNamespace\MyEnumWithConstant::MYCONST']->getValue()); } public function testBackedEnum(): void @@ -77,8 +77,8 @@ public function testBackedEnum(): void self::assertArrayHasKey('\MyNamespace\MyBackedEnum::VALUE1', $enum->getCases()); self::assertArrayHasKey('\MyNamespace\MyBackedEnum::VALUE2', $enum->getCases()); - self::assertSame("'this is value1'", $enum->getCases()['\MyNamespace\MyBackedEnum::VALUE1']->getValue()); - self::assertSame("'this is value2'", $enum->getCases()['\MyNamespace\MyBackedEnum::VALUE2']->getValue()); + self::assertSame("'this is value1'", (string) $enum->getCases()['\MyNamespace\MyBackedEnum::VALUE1']->getValue()); + self::assertSame("'this is value2'", (string) $enum->getCases()['\MyNamespace\MyBackedEnum::VALUE2']->getValue()); } public function testEnumSupportInProperty(): void @@ -89,7 +89,7 @@ public function testEnumSupportInProperty(): void self::assertEquals( '\MyNamespace\MyEnum::VALUE1', - $class->getProperties()['\MyNamespace\EnumConsumer::$myEnum']->getDefault() + (string) $class->getProperties()['\MyNamespace\EnumConsumer::$myEnum']->getDefault() ); self::assertEquals( @@ -117,7 +117,7 @@ public function testEnumSupportInMethod(): void self::assertEquals( '\MyNamespace\MyEnum::VALUE1', - $method->getArguments()[0]->getDefault() + (string) $method->getArguments()[0]->getDefault() ); } } diff --git a/tests/integration/PHP8/ConstructorPromotionTest.php b/tests/integration/PHP8/ConstructorPromotionTest.php index dd7dfb05..d7ecd1cb 100644 --- a/tests/integration/PHP8/ConstructorPromotionTest.php +++ b/tests/integration/PHP8/ConstructorPromotionTest.php @@ -51,7 +51,7 @@ public function testArgumentsAreReadCorrectly() : void $class = $file->getClasses()['\\PHP8\\ConstructorPromotion']; $constructor = $this->expectedConstructorMethod(); - $constructor->addArgument(new Argument('name', new String_(), "'default name'")); + $constructor->addArgument(new Argument('name', new String_(), new Expression("'default name'"))); $constructor->addArgument( new Argument( 'email', @@ -149,7 +149,7 @@ private function expectedNameProperty(): Property ], new Context('PHP8', ['DateTimeImmutable' => 'DateTimeImmutable']) ), - "'default name'", + new Expression("'default name'"), false, new Location(26), new Location(26), diff --git a/tests/integration/ProjectCreationTest.php b/tests/integration/ProjectCreationTest.php index 63558a71..cb36a929 100644 --- a/tests/integration/ProjectCreationTest.php +++ b/tests/integration/ProjectCreationTest.php @@ -75,7 +75,7 @@ public function testCreateProjectWithClass() : void ); $constant = $project->getFiles()[$fileName]->getClasses()['\\Pizza']->getConstants()['\\Pizza::PACKAGING']; - $this->assertEquals('\'box\'', $constant->getValue()); + $this->assertEquals('\'box\'', (string) $constant->getValue()); } public function testTypedPropertiesReturnTheirType() : void @@ -141,7 +141,7 @@ public function testWithNamespacedClass() : void '{{ PHPDOC37a6259cc0c1dae299a7866489dff0bd }}' => new Null_(), ], ), - $sauceArgument->getDefault(false) + $sauceArgument->getDefault() ); } @@ -270,7 +270,7 @@ public function testFunctionContantDefaultIsResolved() : void '{{ PHPDOCa2f2ed4f8ebc2cbb4c21a29dc40ab61d }}' => new Fqsen('\Acme\Plugin::class'), ], ), - $functions['\foo()']->getArguments()[0]->getDefault(false) + $functions['\foo()']->getArguments()[0]->getDefault() ); self::assertEquals( @@ -280,7 +280,7 @@ public function testFunctionContantDefaultIsResolved() : void '{{ PHPDOCa8cfde6331bd59eb2ac96f8911c4b666 }}' => new Object_(), ], ), - $functions['\bar()']->getArguments()[0]->getDefault(false) + $functions['\bar()']->getArguments()[0]->getDefault() ); } } diff --git a/tests/unit/phpDocumentor/Reflection/Php/EnumCaseTest.php b/tests/unit/phpDocumentor/Reflection/Php/EnumCaseTest.php index f8b50ac3..18eaa8db 100644 --- a/tests/unit/phpDocumentor/Reflection/Php/EnumCaseTest.php +++ b/tests/unit/phpDocumentor/Reflection/Php/EnumCaseTest.php @@ -102,10 +102,10 @@ public function testValueCanBeProvidedAsAnExpression(): void $expression, ); - $this->assertSame($expression, $fixture->getValue(false)); + $this->assertSame($expression, $fixture->getValue()); } - public function testValueCanBeReturnedAsString(): void + public function testValueCanBeReturnedAsExpression(): void { $expression = new Expression('Enum case expression'); $fixture = new EnumCase( @@ -116,7 +116,7 @@ public function testValueCanBeReturnedAsString(): void $expression, ); - $this->assertSame('Enum case expression', $fixture->getValue(true)); + $this->assertSame($expression, $fixture->getValue()); } public function testGetLocationReturnsProvidedValue(): void diff --git a/tests/unit/phpDocumentor/Reflection/Php/Factory/ClassConstantTest.php b/tests/unit/phpDocumentor/Reflection/Php/Factory/ClassConstantTest.php index b0388675..27017851 100644 --- a/tests/unit/phpDocumentor/Reflection/Php/Factory/ClassConstantTest.php +++ b/tests/unit/phpDocumentor/Reflection/Php/Factory/ClassConstantTest.php @@ -192,7 +192,7 @@ private function assertConstant(ConstantDescriptor $constant, string $visibility { $this->assertInstanceOf(ConstantDescriptor::class, $constant); $this->assertEquals('\Space\MyClass::MY_CONST1', (string) $constant->getFqsen()); - $this->assertEquals('\'a\'', $constant->getValue()); + $this->assertEquals('\'a\'', (string) $constant->getValue()); $this->assertEquals($visibility, (string) $constant->getVisibility()); } diff --git a/tests/unit/phpDocumentor/Reflection/Php/Factory/ConstructorPromotionTest.php b/tests/unit/phpDocumentor/Reflection/Php/Factory/ConstructorPromotionTest.php index bb63942d..f3d33865 100644 --- a/tests/unit/phpDocumentor/Reflection/Php/Factory/ConstructorPromotionTest.php +++ b/tests/unit/phpDocumentor/Reflection/Php/Factory/ConstructorPromotionTest.php @@ -8,6 +8,7 @@ use phpDocumentor\Reflection\DocBlockFactoryInterface; use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\Php\Class_ as ClassElement; +use phpDocumentor\Reflection\Php\Expression; use phpDocumentor\Reflection\Php\Interface_ as InterfaceElement; use phpDocumentor\Reflection\Php\Project; use phpDocumentor\Reflection\Php\ProjectFactoryStrategy; @@ -127,7 +128,7 @@ public function testCreateWithProperty(int $flags, string $visibility, bool $rea self::assertInstanceOf(PropertyElement::class, $property); self::assertEquals($visibility, $property->getVisibility()); self::assertSame($docBlock, $property->getDocBlock()); - self::assertSame('myType', $property->getDefault()); + self::assertEquals(new Expression('myType'), $property->getDefault()); self::assertEquals('\MyClass::$myArgument', $property->getFqsen()); self::assertSame($readOnly, $property->isReadOnly()); } diff --git a/tests/unit/phpDocumentor/Reflection/Php/Factory/DefineTest.php b/tests/unit/phpDocumentor/Reflection/Php/Factory/DefineTest.php index c0668641..9539f3af 100644 --- a/tests/unit/phpDocumentor/Reflection/Php/Factory/DefineTest.php +++ b/tests/unit/phpDocumentor/Reflection/Php/Factory/DefineTest.php @@ -148,7 +148,7 @@ private function assertConstant(ConstantDescriptor $constant, string $namespace) { $this->assertInstanceOf(ConstantDescriptor::class, $constant); $this->assertEquals($namespace . '\\MY_CONST1', (string) $constant->getFqsen()); - $this->assertEquals('\'a\'', $constant->getValue()); + $this->assertEquals('\'a\'', (string) $constant->getValue()); $this->assertEquals('public', (string) $constant->getVisibility()); } } diff --git a/tests/unit/phpDocumentor/Reflection/Php/Factory/GlobalConstantTest.php b/tests/unit/phpDocumentor/Reflection/Php/Factory/GlobalConstantTest.php index 533c18f6..55e3dd8f 100644 --- a/tests/unit/phpDocumentor/Reflection/Php/Factory/GlobalConstantTest.php +++ b/tests/unit/phpDocumentor/Reflection/Php/Factory/GlobalConstantTest.php @@ -103,7 +103,7 @@ private function assertConstant(ConstantDescriptor $constant): void { $this->assertInstanceOf(ConstantDescriptor::class, $constant); $this->assertEquals('\Space\MyClass\MY_CONST1', (string) $constant->getFqsen()); - $this->assertEquals('\'a\'', $constant->getValue()); + $this->assertEquals('\'a\'', (string) $constant->getValue()); $this->assertEquals('public', (string) $constant->getVisibility()); } } diff --git a/tests/unit/phpDocumentor/Reflection/Php/Factory/PropertyTest.php b/tests/unit/phpDocumentor/Reflection/Php/Factory/PropertyTest.php index dee73daf..5c53dff5 100644 --- a/tests/unit/phpDocumentor/Reflection/Php/Factory/PropertyTest.php +++ b/tests/unit/phpDocumentor/Reflection/Php/Factory/PropertyTest.php @@ -17,6 +17,7 @@ use phpDocumentor\Reflection\DocBlockFactoryInterface; use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\Php\Class_ as ClassElement; +use phpDocumentor\Reflection\Php\Expression; use phpDocumentor\Reflection\Php\ProjectFactoryStrategies; use phpDocumentor\Reflection\Php\Property as PropertyDescriptor; use PhpParser\Comment\Doc; @@ -123,8 +124,8 @@ public function testCreateMultipleInOneStatement(): void next($properties); $property2 = current($properties); - $this->assertProperty($property1, 'private', 'property1', '\'MyDefault1\''); - $this->assertProperty($property2, 'private', 'property2', '\'MyDefault2\''); + $this->assertProperty($property1, 'private', 'property1', new Expression("'MyDefault1'")); + $this->assertProperty($property2, 'private', 'property2', new Expression("'MyDefault2'")); } private function buildPropertyMock(int $modifier): PropertyNode @@ -139,7 +140,7 @@ private function assertProperty( PropertyDescriptor $property, string $visibility, string $name = 'property', - string|null $default = '\'MyDefault\'', + Expression|null $default = new Expression("'MyDefault'"), ): void { $this->assertInstanceOf(PropertyDescriptor::class, $property); $this->assertEquals('\myClass::$' . $name, (string) $property->getFqsen()); diff --git a/tests/unit/phpDocumentor/Reflection/Php/PropertyTest.php b/tests/unit/phpDocumentor/Reflection/Php/PropertyTest.php index 6dc29b43..ffc8d3e0 100644 --- a/tests/unit/phpDocumentor/Reflection/Php/PropertyTest.php +++ b/tests/unit/phpDocumentor/Reflection/Php/PropertyTest.php @@ -112,8 +112,7 @@ public function testGetDefault(): void $expression = new Expression('a'); $property = new Property($this->fqsen, $this->visibility, $this->docBlock, $expression, true); - self::assertSame('a', $property->getDefault()); - self::assertSame($expression, $property->getDefault(false)); + self::assertSame($expression, $property->getDefault()); } public function testGetDocBlock(): void