Merge pull request #360 from phpDocumentor/fix/typeless_param

Add typeless parameter support.
This commit is contained in:
Jaap van Otterdijk
2024-03-20 22:15:57 +01:00
committed by GitHub
14 changed files with 355 additions and 255 deletions
+3 -2
View File
@@ -19,7 +19,8 @@
"webmozart/assert": "^1.9.1", "webmozart/assert": "^1.9.1",
"phpdocumentor/reflection-common": "^2.2", "phpdocumentor/reflection-common": "^2.2",
"ext-filter": "*", "ext-filter": "*",
"phpstan/phpdoc-parser": "^1.7" "phpstan/phpdoc-parser": "^1.7",
"doctrine/deprecations": "^1.1"
}, },
"require-dev": { "require-dev": {
"mockery/mockery": "~1.3.5", "mockery/mockery": "~1.3.5",
@@ -28,7 +29,7 @@
"phpstan/phpstan-mockery": "^1.1", "phpstan/phpstan-mockery": "^1.1",
"phpstan/extension-installer": "^1.1", "phpstan/extension-installer": "^1.1",
"phpstan/phpstan-webmozart-assert": "^1.2", "phpstan/phpstan-webmozart-assert": "^1.2",
"vimeo/psalm": "^4.26" "vimeo/psalm": "^5.13"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
Generated
+223 -212
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "e85fae7945bde2c4a84d94d4ca572202", "content-hash": "be391d67a41b2aa6ba500afca03e00a5",
"packages": [ "packages": [
{ {
"name": "doctrine/deprecations", "name": "doctrine/deprecations",
@@ -435,79 +435,6 @@
], ],
"time": "2021-03-30T17:13:30+00:00" "time": "2021-03-30T17:13:30+00:00"
}, },
{
"name": "composer/package-versions-deprecated",
"version": "1.11.99.5",
"source": {
"type": "git",
"url": "https://github.com/composer/package-versions-deprecated.git",
"reference": "b4f54f74ef3453349c24a845d22392cd31e65f1d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/b4f54f74ef3453349c24a845d22392cd31e65f1d",
"reference": "b4f54f74ef3453349c24a845d22392cd31e65f1d",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.1.0 || ^2.0",
"php": "^7 || ^8"
},
"replace": {
"ocramius/package-versions": "1.11.99"
},
"require-dev": {
"composer/composer": "^1.9.3 || ^2.0@dev",
"ext-zip": "^1.13",
"phpunit/phpunit": "^6.5 || ^7"
},
"type": "composer-plugin",
"extra": {
"class": "PackageVersions\\Installer",
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"PackageVersions\\": "src/PackageVersions"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marco Pivetta",
"email": "[email protected]"
},
{
"name": "Jordi Boggiano",
"email": "[email protected]"
}
],
"description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
"support": {
"issues": "https://github.com/composer/package-versions-deprecated/issues",
"source": "https://github.com/composer/package-versions-deprecated/tree/1.11.99.5"
},
"funding": [
{
"url": "https://packagist.com",
"type": "custom"
},
{
"url": "https://github.com/composer",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
"type": "tidelift"
}
],
"time": "2022-01-17T14:14:24+00:00"
},
{ {
"name": "composer/pcre", "name": "composer/pcre",
"version": "3.0.0", "version": "3.0.0",
@@ -934,6 +861,67 @@
}, },
"time": "2022-03-02T22:36:06+00:00" "time": "2022-03-02T22:36:06+00:00"
}, },
{
"name": "fidry/cpu-core-counter",
"version": "0.5.1",
"source": {
"type": "git",
"url": "https://github.com/theofidry/cpu-core-counter.git",
"reference": "b58e5a3933e541dc286cc91fc4f3898bbc6f1623"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/b58e5a3933e541dc286cc91fc4f3898bbc6f1623",
"reference": "b58e5a3933e541dc286cc91fc4f3898bbc6f1623",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
},
"require-dev": {
"fidry/makefile": "^0.2.0",
"phpstan/extension-installer": "^1.2.0",
"phpstan/phpstan": "^1.9.2",
"phpstan/phpstan-deprecation-rules": "^1.0.0",
"phpstan/phpstan-phpunit": "^1.2.2",
"phpstan/phpstan-strict-rules": "^1.4.4",
"phpunit/phpunit": "^9.5.26 || ^8.5.31",
"theofidry/php-cs-fixer-config": "^1.0",
"webmozarts/strict-phpunit": "^7.5"
},
"type": "library",
"autoload": {
"psr-4": {
"Fidry\\CpuCoreCounter\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Théo FIDRY",
"email": "[email protected]"
}
],
"description": "Tiny utility to get the number of CPU cores.",
"keywords": [
"CPU",
"core"
],
"support": {
"issues": "https://github.com/theofidry/cpu-core-counter/issues",
"source": "https://github.com/theofidry/cpu-core-counter/tree/0.5.1"
},
"funding": [
{
"url": "https://github.com/theofidry",
"type": "github"
}
],
"time": "2022-12-24T12:35:10+00:00"
},
{ {
"name": "hamcrest/hamcrest-php", "name": "hamcrest/hamcrest-php",
"version": "v2.0.1", "version": "v2.0.1",
@@ -1220,59 +1208,6 @@
}, },
"time": "2022-05-31T20:59:12+00:00" "time": "2022-05-31T20:59:12+00:00"
}, },
{
"name": "openlss/lib-array2xml",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/nullivex/lib-array2xml.git",
"reference": "a91f18a8dfc69ffabe5f9b068bc39bb202c81d90"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nullivex/lib-array2xml/zipball/a91f18a8dfc69ffabe5f9b068bc39bb202c81d90",
"reference": "a91f18a8dfc69ffabe5f9b068bc39bb202c81d90",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"type": "library",
"autoload": {
"psr-0": {
"LSS": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Bryan Tong",
"email": "[email protected]",
"homepage": "https://www.nullivex.com"
},
{
"name": "Tony Butler",
"email": "[email protected]",
"homepage": "https://www.nullivex.com"
}
],
"description": "Array2XML conversion library credit to lalit.org",
"homepage": "https://www.nullivex.com",
"keywords": [
"array",
"array conversion",
"xml",
"xml conversion"
],
"support": {
"issues": "https://github.com/nullivex/lib-array2xml/issues",
"source": "https://github.com/nullivex/lib-array2xml/tree/master"
},
"time": "2019-03-29T20:06:56+00:00"
},
{ {
"name": "phar-io/manifest", "name": "phar-io/manifest",
"version": "2.0.3", "version": "2.0.3",
@@ -3066,6 +3001,70 @@
], ],
"time": "2020-09-28T06:39:44+00:00" "time": "2020-09-28T06:39:44+00:00"
}, },
{
"name": "spatie/array-to-xml",
"version": "2.17.1",
"source": {
"type": "git",
"url": "https://github.com/spatie/array-to-xml.git",
"reference": "5cbec9c6ab17e320c58a259f0cebe88bde4a7c46"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/array-to-xml/zipball/5cbec9c6ab17e320c58a259f0cebe88bde4a7c46",
"reference": "5cbec9c6ab17e320c58a259f0cebe88bde4a7c46",
"shasum": ""
},
"require": {
"ext-dom": "*",
"php": "^7.4|^8.0"
},
"require-dev": {
"mockery/mockery": "^1.2",
"pestphp/pest": "^1.21",
"phpunit/phpunit": "^9.0",
"spatie/pest-plugin-snapshots": "^1.1"
},
"type": "library",
"autoload": {
"psr-4": {
"Spatie\\ArrayToXml\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van der Herten",
"email": "[email protected]",
"homepage": "https://freek.dev",
"role": "Developer"
}
],
"description": "Convert an array to xml",
"homepage": "https://github.com/spatie/array-to-xml",
"keywords": [
"array",
"convert",
"xml"
],
"support": {
"source": "https://github.com/spatie/array-to-xml/tree/2.17.1"
},
"funding": [
{
"url": "https://spatie.be/open-source/support-us",
"type": "custom"
},
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2022-12-26T08:22:07+00:00"
},
{ {
"name": "symfony/console", "name": "symfony/console",
"version": "v5.4.12", "version": "v5.4.12",
@@ -3232,6 +3231,70 @@
], ],
"time": "2022-01-02T09:53:40+00:00" "time": "2022-01-02T09:53:40+00:00"
}, },
{
"name": "symfony/filesystem",
"version": "v5.4.35",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "5a553607d4ffbfa9c0ab62facadea296c9db7086"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/5a553607d4ffbfa9c0ab62facadea296c9db7086",
"reference": "5a553607d4ffbfa9c0ab62facadea296c9db7086",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.8",
"symfony/polyfill-php80": "^1.16"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Filesystem\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "[email protected]"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides basic utilities for the filesystem",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/filesystem/tree/v5.4.35"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-01-23T13:51:25+00:00"
},
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "v1.26.0", "version": "v1.26.0",
@@ -3945,24 +4008,24 @@
}, },
{ {
"name": "vimeo/psalm", "name": "vimeo/psalm",
"version": "4.26.0", "version": "5.13.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/vimeo/psalm.git", "url": "https://github.com/vimeo/psalm.git",
"reference": "6998fabb2bf528b65777bf9941920888d23c03ac" "reference": "086b94371304750d1c673315321a55d15fc59015"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/vimeo/psalm/zipball/6998fabb2bf528b65777bf9941920888d23c03ac", "url": "https://api.github.com/repos/vimeo/psalm/zipball/086b94371304750d1c673315321a55d15fc59015",
"reference": "6998fabb2bf528b65777bf9941920888d23c03ac", "reference": "086b94371304750d1c673315321a55d15fc59015",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"amphp/amp": "^2.4.2", "amphp/amp": "^2.4.2",
"amphp/byte-stream": "^1.5", "amphp/byte-stream": "^1.5",
"composer/package-versions-deprecated": "^1.8.0", "composer-runtime-api": "^2",
"composer/semver": "^1.4 || ^2.0 || ^3.0", "composer/semver": "^1.4 || ^2.0 || ^3.0",
"composer/xdebug-handler": "^1.1 || ^2.0 || ^3.0", "composer/xdebug-handler": "^2.0 || ^3.0",
"dnoegel/php-xdg-base-dir": "^0.1.1", "dnoegel/php-xdg-base-dir": "^0.1.1",
"ext-ctype": "*", "ext-ctype": "*",
"ext-dom": "*", "ext-dom": "*",
@@ -3971,34 +4034,35 @@
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-simplexml": "*", "ext-simplexml": "*",
"ext-tokenizer": "*", "ext-tokenizer": "*",
"felixfbecker/advanced-json-rpc": "^3.0.3", "felixfbecker/advanced-json-rpc": "^3.1",
"felixfbecker/language-server-protocol": "^1.5", "felixfbecker/language-server-protocol": "^1.5.2",
"fidry/cpu-core-counter": "^0.4.1 || ^0.5.1",
"netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0", "netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0",
"nikic/php-parser": "^4.13", "nikic/php-parser": "^4.14",
"openlss/lib-array2xml": "^1.0", "php": "^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0",
"php": "^7.1|^8", "sebastian/diff": "^4.0 || ^5.0",
"sebastian/diff": "^3.0 || ^4.0", "spatie/array-to-xml": "^2.17.0 || ^3.0",
"symfony/console": "^3.4.17 || ^4.1.6 || ^5.0 || ^6.0", "symfony/console": "^4.1.6 || ^5.0 || ^6.0",
"symfony/polyfill-php80": "^1.25", "symfony/filesystem": "^5.4 || ^6.0"
"webmozart/path-util": "^2.3"
}, },
"provide": { "provide": {
"psalm/psalm": "self.version" "psalm/psalm": "self.version"
}, },
"require-dev": { "require-dev": {
"bamarni/composer-bin-plugin": "^1.2", "amphp/phpunit-util": "^2.0",
"brianium/paratest": "^4.0||^6.0", "bamarni/composer-bin-plugin": "^1.4",
"brianium/paratest": "^6.9",
"ext-curl": "*", "ext-curl": "*",
"mockery/mockery": "^1.5",
"nunomaduro/mock-final-classes": "^1.1",
"php-parallel-lint/php-parallel-lint": "^1.2", "php-parallel-lint/php-parallel-lint": "^1.2",
"phpdocumentor/reflection-docblock": "^5", "phpstan/phpdoc-parser": "^1.6",
"phpmyadmin/sql-parser": "5.1.0||dev-master", "phpunit/phpunit": "^9.6",
"phpspec/prophecy": ">=1.9.0", "psalm/plugin-mockery": "^1.1",
"phpunit/phpunit": "^9.0", "psalm/plugin-phpunit": "^0.18",
"psalm/plugin-phpunit": "^0.16", "slevomat/coding-standard": "^8.4",
"slevomat/coding-standard": "^7.0", "squizlabs/php_codesniffer": "^3.6",
"squizlabs/php_codesniffer": "^3.5", "symfony/process": "^4.4 || ^5.0 || ^6.0"
"symfony/process": "^4.3 || ^5.0 || ^6.0",
"weirdan/prophecy-shim": "^1.0 || ^2.0"
}, },
"suggest": { "suggest": {
"ext-curl": "In order to send data to shepherd", "ext-curl": "In order to send data to shepherd",
@@ -4014,17 +4078,14 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "4.x-dev", "dev-master": "5.x-dev",
"dev-4.x": "4.x-dev",
"dev-3.x": "3.x-dev", "dev-3.x": "3.x-dev",
"dev-2.x": "2.x-dev", "dev-2.x": "2.x-dev",
"dev-1.x": "1.x-dev" "dev-1.x": "1.x-dev"
} }
}, },
"autoload": { "autoload": {
"files": [
"src/functions.php",
"src/spl_object_id.php"
],
"psr-4": { "psr-4": {
"Psalm\\": "src/Psalm/" "Psalm\\": "src/Psalm/"
} }
@@ -4042,64 +4103,14 @@
"keywords": [ "keywords": [
"code", "code",
"inspection", "inspection",
"php" "php",
"static analysis"
], ],
"support": { "support": {
"issues": "https://github.com/vimeo/psalm/issues", "issues": "https://github.com/vimeo/psalm/issues",
"source": "https://github.com/vimeo/psalm/tree/4.26.0" "source": "https://github.com/vimeo/psalm/tree/5.13.1"
}, },
"time": "2022-07-31T13:10:26+00:00" "time": "2023-06-27T16:39:49+00:00"
},
{
"name": "webmozart/path-util",
"version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/webmozart/path-util.git",
"reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webmozart/path-util/zipball/d939f7edc24c9a1bb9c0dee5cb05d8e859490725",
"reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"webmozart/assert": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.6",
"sebastian/version": "^1.0.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
}
},
"autoload": {
"psr-4": {
"Webmozart\\PathUtil\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bernhard Schussek",
"email": "[email protected]"
}
],
"description": "A robust cross-platform utility for normalizing, comparing and modifying file paths.",
"support": {
"issues": "https://github.com/webmozart/path-util/issues",
"source": "https://github.com/webmozart/path-util/tree/2.3.0"
},
"abandoned": "symfony/filesystem",
"time": "2015-12-17T08:42:14+00:00"
} }
], ],
"aliases": [], "aliases": [],
+13
View File
@@ -34,6 +34,19 @@
</errorLevel> </errorLevel>
</DeprecatedInterface> </DeprecatedInterface>
<DeprecatedMethod>
<errorLevel type="info">
<!-- Will be removed in 6.0.0 issues/361 -->
<referencedMethod name="phpDocumentor\Reflection\DocBlock\Tags\Param::create"/>
</errorLevel>
</DeprecatedMethod>
<NoInterfaceProperties>
<errorLevel type="info">
<file name="src/DocBlock/Tags/Factory/ParamFactory.php"/>
</errorLevel>
</NoInterfaceProperties>
<RedundantConditionGivenDocblockType> <RedundantConditionGivenDocblockType>
<errorLevel type="info"> <errorLevel type="info">
<!-- Psalm manage to infer a more precise type than PHPStan. notNull assert is needed for PHPStan but <!-- Psalm manage to infer a more precise type than PHPStan. notNull assert is needed for PHPStan but
+30 -3
View File
@@ -4,15 +4,20 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
use Doctrine\Deprecations\Deprecation;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tags\Param; use phpDocumentor\Reflection\DocBlock\Tags\Param;
use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context; use phpDocumentor\Reflection\Types\Context;
use PHPStan\PhpDocParser\Ast\PhpDoc\InvalidTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
use function sprintf;
use function trim; use function trim;
/** /**
@@ -32,11 +37,31 @@ final class ParamFactory implements PHPStanFactory
public function create(PhpDocTagNode $node, Context $context): Tag public function create(PhpDocTagNode $node, Context $context): Tag
{ {
$tagValue = $node->value; $tagValue = $node->value;
Assert::isInstanceOf($tagValue, ParamTagValueNode::class);
if ($tagValue instanceof InvalidTagValueNode) {
Deprecation::trigger(
'phpdocumentor/reflection-docblock',
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/362',
sprintf(
'Param tag value "%s" is invalid, falling back to legacy parsing. Please update your docblocks.',
$tagValue->value
)
);
return Param::create($tagValue->value, $this->typeResolver, $this->descriptionFactory, $context);
}
Assert::isInstanceOfAny(
$tagValue,
[
ParamTagValueNode::class,
TypelessParamTagValueNode::class,
]
);
return new Param( return new Param(
trim($tagValue->parameterName, '$'), trim($tagValue->parameterName, '$'),
$this->typeResolver->createType($tagValue->type, $context), $this->typeResolver->createType($tagValue->type ?? new IdentifierTypeNode('mixed'), $context),
$tagValue->isVariadic, $tagValue->isVariadic,
$this->descriptionFactory->create($tagValue->description, $context), $this->descriptionFactory->create($tagValue->description, $context),
$tagValue->isReference $tagValue->isReference
@@ -45,6 +70,8 @@ final class ParamFactory implements PHPStanFactory
public function supports(PhpDocTagNode $node, Context $context): bool public function supports(PhpDocTagNode $node, Context $context): bool
{ {
return $node->value instanceof ParamTagValueNode; return $node->value instanceof ParamTagValueNode
|| $node->value instanceof TypelessParamTagValueNode
|| $node->name === '@param';
} }
} }
+5 -4
View File
@@ -13,6 +13,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags; namespace phpDocumentor\Reflection\DocBlock\Tags;
use Doctrine\Deprecations\Deprecation;
use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Type;
@@ -26,9 +27,7 @@ use function array_unshift;
use function implode; use function implode;
use function strpos; use function strpos;
use function substr; use function substr;
use function trigger_error;
use const E_USER_DEPRECATED;
use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_DELIM_CAPTURE;
/** /**
@@ -69,11 +68,13 @@ final class Param extends TagWithType implements Factory\StaticMethod
?DescriptionFactory $descriptionFactory = null, ?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null ?TypeContext $context = null
): self { ): self {
trigger_error( Deprecation::triggerIfCalledFromOutside(
'phpdocumentor/reflection-docblock',
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
'Create using static factory is deprecated, this method should not be called directly 'Create using static factory is deprecated, this method should not be called directly
by library consumers', by library consumers',
E_USER_DEPRECATED
); );
Assert::stringNotEmpty($body); Assert::stringNotEmpty($body);
Assert::notNull($typeResolver); Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory); Assert::notNull($descriptionFactory);
+5 -4
View File
@@ -13,6 +13,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags; namespace phpDocumentor\Reflection\DocBlock\Tags;
use Doctrine\Deprecations\Deprecation;
use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Type;
@@ -26,9 +27,7 @@ use function array_unshift;
use function implode; use function implode;
use function strpos; use function strpos;
use function substr; use function substr;
use function trigger_error;
use const E_USER_DEPRECATED;
use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_DELIM_CAPTURE;
/** /**
@@ -58,11 +57,13 @@ final class Property extends TagWithType implements Factory\StaticMethod
?DescriptionFactory $descriptionFactory = null, ?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null ?TypeContext $context = null
): self { ): self {
trigger_error( Deprecation::triggerIfCalledFromOutside(
'phpdocumentor/reflection-docblock',
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
'Create using static factory is deprecated, this method should not be called directly 'Create using static factory is deprecated, this method should not be called directly
by library consumers', by library consumers',
E_USER_DEPRECATED
); );
Assert::stringNotEmpty($body); Assert::stringNotEmpty($body);
Assert::notNull($typeResolver); Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory); Assert::notNull($descriptionFactory);
+5 -4
View File
@@ -13,6 +13,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags; namespace phpDocumentor\Reflection\DocBlock\Tags;
use Doctrine\Deprecations\Deprecation;
use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Type;
@@ -26,9 +27,7 @@ use function array_unshift;
use function implode; use function implode;
use function strpos; use function strpos;
use function substr; use function substr;
use function trigger_error;
use const E_USER_DEPRECATED;
use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_DELIM_CAPTURE;
/** /**
@@ -58,11 +57,13 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
?DescriptionFactory $descriptionFactory = null, ?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null ?TypeContext $context = null
): self { ): self {
trigger_error( Deprecation::triggerIfCalledFromOutside(
'phpdocumentor/reflection-docblock',
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
'Create using static factory is deprecated, this method should not be called directly 'Create using static factory is deprecated, this method should not be called directly
by library consumers', by library consumers',
E_USER_DEPRECATED
); );
Assert::stringNotEmpty($body); Assert::stringNotEmpty($body);
Assert::notNull($typeResolver); Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory); Assert::notNull($descriptionFactory);
+5 -4
View File
@@ -13,6 +13,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags; namespace phpDocumentor\Reflection\DocBlock\Tags;
use Doctrine\Deprecations\Deprecation;
use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Type;
@@ -26,9 +27,7 @@ use function array_unshift;
use function implode; use function implode;
use function strpos; use function strpos;
use function substr; use function substr;
use function trigger_error;
use const E_USER_DEPRECATED;
use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_DELIM_CAPTURE;
/** /**
@@ -58,11 +57,13 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
?DescriptionFactory $descriptionFactory = null, ?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null ?TypeContext $context = null
): self { ): self {
trigger_error( Deprecation::triggerIfCalledFromOutside(
'phpdocumentor/reflection-docblock',
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
'Create using static factory is deprecated, this method should not be called directly 'Create using static factory is deprecated, this method should not be called directly
by library consumers', by library consumers',
E_USER_DEPRECATED
); );
Assert::stringNotEmpty($body); Assert::stringNotEmpty($body);
Assert::notNull($typeResolver); Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory); Assert::notNull($descriptionFactory);
+5 -6
View File
@@ -13,6 +13,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags; namespace phpDocumentor\Reflection\DocBlock\Tags;
use Doctrine\Deprecations\Deprecation;
use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Type;
@@ -20,10 +21,6 @@ use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext; use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
use function trigger_error;
use const E_USER_DEPRECATED;
/** /**
* Reflection class for a {@}return tag in a Docblock. * Reflection class for a {@}return tag in a Docblock.
*/ */
@@ -46,11 +43,13 @@ final class Return_ extends TagWithType implements Factory\StaticMethod
?DescriptionFactory $descriptionFactory = null, ?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null ?TypeContext $context = null
): self { ): self {
trigger_error( Deprecation::triggerIfCalledFromOutside(
'phpdocumentor/reflection-docblock',
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
'Create using static factory is deprecated, this method should not be called directly 'Create using static factory is deprecated, this method should not be called directly
by library consumers', by library consumers',
E_USER_DEPRECATED
); );
Assert::notNull($typeResolver); Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory); Assert::notNull($descriptionFactory);
+4 -4
View File
@@ -13,6 +13,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags; namespace phpDocumentor\Reflection\DocBlock\Tags;
use Doctrine\Deprecations\Deprecation;
use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\Type; use phpDocumentor\Reflection\Type;
@@ -26,9 +27,7 @@ use function array_unshift;
use function implode; use function implode;
use function strpos; use function strpos;
use function substr; use function substr;
use function trigger_error;
use const E_USER_DEPRECATED;
use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_DELIM_CAPTURE;
/** /**
@@ -58,10 +57,11 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
?DescriptionFactory $descriptionFactory = null, ?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null ?TypeContext $context = null
): self { ): self {
trigger_error( Deprecation::triggerIfCalledFromOutside(
'phpdocumentor/reflection-docblock',
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
'Create using static factory is deprecated, this method should not be called directly 'Create using static factory is deprecated, this method should not be called directly
by library consumers', by library consumers',
E_USER_DEPRECATED
); );
Assert::stringNotEmpty($body); Assert::stringNotEmpty($body);
Assert::notNull($typeResolver); Assert::notNull($typeResolver);
@@ -217,6 +217,5 @@ DOC;
], ],
$docblock->getTags() $docblock->getTags()
); );
} }
} }
@@ -16,6 +16,8 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\Tags\Param; use phpDocumentor\Reflection\DocBlock\Tags\Param;
use phpDocumentor\Reflection\Types\Context; use phpDocumentor\Reflection\Types\Context;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\Mixed_;
use phpDocumentor\Reflection\Types\String_; use phpDocumentor\Reflection\Types\String_;
final class ParamFactoryTest extends TagFactoryTestCase final class ParamFactoryTest extends TagFactoryTestCase
@@ -24,23 +26,67 @@ final class ParamFactoryTest extends TagFactoryTestCase
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::__construct
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::create * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::create
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::supports * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::supports
* @dataProvider paramInputProvider
*/ */
public function testParamIsCreated(): void public function testParamIsCreated(string $input, Param $expected): void
{ {
$ast = $this->parseTag('@param string $var'); $ast = $this->parseTag($input);
$factory = new ParamFactory($this->giveTypeResolver(), $this->givenDescriptionFactory()); $factory = new ParamFactory($this->giveTypeResolver(), $this->givenDescriptionFactory());
$context = new Context('global'); $context = new Context('global');
self::assertTrue($factory->supports($ast, $context)); self::assertTrue($factory->supports($ast, $context));
self::assertEquals( self::assertEquals(
new Param( $expected,
'var',
new String_(),
false,
new Description(''),
false
),
$factory->create($ast, $context) $factory->create($ast, $context)
); );
} }
/**
* @return array<array-key, string|Param>
*/
public function paramInputProvider(): array
{
return [
[
'@param string $var',
new Param(
'var',
new String_(),
false,
new Description(''),
false
),
],
[
'@param $param8 Description 4',
new Param(
'param8',
new Mixed_(),
false,
new Description('Description 4'),
false
),
],
[
'@param $param9',
new Param(
'param9',
new Mixed_(),
false,
new Description(''),
false
),
],
[
'@param int My Description',
new Param(
null,
new Integer(),
false,
new Description('My Description'),
false
),
],
];
}
} }
@@ -45,7 +45,7 @@ abstract class TagFactoryTestCase extends TestCase
public function givenDescriptionFactory(): DescriptionFactory public function givenDescriptionFactory(): DescriptionFactory
{ {
$factory = m::mock(DescriptionFactory::class); $factory = m::mock(DescriptionFactory::class);
$factory->shouldReceive('create')->andReturn(new Description('')); $factory->shouldReceive('create')->andReturnUsing(static fn ($args) => new Description($args));
return $factory; return $factory;
} }
@@ -25,7 +25,7 @@ final class VarFactoryTest extends TagFactoryTestCase
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory::create * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory::create
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory::supports * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory::supports
*/ */
public function testParamIsCreated(): void public function testVarIsCreated(): void
{ {
$ast = $this->parseTag('@var string $var'); $ast = $this->parseTag('@var string $var');
$factory = new VarFactory($this->giveTypeResolver(), $this->givenDescriptionFactory()); $factory = new VarFactory($this->giveTypeResolver(), $this->givenDescriptionFactory());