diff options
| author | fox <fox@fakecake.org> | 2026-05-26 06:45:47 +0300 |
|---|---|---|
| committer | fox <fox@fakecake.org> | 2026-05-26 06:45:47 +0300 |
| commit | 4ce7212e8c26cd613db0cfc75ef8a5a0ba6eb7be (patch) | |
| tree | 0ec2e37f6f86d59a904a2f1de2a15294ef1ae349 /vendor/phpdocumentor | |
| parent | cae514dddfc59f533a93a47afc283371d5949843 (diff) | |
| parent | dc60880d9cc4074a231fd21c9508d0f78beaf1f1 (diff) | |
| download | the-epube-4ce7212e8c26cd613db0cfc75ef8a5a0ba6eb7be.tar.gz the-epube-4ce7212e8c26cd613db0cfc75ef8a5a0ba6eb7be.tar.xz | |
Merge branch 'dev' into 'master'
Dev See merge request git/the-epube!39
Diffstat (limited to 'vendor/phpdocumentor')
177 files changed, 11463 insertions, 0 deletions
diff --git a/vendor/phpdocumentor/reflection-common/.github/dependabot.yml b/vendor/phpdocumentor/reflection-common/.github/dependabot.yml new file mode 100644 index 0000000..c630ffa --- /dev/null +++ b/vendor/phpdocumentor/reflection-common/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: +- package-ecosystem: composer + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 diff --git a/vendor/phpdocumentor/reflection-common/.github/workflows/push.yml b/vendor/phpdocumentor/reflection-common/.github/workflows/push.yml new file mode 100644 index 0000000..484410e --- /dev/null +++ b/vendor/phpdocumentor/reflection-common/.github/workflows/push.yml @@ -0,0 +1,223 @@ +on: + push: + branches: + - 2.x + pull_request: +name: Qa workflow +jobs: + setup: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Restore/cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: all-build-${{ hashFiles('**/composer.lock') }} + restore-keys: | + all-build-${{ hashFiles('**/composer.lock') }} + all-build- + + - name: Restore/cache tools folder + uses: actions/cache@v1 + with: + path: tools + key: all-tools-${{ github.sha }} + restore-keys: | + all-tools-${{ github.sha }}- + all-tools- + + - name: composer + uses: docker://composer + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: install --no-interaction --prefer-dist --optimize-autoloader + + - name: Install phive + run: make install-phive + + - name: Install PHAR dependencies + run: tools/phive.phar --no-progress install --copy --trust-gpg-keys 4AA394086372C20A,8A03EA3B385DBAA1 --force-accept-unsigned + + phpunit-with-coverage: + runs-on: ubuntu-latest + name: Unit tests + needs: setup + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 7.2 + ini-values: memory_limit=2G, display_errors=On, error_reporting=-1 + coverage: pcov + + - name: Restore/cache tools folder + uses: actions/cache@v1 + with: + path: tools + key: all-tools-${{ github.sha }} + restore-keys: | + all-tools-${{ github.sha }}- + all-tools- + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache composer dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ubuntu-latest-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ubuntu-latest-composer- + + - name: Install Composer dependencies + run: | + composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + + - name: Run PHPUnit + run: php tools/phpunit + + phpunit: + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: + - ubuntu-latest + - windows-latest + - macOS-latest + php-versions: ['7.2', '7.3', '7.4', '8.0'] + name: Unit tests for PHP version ${{ matrix.php-versions }} on ${{ matrix.operating-system }} + needs: + - setup + - phpunit-with-coverage + steps: + - uses: actions/checkout@v2 + + - name: Restore/cache tools folder + uses: actions/cache@v1 + with: + path: tools + key: all-tools-${{ github.sha }} + restore-keys: | + all-tools-${{ github.sha }}- + all-tools- + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + ini-values: memory_limit=2G, display_errors=On, error_reporting=-1 + coverage: none + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache composer dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install Composer dependencies + run: | + composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + + - name: Run PHPUnit + continue-on-error: true + run: php tools/phpunit + + codestyle: + runs-on: ubuntu-latest + needs: [setup, phpunit] + steps: + - uses: actions/checkout@v2 + - name: Restore/cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: all-build-${{ hashFiles('**/composer.lock') }} + restore-keys: | + all-build-${{ hashFiles('**/composer.lock') }} + all-build- + - name: Code style check + uses: phpDocumentor/coding-standard@latest + with: + args: -s + + phpstan: + runs-on: ubuntu-latest + needs: [setup, phpunit] + steps: + - uses: actions/checkout@v2 + - name: Restore/cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: all-build-${{ hashFiles('**/composer.lock') }} + restore-keys: | + all-build-${{ hashFiles('**/composer.lock') }} + all-build- + - name: PHPStan + uses: phpDocumentor/phpstan-ga@latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: analyse src --configuration phpstan.neon + + psalm: + runs-on: ubuntu-latest + needs: [setup, phpunit] + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 7.2 + ini-values: memory_limit=2G, display_errors=On, error_reporting=-1 + tools: psalm + coverage: none + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache composer dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install Composer dependencies + run: | + composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + + - name: Psalm + run: psalm --output-format=github + + bc_check: + name: BC Check + runs-on: ubuntu-latest + needs: [setup, phpunit] + steps: + - uses: actions/checkout@v2 + - name: fetch tags + run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* + - name: Restore/cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: all-build-${{ hashFiles('**/composer.lock') }} + restore-keys: | + all-build-${{ hashFiles('**/composer.lock') }} + all-build- + - name: Roave BC Check + uses: docker://nyholm/roave-bc-check-ga diff --git a/vendor/phpdocumentor/reflection-common/LICENSE b/vendor/phpdocumentor/reflection-common/LICENSE new file mode 100644 index 0000000..ed6926c --- /dev/null +++ b/vendor/phpdocumentor/reflection-common/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 phpDocumentor + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/vendor/phpdocumentor/reflection-common/README.md b/vendor/phpdocumentor/reflection-common/README.md new file mode 100644 index 0000000..70f830d --- /dev/null +++ b/vendor/phpdocumentor/reflection-common/README.md @@ -0,0 +1,11 @@ +[](https://opensource.org/licenses/MIT) + +[](https://coveralls.io/github/phpDocumentor/ReflectionCommon?branch=master) +[](https://scrutinizer-ci.com/g/phpDocumentor/ReflectionCommon/?branch=master) +[](https://scrutinizer-ci.com/g/phpDocumentor/ReflectionCommon/?branch=master) +[](https://packagist.org/packages/phpDocumentor/Reflection-Common) +[](https://packagist.org/packages/phpDocumentor/Reflection-Common) + + +ReflectionCommon +================ diff --git a/vendor/phpdocumentor/reflection-common/composer.json b/vendor/phpdocumentor/reflection-common/composer.json new file mode 100644 index 0000000..4d128b4 --- /dev/null +++ b/vendor/phpdocumentor/reflection-common/composer.json @@ -0,0 +1,28 @@ +{ + "name": "phpdocumentor/reflection-common", + "keywords": ["phpdoc", "phpDocumentor", "reflection", "static analysis", "FQSEN"], + "homepage": "http://www.phpdoc.org", + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "license": "MIT", + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "require": { + "php": "^7.2 || ^8.0" + }, + "autoload" : { + "psr-4" : { + "phpDocumentor\\Reflection\\": "src/" + } + }, + "require-dev": { + }, + "extra": { + "branch-alias": { + "dev-2.x": "2.x-dev" + } + } +} diff --git a/vendor/phpdocumentor/reflection-common/src/Element.php b/vendor/phpdocumentor/reflection-common/src/Element.php new file mode 100644 index 0000000..8923e4f --- /dev/null +++ b/vendor/phpdocumentor/reflection-common/src/Element.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +/** + * phpDocumentor + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +/** + * Interface for Api Elements + */ +interface Element +{ + /** + * Returns the Fqsen of the element. + */ + public function getFqsen() : Fqsen; + + /** + * Returns the name of the element. + */ + public function getName() : string; +} diff --git a/vendor/phpdocumentor/reflection-common/src/File.php b/vendor/phpdocumentor/reflection-common/src/File.php new file mode 100644 index 0000000..239c137 --- /dev/null +++ b/vendor/phpdocumentor/reflection-common/src/File.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +/** + * Interface for files processed by the ProjectFactory + */ +interface File +{ + /** + * Returns the content of the file as a string. + */ + public function getContents() : string; + + /** + * Returns md5 hash of the file. + */ + public function md5() : string; + + /** + * Returns an relative path to the file. + */ + public function path() : string; +} diff --git a/vendor/phpdocumentor/reflection-common/src/Fqsen.php b/vendor/phpdocumentor/reflection-common/src/Fqsen.php new file mode 100644 index 0000000..8fc5d34 --- /dev/null +++ b/vendor/phpdocumentor/reflection-common/src/Fqsen.php @@ -0,0 +1,89 @@ +<?php + +declare(strict_types=1); + +/** + * phpDocumentor + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +use InvalidArgumentException; +use function assert; +use function end; +use function explode; +use function is_string; +use function preg_match; +use function sprintf; +use function trim; + +/** + * Value Object for Fqsen. + * + * @link https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc-meta.md + * + * @psalm-immutable + */ +final class Fqsen +{ + /** @var string full quallified class name */ + private $fqsen; + + /** @var string name of the element without path. */ + private $name; + + /** + * Initializes the object. + * + * @throws InvalidArgumentException when $fqsen is not matching the format. + */ + public function __construct(string $fqsen) + { + $matches = []; + + $result = preg_match( + //phpcs:ignore Generic.Files.LineLength.TooLong + '/^\\\\([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\\\]*)?(?:[:]{2}\\$?([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*))?(?:\\(\\))?$/', + $fqsen, + $matches + ); + + if ($result === 0) { + throw new InvalidArgumentException( + sprintf('"%s" is not a valid Fqsen.', $fqsen) + ); + } + + $this->fqsen = $fqsen; + + if (isset($matches[2])) { + $this->name = $matches[2]; + } else { + $matches = explode('\\', $fqsen); + $name = end($matches); + assert(is_string($name)); + $this->name = trim($name, '()'); + } + } + + /** + * converts this class to string. + */ + public function __toString() : string + { + return $this->fqsen; + } + + /** + * Returns the name of the element without path. + */ + public function getName() : string + { + return $this->name; + } +} diff --git a/vendor/phpdocumentor/reflection-common/src/Location.php b/vendor/phpdocumentor/reflection-common/src/Location.php new file mode 100644 index 0000000..177deed --- /dev/null +++ b/vendor/phpdocumentor/reflection-common/src/Location.php @@ -0,0 +1,53 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +/** + * The location where an element occurs within a file. + * + * @psalm-immutable + */ +final class Location +{ + /** @var int */ + private $lineNumber = 0; + + /** @var int */ + private $columnNumber = 0; + + /** + * Initializes the location for an element using its line number in the file and optionally the column number. + */ + public function __construct(int $lineNumber, int $columnNumber = 0) + { + $this->lineNumber = $lineNumber; + $this->columnNumber = $columnNumber; + } + + /** + * Returns the line number that is covered by this location. + */ + public function getLineNumber() : int + { + return $this->lineNumber; + } + + /** + * Returns the column number (character position on a line) for this location object. + */ + public function getColumnNumber() : int + { + return $this->columnNumber; + } +} diff --git a/vendor/phpdocumentor/reflection-common/src/Project.php b/vendor/phpdocumentor/reflection-common/src/Project.php new file mode 100644 index 0000000..57839fd --- /dev/null +++ b/vendor/phpdocumentor/reflection-common/src/Project.php @@ -0,0 +1,25 @@ +<?php + +declare(strict_types=1); + +/** + * phpDocumentor + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +/** + * Interface for project. Since the definition of a project can be different per factory this interface will be small. + */ +interface Project +{ + /** + * Returns the name of the project. + */ + public function getName() : string; +} diff --git a/vendor/phpdocumentor/reflection-common/src/ProjectFactory.php b/vendor/phpdocumentor/reflection-common/src/ProjectFactory.php new file mode 100644 index 0000000..8bdc606 --- /dev/null +++ b/vendor/phpdocumentor/reflection-common/src/ProjectFactory.php @@ -0,0 +1,28 @@ +<?php + +declare(strict_types=1); + +/** + * phpDocumentor + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +/** + * Interface for project factories. A project factory shall convert a set of files + * into an object implementing the Project interface. + */ +interface ProjectFactory +{ + /** + * Creates a project from the set of files. + * + * @param File[] $files + */ + public function create(string $name, array $files) : Project; +} diff --git a/vendor/phpdocumentor/reflection-docblock/LICENSE b/vendor/phpdocumentor/reflection-docblock/LICENSE new file mode 100644 index 0000000..792e404 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2010 Mike van Riel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/phpdocumentor/reflection-docblock/README.md b/vendor/phpdocumentor/reflection-docblock/README.md new file mode 100644 index 0000000..9754ba6 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/README.md @@ -0,0 +1,74 @@ +[](https://opensource.org/licenses/MIT) +[](https://github.com/phpDocumentor/ReflectionDocBlock/actions/workflows/integrate.yaml) +[](https://scrutinizer-ci.com/g/phpDocumentor/ReflectionDocBlock/?branch=master) +[](https://scrutinizer-ci.com/g/phpDocumentor/ReflectionDocBlock/?branch=master) +[](https://packagist.org/packages/phpdocumentor/reflection-docblock) +[](https://packagist.org/packages/phpdocumentor/reflection-docblock) + +ReflectionDocBlock +================== + +Introduction +------------ + +The ReflectionDocBlock component of phpDocumentor provides a DocBlock parser +that is 100% compatible with the [PHPDoc standard](http://phpdoc.org/docs/latest). + +With this component, a library can provide support for annotations via DocBlocks +or otherwise retrieve information that is embedded in a DocBlock. + +Installation +------------ + +```bash +composer require phpdocumentor/reflection-docblock +``` + +Usage +----- + +In order to parse the DocBlock one needs a DocBlockFactory that can be +instantiated using its `createInstance` factory method like this: + +```php +$factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); +``` + +Then we can use the `create` method of the factory to interpret the DocBlock. +Please note that it is also possible to provide a class that has the +`getDocComment()` method, such as an object of type `ReflectionClass`, the +create method will read that if it exists. + +```php +$docComment = <<<DOCCOMMENT +/** + * This is an example of a summary. + * + * This is a Description. A Summary and Description are separated by either + * two subsequent newlines (thus a whiteline in between as can be seen in this + * example), or when the Summary ends with a dot (`.`) and some form of + * whitespace. + */ +DOCCOMMENT; + +$docblock = $factory->create($docComment); +``` + +The `create` method will yield an object of type `\phpDocumentor\Reflection\DocBlock` +whose methods can be queried: + +```php +// Contains the summary for this DocBlock +$summary = $docblock->getSummary(); + +// Contains \phpDocumentor\Reflection\DocBlock\Description object +$description = $docblock->getDescription(); + +// You can either cast it to string +$description = (string) $docblock->getDescription(); + +// Or use the render method to get a string representation of the Description. +$description = $docblock->getDescription()->render(); +``` + +> For more examples it would be best to review the scripts in the [`/docs/examples` folder](/docs/examples). diff --git a/vendor/phpdocumentor/reflection-docblock/composer.json b/vendor/phpdocumentor/reflection-docblock/composer.json new file mode 100644 index 0000000..28edc60 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/composer.json @@ -0,0 +1,58 @@ +{ + "name": "phpdocumentor/reflection-docblock", + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + }, + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "require": { + "php": "^7.4 || ^8.0", + "phpdocumentor/type-resolver": "^2.0", + "webmozart/assert": "^1.9.1 || ^2", + "phpdocumentor/reflection-common": "^2.2", + "ext-filter": "*", + "phpstan/phpdoc-parser": "^2.0", + "doctrine/deprecations": "^1.1" + }, + "require-dev": { + "mockery/mockery": "~1.3.5 || ~1.6.0", + "phpunit/phpunit": "^9.5", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-mockery": "^1.1", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan-webmozart-assert": "^1.2", + "psalm/phar": "^5.26", + "shipmonk/dead-code-detector": "^0.5.1" + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "phpDocumentor\\Reflection\\": ["tests/unit", "tests/integration"] + } + }, + "config": { + "platform": { + "php":"7.4.0" + }, + "allow-plugins": { + "phpstan/extension-installer": true + } + }, + "extra": { + "branch-alias": { + "dev-master": "5.x-dev" + } + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock.php new file mode 100644 index 0000000..90d8066 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock.php @@ -0,0 +1,228 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\TagWithType; +use Webmozart\Assert\Assert; + +final class DocBlock +{ + /** @var string The opening line for this docblock. */ + private string $summary; + + /** @var DocBlock\Description The actual description for this docblock. */ + private DocBlock\Description $description; + + /** @var Tag[] An array containing all the tags in this docblock; except inline. */ + private array $tags = []; + + /** @var Types\Context|null Information about the context of this DocBlock. */ + private ?Types\Context $context = null; + + /** @var Location|null Information about the location of this DocBlock. */ + private ?Location $location = null; + + /** @var bool Is this DocBlock (the start of) a template? */ + private bool $isTemplateStart; + + /** @var bool Does this DocBlock signify the end of a DocBlock template? */ + private bool $isTemplateEnd; + + /** + * @param DocBlock\Tag[] $tags + * @param Types\Context $context The context in which the DocBlock occurs. + * @param Location $location The location within the file that this DocBlock occurs in. + */ + public function __construct( + string $summary = '', + ?DocBlock\Description $description = null, + array $tags = [], + ?Types\Context $context = null, + ?Location $location = null, + bool $isTemplateStart = false, + bool $isTemplateEnd = false + ) { + Assert::allIsInstanceOf($tags, Tag::class); + + $this->summary = $summary; + $this->description = $description ?: new DocBlock\Description(''); + foreach ($tags as $tag) { + $this->addTag($tag); + } + + $this->context = $context; + $this->location = $location; + + $this->isTemplateEnd = $isTemplateEnd; + $this->isTemplateStart = $isTemplateStart; + } + + public function getSummary(): string + { + return $this->summary; + } + + public function getDescription(): DocBlock\Description + { + return $this->description; + } + + /** + * Returns the current context. + */ + public function getContext(): ?Types\Context + { + return $this->context; + } + + /** + * Returns the current location. + */ + public function getLocation(): ?Location + { + return $this->location; + } + + /** + * Returns whether this DocBlock is the start of a Template section. + * + * A Docblock may serve as template for a series of subsequent DocBlocks. This is indicated by a special marker + * (`#@+`) that is appended directly after the opening `/**` of a DocBlock. + * + * An example of such an opening is: + * + * ``` + * /**#@+ + * * My DocBlock + * * / + * ``` + * + * The description and tags (not the summary!) are copied onto all subsequent DocBlocks and also applied to all + * elements that follow until another DocBlock is found that contains the closing marker (`#@-`). + * + * @see self::isTemplateEnd() for the check whether a closing marker was provided. + */ + public function isTemplateStart(): bool + { + return $this->isTemplateStart; + } + + /** + * Returns whether this DocBlock is the end of a Template section. + * + * @see self::isTemplateStart() for a more complete description of the Docblock Template functionality. + */ + public function isTemplateEnd(): bool + { + return $this->isTemplateEnd; + } + + /** + * Returns the tags for this DocBlock. + * + * @return Tag[] + */ + public function getTags(): array + { + return $this->tags; + } + + /** + * Returns an array of tags matching the given name. If no tags are found + * an empty array is returned. + * + * @param string $name String to search by. + * + * @return Tag[] + */ + public function getTagsByName(string $name): array + { + $result = []; + + foreach ($this->getTags() as $tag) { + if ($tag->getName() !== $name) { + continue; + } + + $result[] = $tag; + } + + return $result; + } + + /** + * Returns an array of tags with type matching the given name. If no tags are found + * an empty array is returned. + * + * @param string $name String to search by. + * + * @return TagWithType[] + */ + public function getTagsWithTypeByName(string $name): array + { + $result = []; + + foreach ($this->getTagsByName($name) as $tag) { + if (!$tag instanceof TagWithType) { + continue; + } + + $result[] = $tag; + } + + return $result; + } + + /** + * Checks if a tag of a certain type is present in this DocBlock. + * + * @param string $name Tag name to check for. + */ + public function hasTag(string $name): bool + { + foreach ($this->getTags() as $tag) { + if ($tag->getName() === $name) { + return true; + } + } + + return false; + } + + /** + * Remove a tag from this DocBlock. + * + * @param Tag $tagToRemove The tag to remove. + */ + public function removeTag(Tag $tagToRemove): void + { + foreach ($this->tags as $key => $tag) { + if ($tag === $tagToRemove) { + unset($this->tags[$key]); + break; + } + } + } + + /** + * Adds a tag to this DocBlock. + * + * @param Tag $tag The tag to add. + */ + private function addTag(Tag $tag): void + { + $this->tags[] = $tag; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Description.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Description.php new file mode 100644 index 0000000..a188ae3 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Description.php @@ -0,0 +1,118 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock; + +use phpDocumentor\Reflection\DocBlock\Tags\Formatter; +use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter; + +use function vsprintf; + +/** + * Object representing to description for a DocBlock. + * + * A Description object can consist of plain text but can also include tags. A Description Formatter can then combine + * a body template with sprintf-style placeholders together with formatted tags in order to reconstitute a complete + * description text using the format that you would prefer. + * + * Because parsing a Description text can be a verbose process this is handled by the {@see DescriptionFactory}. It is + * thus recommended to use that to create a Description object, like this: + * + * $description = $descriptionFactory->create('This is a {@see Description}', $context); + * + * The description factory will interpret the given body and create a body template and list of tags from them, and pass + * that onto the constructor if this class. + * + * > The $context variable is a class of type {@see \phpDocumentor\Reflection\Types\Context} and contains the namespace + * > and the namespace aliases that apply to this DocBlock. These are used by the Factory to resolve and expand partial + * > type names and FQSENs. + * + * If you do not want to use the DescriptionFactory you can pass a body template and tag listing like this: + * + * $description = new Description( + * 'This is a %1$s', + * [ new See(new Fqsen('\phpDocumentor\Reflection\DocBlock\Description')) ] + * ); + * + * It is generally recommended to use the Factory as that will also apply escaping rules, while the Description object + * is mainly responsible for rendering. + * + * @see DescriptionFactory to create a new Description. + * @see Tags\Formatter for the formatting of the body and tags. + */ +class Description +{ + private string $bodyTemplate; + + /** @var Tag[] */ + private array $tags; + + /** + * Initializes a Description with its body (template) and a listing of the tags used in the body template. + * + * @param Tag[] $tags + */ + public function __construct(string $bodyTemplate, array $tags = []) + { + $this->bodyTemplate = $bodyTemplate; + $this->tags = $tags; + } + + /** + * Returns the body template. + */ + public function getBodyTemplate(): string + { + return $this->bodyTemplate; + } + + /** + * Returns the tags for this DocBlock. + * + * @return Tag[] + */ + public function getTags(): array + { + return $this->tags; + } + + /** + * Renders this description as a string where the provided formatter will format the tags in the expected string + * format. + */ + public function render(?Formatter $formatter = null): string + { + if ($this->tags === []) { + return vsprintf($this->bodyTemplate, []); + } + + if ($formatter === null) { + $formatter = new PassthroughFormatter(); + } + + $tags = []; + foreach ($this->tags as $tag) { + $tags[] = '{' . $formatter->format($tag) . '}'; + } + + return vsprintf($this->bodyTemplate, $tags); + } + + /** + * Returns a plain string representation of this description. + */ + public function __toString(): string + { + return $this->render(); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/DescriptionFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/DescriptionFactory.php new file mode 100644 index 0000000..6915c16 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/DescriptionFactory.php @@ -0,0 +1,179 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock; + +use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory; +use phpDocumentor\Reflection\Types\Context as TypeContext; +use phpDocumentor\Reflection\Utils; + +use function count; +use function implode; +use function ltrim; +use function min; +use function str_replace; +use function strlen; +use function strpos; +use function substr; +use function trim; + +use const PREG_SPLIT_DELIM_CAPTURE; + +/** + * Creates a new Description object given a body of text. + * + * Descriptions in phpDocumentor are somewhat complex entities as they can contain one or more tags inside their + * body that can be replaced with a readable output. The replacing is done by passing a Formatter object to the + * Description object's `render` method. + * + * In addition to the above does a Description support two types of escape sequences: + * + * 1. `{@}` to escape the `@` character to prevent it from being interpreted as part of a tag, i.e. `{{@}link}` + * 2. `{}` to escape the `}` character, this can be used if you want to use the `}` character in the description + * of an inline tag. + * + * If a body consists of multiple lines then this factory will also remove any superfluous whitespace at the beginning + * of each line while maintaining any indentation that is used. This will prevent formatting parsers from tripping + * over unexpected spaces as can be observed with tag descriptions. + */ +class DescriptionFactory +{ + private Factory $tagFactory; + + /** + * Initializes this factory with the means to construct (inline) tags. + */ + public function __construct(Factory $tagFactory) + { + $this->tagFactory = $tagFactory; + } + + /** + * Returns the parsed text of this description. + */ + public function create(string $contents, ?TypeContext $context = null): Description + { + $tokens = $this->lex($contents); + $count = count($tokens); + $tagCount = 0; + $tags = []; + + for ($i = 1; $i < $count; $i += 2) { + $tags[] = $this->tagFactory->create($tokens[$i], $context); + $tokens[$i] = '%' . ++$tagCount . '$s'; + } + + //In order to allow "literal" inline tags, the otherwise invalid + //sequence "{@}" is changed to "@", and "{}" is changed to "}". + //"%" is escaped to "%%" because of vsprintf. + //See unit tests for examples. + for ($i = 0; $i < $count; $i += 2) { + $tokens[$i] = str_replace(['{@}', '{}', '%'], ['@', '}', '%%'], $tokens[$i]); + } + + return new Description(implode('', $tokens), $tags); + } + + /** + * Strips the contents from superfluous whitespace and splits the description into a series of tokens. + * + * @return string[] A series of tokens of which the description text is composed. + */ + private function lex(string $contents): array + { + $contents = $this->removeSuperfluousStartingWhitespace($contents); + + // performance optimalization; if there is no inline tag, don't bother splitting it up. + if (strpos($contents, '{@') === false) { + return [$contents]; + } + + return Utils::pregSplit( + '/\{ + # "{@}" and "{@*}" are not a valid inline tags. This ensures that we do not treat them as one, but treat + # them literally. + (?!(?:@\}|@\*\}) ) + # We want to capture the whole tag line, but without the inline tag delimiters. + (\@ + # Match everything up to the next delimiter. + [^{}]* + # Nested inline tag content should not be captured, or it will appear in the result separately. + (?: + # Match nested inline tags. + (?: + # Because we did not catch the tag delimiters earlier, we must be explicit with them here. + # Notice that this also matches "{}", as a way to later introduce it as an escape sequence. + \{(?1)?\} + | + # Make sure we match hanging "{". + \{ + ) + # Match content after the nested inline tag. + [^{}]* + )* # If there are more inline tags, match them as well. We use "*" since there may not be any + # nested inline tags. + ) + \}/Sux', + $contents, + 0, + PREG_SPLIT_DELIM_CAPTURE + ); + } + + /** + * Removes the superfluous from a multi-line description. + * + * When a description has more than one line then it can happen that the second and subsequent lines have an + * additional indentation. This is commonly in use with tags like this: + * + * {@}since 1.1.0 This is an example + * description where we have an + * indentation in the second and + * subsequent lines. + * + * If we do not normalize the indentation then we have superfluous whitespace on the second and subsequent + * lines and this may cause rendering issues when, for example, using a Markdown converter. + */ + private function removeSuperfluousStartingWhitespace(string $contents): string + { + $lines = Utils::pregSplit("/\r\n?|\n/", $contents); + + // if there is only one line then we don't have lines with superfluous whitespace and + // can use the contents as-is + if (count($lines) <= 1) { + return $contents; + } + + // determine how many whitespace characters need to be stripped + $startingSpaceCount = 9999999; + for ($i = 1, $iMax = count($lines); $i < $iMax; ++$i) { + // lines with a no length do not count as they are not indented at all + if (trim($lines[$i]) === '') { + continue; + } + + // determine the number of prefixing spaces by checking the difference in line length before and after + // an ltrim + $startingSpaceCount = min($startingSpaceCount, strlen($lines[$i]) - strlen(ltrim($lines[$i]))); + } + + // strip the number of spaces from each line + if ($startingSpaceCount > 0) { + for ($i = 1, $iMax = count($lines); $i < $iMax; ++$i) { + $lines[$i] = substr($lines[$i], $startingSpaceCount); + } + } + + return implode("\n", $lines); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/ExampleFinder.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/ExampleFinder.php new file mode 100644 index 0000000..0fb24a6 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/ExampleFinder.php @@ -0,0 +1,158 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock; + +use phpDocumentor\Reflection\DocBlock\Tags\Example; + +use function array_slice; +use function file; +use function getcwd; +use function implode; +use function is_readable; +use function rtrim; +use function sprintf; +use function trim; + +use const DIRECTORY_SEPARATOR; + +/** + * Class used to find an example file's location based on a given ExampleDescriptor. + */ +class ExampleFinder +{ + private string $sourceDirectory = ''; + + /** @var string[] */ + private array $exampleDirectories = []; + + /** + * Attempts to find the example contents for the given descriptor. + */ + public function find(Example $example): string + { + $filename = $example->getFilePath(); + + $file = $this->getExampleFileContents($filename); + if ($file === null) { + return sprintf('** File not found : %s **', $filename); + } + + return implode('', array_slice($file, $example->getStartingLine() - 1, $example->getLineCount())); + } + + /** + * Registers the project's root directory where an 'examples' folder can be expected. + */ + public function setSourceDirectory(string $directory = ''): void + { + $this->sourceDirectory = $directory; + } + + /** + * Returns the project's root directory where an 'examples' folder can be expected. + */ + public function getSourceDirectory(): string + { + return $this->sourceDirectory; + } + + /** + * Registers a series of directories that may contain examples. + * + * @param string[] $directories + */ + public function setExampleDirectories(array $directories): void + { + $this->exampleDirectories = $directories; + } + + /** + * Returns a series of directories that may contain examples. + * + * @return string[] + */ + public function getExampleDirectories(): array + { + return $this->exampleDirectories; + } + + /** + * Attempts to find the requested example file and returns its contents or null if no file was found. + * + * This method will try several methods in search of the given example file, the first one it encounters is + * returned: + * + * 1. Iterates through all examples folders for the given filename + * 2. Checks the source folder for the given filename + * 3. Checks the 'examples' folder in the current working directory for examples + * 4. Checks the path relative to the current working directory for the given filename + * + * @return string[] all lines of the example file + */ + private function getExampleFileContents(string $filename): ?array + { + $normalizedPath = null; + + foreach ($this->exampleDirectories as $directory) { + $exampleFileFromConfig = $this->constructExamplePath($directory, $filename); + if (is_readable($exampleFileFromConfig)) { + $normalizedPath = $exampleFileFromConfig; + break; + } + } + + if ($normalizedPath === null) { + if (is_readable($this->getExamplePathFromSource($filename))) { + $normalizedPath = $this->getExamplePathFromSource($filename); + } elseif (is_readable($this->getExamplePathFromExampleDirectory($filename))) { + $normalizedPath = $this->getExamplePathFromExampleDirectory($filename); + } elseif (is_readable($filename)) { + $normalizedPath = $filename; + } + } + + $lines = $normalizedPath !== null && is_readable($normalizedPath) ? file($normalizedPath) : false; + + return $lines !== false ? $lines : null; + } + + /** + * Get example filepath based on the example directory inside your project. + */ + private function getExamplePathFromExampleDirectory(string $file): string + { + return getcwd() . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . $file; + } + + /** + * Returns a path to the example file in the given directory.. + */ + private function constructExamplePath(string $directory, string $file): string + { + return rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . $file; + } + + /** + * Get example filepath based on sourcecode. + */ + private function getExamplePathFromSource(string $file): string + { + return sprintf( + '%s%s%s', + trim($this->getSourceDirectory(), '\\/'), + DIRECTORY_SEPARATOR, + trim($file, '"') + ); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Serializer.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Serializer.php new file mode 100644 index 0000000..2c257dd --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Serializer.php @@ -0,0 +1,156 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock; + +use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Tags\Formatter; +use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter; + +use function sprintf; +use function str_repeat; +use function str_replace; +use function strlen; +use function wordwrap; + +/** + * Converts a DocBlock back from an object to a complete DocComment including Asterisks. + */ +class Serializer +{ + /** @var string The string to indent the comment with. */ + protected string $indentString = ' '; + + /** @var int The number of times the indent string is repeated. */ + protected int $indent = 0; + + /** @var bool Whether to indent the first line with the given indent amount and string. */ + protected bool $isFirstLineIndented = true; + + /** @var int|null The max length of a line. */ + protected ?int $lineLength = null; + + /** @var Formatter A custom tag formatter. */ + protected Formatter $tagFormatter; + private string $lineEnding; + + /** + * Create a Serializer instance. + * + * @param int $indent The number of times the indent string is repeated. + * @param string $indentString The string to indent the comment with. + * @param bool $indentFirstLine Whether to indent the first line. + * @param int|null $lineLength The max length of a line or NULL to disable line wrapping. + * @param Formatter $tagFormatter A custom tag formatter, defaults to PassthroughFormatter. + * @param string $lineEnding Line ending used in the output, by default \n is used. + */ + public function __construct( + int $indent = 0, + string $indentString = ' ', + bool $indentFirstLine = true, + ?int $lineLength = null, + ?Formatter $tagFormatter = null, + string $lineEnding = "\n" + ) { + $this->indent = $indent; + $this->indentString = $indentString; + $this->isFirstLineIndented = $indentFirstLine; + $this->lineLength = $lineLength; + $this->tagFormatter = $tagFormatter ?: new PassthroughFormatter(); + $this->lineEnding = $lineEnding; + } + + /** + * Generate a DocBlock comment. + * + * @param DocBlock $docblock The DocBlock to serialize. + * + * @return string The serialized doc block. + */ + public function getDocComment(DocBlock $docblock): string + { + $indent = str_repeat($this->indentString, $this->indent); + $firstIndent = $this->isFirstLineIndented ? $indent : ''; + // 3 === strlen(' * ') + $wrapLength = $this->lineLength !== null ? $this->lineLength - strlen($indent) - 3 : null; + + $text = $this->removeTrailingSpaces( + $indent, + $this->addAsterisksForEachLine( + $indent, + $this->getSummaryAndDescriptionTextBlock($docblock, $wrapLength) + ) + ); + + $comment = $firstIndent . "/**\n"; + if ($text) { + $comment .= $indent . ' * ' . $text . "\n"; + $comment .= $indent . " *\n"; + } + + $comment = $this->addTagBlock($docblock, $wrapLength, $indent, $comment); + + return str_replace("\n", $this->lineEnding, $comment . $indent . ' */'); + } + + private function removeTrailingSpaces(string $indent, string $text): string + { + return str_replace( + sprintf("\n%s * \n", $indent), + sprintf("\n%s *\n", $indent), + $text + ); + } + + private function addAsterisksForEachLine(string $indent, string $text): string + { + return str_replace( + "\n", + sprintf("\n%s * ", $indent), + $text + ); + } + + private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, ?int $wrapLength): string + { + $text = $docblock->getSummary() . ((string) $docblock->getDescription() ? "\n\n" . $docblock->getDescription() + : ''); + if ($wrapLength !== null) { + $text = wordwrap($text, $wrapLength); + + return $text; + } + + return $text; + } + + private function addTagBlock(DocBlock $docblock, ?int $wrapLength, string $indent, string $comment): string + { + foreach ($docblock->getTags() as $tag) { + $tagText = $this->tagFormatter->format($tag); + if ($wrapLength !== null) { + $tagText = wordwrap($tagText, $wrapLength); + } + + $tagText = str_replace( + "\n", + sprintf("\n%s * ", $indent), + $tagText + ); + + $comment .= sprintf("%s * %s\n", $indent, $tagText); + } + + return $comment; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/StandardTagFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/StandardTagFactory.php new file mode 100644 index 0000000..1d9e5fe --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/StandardTagFactory.php @@ -0,0 +1,392 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock; + +use InvalidArgumentException; +use phpDocumentor\Reflection\DocBlock\Tags\Author; +use phpDocumentor\Reflection\DocBlock\Tags\Covers; +use phpDocumentor\Reflection\DocBlock\Tags\Deprecated; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractPHPStanFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\ExtendsFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\ImplementsFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\MethodFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\MixinFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyWriteFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateCovariantFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\ThrowsFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Generic; +use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag; +use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag; +use phpDocumentor\Reflection\DocBlock\Tags\See as SeeTag; +use phpDocumentor\Reflection\DocBlock\Tags\Since; +use phpDocumentor\Reflection\DocBlock\Tags\Source; +use phpDocumentor\Reflection\DocBlock\Tags\Uses; +use phpDocumentor\Reflection\DocBlock\Tags\Version; +use phpDocumentor\Reflection\FqsenResolver; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context as TypeContext; +use ReflectionMethod; +use ReflectionNamedType; +use ReflectionParameter; +use Webmozart\Assert\Assert; + +use function array_key_exists; +use function array_merge; +use function array_slice; +use function call_user_func_array; +use function get_class; +use function is_object; +use function preg_match; +use function sprintf; +use function strpos; +use function trim; + +/** + * Creates a Tag object given the contents of a tag. + * + * This Factory is capable of determining the appropriate class for a tag and instantiate it using its `create` + * factory method. The `create` factory method of a Tag can have a variable number of arguments; this way you can + * pass the dependencies that you need to construct a tag object. + * + * > Important: each parameter in addition to the body variable for the `create` method must default to null, otherwise + * > it violates the constraint with the interface; it is recommended to use the {@see Assert::notNull()} method to + * > verify that a dependency is actually passed. + * + * This Factory also features a Service Locator component that is used to pass the right dependencies to the + * `create` method of a tag; each dependency should be registered as a service or as a parameter. + * + * When you want to use a Tag of your own with custom handling you need to call the `registerTagHandler` method, pass + * the name of the tag and a Fully Qualified Class Name pointing to a class that implements the Tag interface. + */ +final class StandardTagFactory implements TagFactory +{ + /** PCRE regular expression matching a tag name. */ + public const REGEX_TAGNAME = '[\w\-\_\\\\:]+'; + + /** + * @var array<string, class-string<Tag>|Tag|Factory> An array with a tag as a key, and an + * FQCN to a class that handles it as an array value. + */ + private array $tagHandlerMappings = [ + 'author' => Author::class, + 'covers' => Covers::class, + 'deprecated' => Deprecated::class, + 'link' => LinkTag::class, + 'see' => SeeTag::class, + 'since' => Since::class, + 'source' => Source::class, + 'uses' => Uses::class, + 'version' => Version::class, + ]; + + /** + * @var array<class-string<Tag>> An array with an annotation as a key, and an + * FQCN to a class that handles it as an array value. + */ + private array $annotationMappings = []; + + /** + * @var ReflectionParameter[][] a lazy-loading cache containing parameters + * for each tagHandler that has been used. + */ + private array $tagHandlerParameterCache = []; + + 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 array $serviceLocator = []; + + private function __construct(FqsenResolver $fqsenResolver) + { + $this->fqsenResolver = $fqsenResolver; + + $this->addService($fqsenResolver, FqsenResolver::class); + } + + /** + * Initialize this tag factory with the means to resolve an FQSEN. + * + * @see self::registerTagHandler() to add a new tag handler to the existing default list. + */ + public static function createInstance(FqsenResolver $fqsenResolver): self + { + $tagFactory = new self($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + + $typeResolver = new TypeResolver($fqsenResolver); + + $phpstanTagFactory = new AbstractPHPStanFactory( + new ParamFactory($typeResolver, $descriptionFactory), + new VarFactory($typeResolver, $descriptionFactory), + new ReturnFactory($typeResolver, $descriptionFactory), + new PropertyFactory($typeResolver, $descriptionFactory), + new PropertyReadFactory($typeResolver, $descriptionFactory), + new PropertyWriteFactory($typeResolver, $descriptionFactory), + new MethodFactory($typeResolver, $descriptionFactory), + new MixinFactory($typeResolver, $descriptionFactory), + new ImplementsFactory($typeResolver, $descriptionFactory), + new ExtendsFactory($typeResolver, $descriptionFactory), + new TemplateFactory($typeResolver, $descriptionFactory), + new TemplateCovariantFactory($typeResolver, $descriptionFactory), + new ThrowsFactory($typeResolver, $descriptionFactory), + ); + + $tagFactory->addService($descriptionFactory); + $tagFactory->addService($typeResolver); + $tagFactory->registerTagHandler('param', $phpstanTagFactory); + $tagFactory->registerTagHandler('var', $phpstanTagFactory); + $tagFactory->registerTagHandler('return', $phpstanTagFactory); + $tagFactory->registerTagHandler('property', $phpstanTagFactory); + $tagFactory->registerTagHandler('property-read', $phpstanTagFactory); + $tagFactory->registerTagHandler('property-write', $phpstanTagFactory); + $tagFactory->registerTagHandler('method', $phpstanTagFactory); + $tagFactory->registerTagHandler('mixin', $phpstanTagFactory); + $tagFactory->registerTagHandler('extends', $phpstanTagFactory); + $tagFactory->registerTagHandler('implements', $phpstanTagFactory); + $tagFactory->registerTagHandler('template', $phpstanTagFactory); + $tagFactory->registerTagHandler('template-covariant', $phpstanTagFactory); + $tagFactory->registerTagHandler('template-extends', $phpstanTagFactory); + $tagFactory->registerTagHandler('template-implements', $phpstanTagFactory); + $tagFactory->registerTagHandler('throws', $phpstanTagFactory); + + return $tagFactory; + } + + public function create(string $tagLine, ?TypeContext $context = null): Tag + { + if (!$context) { + $context = new TypeContext(''); + } + + [$tagName, $tagBody] = $this->extractTagParts($tagLine); + + return $this->createTag(trim($tagBody), $tagName, $context); + } + + /** + * @param mixed $value + */ + public function addParameter(string $name, $value): void + { + $this->serviceLocator[$name] = $value; + } + + public function addService(object $service, ?string $alias = null): void + { + $this->serviceLocator[$alias ?? get_class($service)] = $service; + } + + /** {@inheritDoc} */ + public function registerTagHandler(string $tagName, $handler): void + { + Assert::stringNotEmpty($tagName); + if (strpos($tagName, '\\') !== false && $tagName[0] !== '\\') { + throw new InvalidArgumentException( + 'A namespaced tag must have a leading backslash as it must be fully qualified' + ); + } + + if (is_object($handler)) { + Assert::isInstanceOf($handler, Factory::class); + $this->tagHandlerMappings[$tagName] = $handler; + + return; + } + + Assert::classExists($handler); + Assert::implementsInterface($handler, Tag::class); + $this->tagHandlerMappings[$tagName] = $handler; + } + + /** + * Extracts all components for a tag. + * + * @return string[] + */ + private function extractTagParts(string $tagLine): array + { + $matches = []; + if (!preg_match('/^@(' . self::REGEX_TAGNAME . ')((?:[\s\(\{])\s*([^\s].*)|$)/us', $tagLine, $matches)) { + throw new InvalidArgumentException( + 'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors' + ); + } + + return array_slice($matches, 1); + } + + /** + * Creates a new tag object with the given name and body or returns null if the tag name was recognized but the + * body was invalid. + */ + private function createTag(string $body, string $name, TypeContext $context): Tag + { + $handlerClassName = $this->findHandlerClassName($name, $context); + $arguments = $this->getArgumentsForParametersFromWiring( + $this->fetchParametersForHandlerFactoryMethod($handlerClassName), + $this->getServiceLocatorWithDynamicParameters($context, $name, $body) + ); + + if (array_key_exists('tagLine', $arguments)) { + $arguments['tagLine'] = sprintf('@%s %s', $name, $body); + } + + try { + $callable = [$handlerClassName, 'create']; + Assert::isCallable($callable); + /** @phpstan-var callable(string): ?Tag $callable */ + $tag = call_user_func_array($callable, $arguments); + + return $tag ?? InvalidTag::create($body, $name); + } catch (InvalidArgumentException $e) { + return InvalidTag::create($body, $name)->withError($e); + } + } + + /** + * Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`). + * + * @return class-string<Tag>|Tag|Factory + */ + private function findHandlerClassName(string $tagName, TypeContext $context) + { + $handlerClassName = Generic::class; + if (isset($this->tagHandlerMappings[$tagName])) { + $handlerClassName = $this->tagHandlerMappings[$tagName]; + } elseif ($this->isAnnotation($tagName)) { + // TODO: Annotation support is planned for a later stage and as such is disabled for now + $tagName = (string) $this->fqsenResolver->resolve($tagName, $context); + if (isset($this->annotationMappings[$tagName])) { + $handlerClassName = $this->annotationMappings[$tagName]; + } + } + + return $handlerClassName; + } + + /** + * Retrieves the arguments that need to be passed to the Factory Method with the given Parameters. + * + * @param ReflectionParameter[] $parameters + * @param mixed[] $locator + * + * @return mixed[] A series of values that can be passed to the Factory Method of the tag whose parameters + * is provided with this method. + */ + private function getArgumentsForParametersFromWiring(array $parameters, array $locator): array + { + $arguments = []; + foreach ($parameters as $parameter) { + $type = $parameter->getType(); + $typeHint = null; + if ($type instanceof ReflectionNamedType) { + $typeHint = $type->getName(); + if ($typeHint === 'self') { + $declaringClass = $parameter->getDeclaringClass(); + if ($declaringClass !== null) { + $typeHint = $declaringClass->getName(); + } + } + } + + $parameterName = $parameter->getName(); + if (isset($locator[$typeHint ?? ''])) { + $arguments[$parameterName] = $locator[$typeHint ?? '']; + continue; + } + + if (isset($locator[$parameterName])) { + $arguments[$parameterName] = $locator[$parameterName]; + continue; + } + + $arguments[$parameterName] = null; + } + + return $arguments; + } + + /** + * Retrieves a series of ReflectionParameter objects for the static 'create' method of the given + * tag handler class name. + * + * @param class-string<Tag>|Tag|Factory $handler + * + * @return ReflectionParameter[] + */ + private function fetchParametersForHandlerFactoryMethod($handler): array + { + $handlerClassName = is_object($handler) ? get_class($handler) : $handler; + + if (!isset($this->tagHandlerParameterCache[$handlerClassName])) { + $methodReflection = new ReflectionMethod($handlerClassName, 'create'); + $this->tagHandlerParameterCache[$handlerClassName] = $methodReflection->getParameters(); + } + + return $this->tagHandlerParameterCache[$handlerClassName]; + } + + /** + * Returns a copy of this class' Service Locator with added dynamic parameters, + * such as the tag's name, body and Context. + * + * @param TypeContext $context The Context (namespace and aliases) that may be + * passed and is used to resolve FQSENs. + * @param string $tagName The name of the tag that may be + * passed onto the factory method of the Tag class. + * @param string $tagBody The body of the tag that may be + * passed onto the factory method of the Tag class. + * + * @return mixed[] + */ + private function getServiceLocatorWithDynamicParameters( + TypeContext $context, + string $tagName, + string $tagBody + ): array { + return array_merge( + $this->serviceLocator, + [ + 'name' => $tagName, + 'body' => $tagBody, + TypeContext::class => $context, + ] + ); + } + + /** + * Returns whether the given tag belongs to an annotation. + * + * @todo this method should be populated once we implement Annotation notation support. + */ + private function isAnnotation(string $tagContent): bool + { + // 1. Contains a namespace separator + // 2. Contains parenthesis + // 3. Is present in a list of known annotations (make the algorithm smart by first checking is the last part + // of the annotation class name matches the found tag name + + return false; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tag.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tag.php new file mode 100644 index 0000000..7cf07b4 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tag.php @@ -0,0 +1,31 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock; + +use phpDocumentor\Reflection\DocBlock\Tags\Formatter; + +interface Tag +{ + public function getName(): string; + + /** + * @return Tag|mixed Class that implements Tag + * @phpstan-return ?Tag + */ + public static function create(string $body); + + public function render(?Formatter $formatter = null): string; + + public function __toString(): string; +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/TagFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/TagFactory.php new file mode 100644 index 0000000..a6f1ae8 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/TagFactory.php @@ -0,0 +1,73 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock; + +use InvalidArgumentException; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory; + +interface TagFactory extends Factory +{ + /** + * Adds a parameter to the service locator that can be injected in a tag's factory method. + * + * When calling a tag's "create" method we always check the signature for dependencies to inject. One way is to + * typehint a parameter in the signature so that we can use that interface or class name to inject a dependency + * (see {@see addService()} for more information on that). + * + * Another way is to check the name of the argument against the names in the Service Locator. With this method + * you can add a variable that will be inserted when a tag's create method is not typehinted and has a matching + * name. + * + * Be aware that there are two reserved names: + * + * - name, representing the name of the tag. + * - body, representing the complete body of the tag. + * + * These parameters are injected at the last moment and will override any existing parameter with those names. + * + * @param mixed $value + */ + public function addParameter(string $name, $value): void; + + /** + * Registers a service with the Service Locator using the FQCN of the class or the alias, if provided. + * + * When calling a tag's "create" method we always check the signature for dependencies to inject. If a parameter + * has a typehint then the ServiceLocator is queried to see if a Service is registered for that typehint. + * + * Because interfaces are regularly used as type-hints this method provides an alias parameter; if the FQCN of the + * interface is passed as alias then every time that interface is requested the provided service will be returned. + */ + public function addService(object $service): void; + + /** + * Registers a handler for tags. + * + * If you want to use your own tags then you can use this method to instruct the TagFactory + * to register the name of a tag with the FQCN of a 'Tag Handler'. The Tag handler should implement + * the {@see Tag} interface (and thus the create method). + * + * @param string $tagName Name of tag to register a handler for. When registering a namespaced + * tag, the full name, along with a prefixing slash MUST be provided. + * @param class-string<Tag>|Factory $handler FQCN of handler. + * + * @throws InvalidArgumentException If the tag name is not a string. + * @throws InvalidArgumentException If the tag name is namespaced (contains backslashes) but + * does not start with a backslash. + * @throws InvalidArgumentException If the handler is not a string. + * @throws InvalidArgumentException If the handler is not an existing class. + * @throws InvalidArgumentException If the handler does not implement the {@see Tag} interface. + */ + public function registerTagHandler(string $tagName, $handler): void; +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Author.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Author.php new file mode 100644 index 0000000..e604ac8 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Author.php @@ -0,0 +1,102 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use InvalidArgumentException; + +use function filter_var; +use function preg_match; +use function trim; + +use const FILTER_VALIDATE_EMAIL; + +/** + * Reflection class for an {@}author tag in a Docblock. + */ +final class Author extends BaseTag +{ + /** @var string register that this is the author tag. */ + protected string $name = 'author'; + + /** @var string The name of the author */ + private string $authorName; + + /** @var string The email of the author */ + private string $authorEmail; + + /** + * Initializes this tag with the author name and e-mail. + */ + public function __construct(string $authorName, string $authorEmail) + { + if ($authorEmail && !filter_var($authorEmail, FILTER_VALIDATE_EMAIL)) { + throw new InvalidArgumentException('The author tag does not have a valid e-mail address'); + } + + $this->authorName = $authorName; + $this->authorEmail = $authorEmail; + } + + /** + * Gets the author's name. + * + * @return string The author's name. + */ + public function getAuthorName(): string + { + return $this->authorName; + } + + /** + * Returns the author's email. + * + * @return string The author's email. + */ + public function getEmail(): string + { + return $this->authorEmail; + } + + /** + * Returns this tag in string form. + */ + public function __toString(): string + { + if ($this->authorEmail) { + $authorEmail = '<' . $this->authorEmail . '>'; + } else { + $authorEmail = ''; + } + + $authorName = $this->authorName; + + return $authorName . ($authorEmail !== '' ? ($authorName !== '' ? ' ' : '') . $authorEmail : ''); + } + + /** + * Attempts to create a new Author object based on the tag body. + */ + public static function create(string $body): ?self + { + $splitTagContent = preg_match('/^([^\<]*)(?:\<([^\>]*)\>)?$/u', $body, $matches); + if (!$splitTagContent) { + return null; + } + + $authorName = trim($matches[1]); + $email = isset($matches[2]) ? trim($matches[2]) : ''; + + return new static($authorName, $email); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/BaseTag.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/BaseTag.php new file mode 100644 index 0000000..98b0d88 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/BaseTag.php @@ -0,0 +1,53 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Description; + +/** + * Parses a tag definition for a DocBlock. + */ +abstract class BaseTag implements DocBlock\Tag +{ + /** @var string Name of the tag */ + protected string $name = ''; + + /** @var Description|null Description of the tag. */ + protected ?Description $description = null; + + /** + * Gets the name of this tag. + * + * @return string The name of this tag. + */ + public function getName(): string + { + return $this->name; + } + + public function getDescription(): ?Description + { + return $this->description; + } + + public function render(?Formatter $formatter = null): string + { + if ($formatter === null) { + $formatter = new Formatter\PassthroughFormatter(); + } + + return $formatter->format($this); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Covers.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Covers.php new file mode 100644 index 0000000..ba2384f --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Covers.php @@ -0,0 +1,99 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\Fqsen; +use phpDocumentor\Reflection\FqsenResolver; +use phpDocumentor\Reflection\Types\Context as TypeContext; +use phpDocumentor\Reflection\Utils; +use Webmozart\Assert\Assert; + +use function array_key_exists; +use function explode; + +/** + * Reflection class for a @covers tag in a Docblock. + */ +final class Covers extends BaseTag +{ + protected string $name = 'covers'; + + private Fqsen $refers; + + /** + * Initializes this tag. + */ + public function __construct(Fqsen $refers, ?Description $description = null) + { + $this->refers = $refers; + $this->description = $description; + } + + public static function create( + string $body, + ?DescriptionFactory $descriptionFactory = null, + ?FqsenResolver $resolver = null, + ?TypeContext $context = null + ): self { + Assert::stringNotEmpty($body); + Assert::notNull($descriptionFactory); + Assert::notNull($resolver); + + $parts = Utils::pregSplit('/\s+/Su', $body, 2); + + return new static( + self::resolveFqsen($parts[0], $resolver, $context), + $descriptionFactory->create($parts[1] ?? '', $context) + ); + } + + private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context): Fqsen + { + Assert::notNull($fqsenResolver); + $fqsenParts = explode('::', $parts); + $resolved = $fqsenResolver->resolve($fqsenParts[0], $context); + + if (!array_key_exists(1, $fqsenParts)) { + return $resolved; + } + + return new Fqsen($resolved . '::' . $fqsenParts[1]); + } + + /** + * Returns the structural element this tag refers to. + */ + public function getReference(): Fqsen + { + return $this->refers; + } + + /** + * Returns a string representation of this tag. + */ + public function __toString(): string + { + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $refers = (string) $this->refers; + + return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Deprecated.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Deprecated.php new file mode 100644 index 0000000..8ae8322 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Deprecated.php @@ -0,0 +1,108 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\Types\Context as TypeContext; +use Webmozart\Assert\Assert; + +use function preg_match; + +/** + * Reflection class for a {@}deprecated tag in a Docblock. + */ +final class Deprecated extends BaseTag +{ + protected string $name = 'deprecated'; + + /** + * PCRE regular expression matching a version vector. + * Assumes the "x" modifier. + */ + public const REGEX_VECTOR = '(?: + # Normal release vectors. + \d\S* + | + # VCS version vectors. Per PHPCS, they are expected to + # follow the form of the VCS name, followed by ":", followed + # by the version vector itself. + # By convention, popular VCSes like CVS, SVN and GIT use "$" + # around the actual version vector. + [^\s\:]+\:\s*\$[^\$]+\$ + )'; + + /** @var string|null The version vector. */ + private ?string $version = null; + + public function __construct(?string $version = null, ?Description $description = null) + { + Assert::nullOrNotEmpty($version); + + $this->version = $version; + $this->description = $description; + } + + /** + * @return static + */ + public static function create( + ?string $body, + ?DescriptionFactory $descriptionFactory = null, + ?TypeContext $context = null + ): self { + if ($body === null || $body === '') { + return new static(); + } + + $matches = []; + if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { + return new static( + null, + $descriptionFactory !== null ? $descriptionFactory->create($body, $context) : null + ); + } + + Assert::notNull($descriptionFactory); + + return new static( + $matches[1], + $descriptionFactory->create($matches[2] ?? '', $context) + ); + } + + /** + * Gets the version section of the tag. + */ + public function getVersion(): ?string + { + return $this->version; + } + + /** + * Returns a string representation for this tag. + */ + public function __toString(): string + { + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $version = (string) $this->version; + + return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Example.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Example.php new file mode 100644 index 0000000..06ecf8c --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Example.php @@ -0,0 +1,197 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Tag; +use Webmozart\Assert\Assert; + +use function array_key_exists; +use function preg_match; +use function rawurlencode; +use function str_replace; +use function strpos; +use function trim; + +/** + * Reflection class for a {@}example tag in a Docblock. + */ +final class Example implements Tag +{ + /** @var string Path to a file to use as an example. May also be an absolute URI. */ + private string $filePath; + + /** + * @var bool Whether the file path component represents an URI. This determines how the file portion + * appears at {@link getContent()}. + */ + private bool $isURI; + + private int $startingLine; + + private int $lineCount; + + private ?string $content = null; + + public function __construct( + string $filePath, + bool $isURI, + int $startingLine, + int $lineCount, + ?string $content + ) { + Assert::stringNotEmpty($filePath); + Assert::greaterThanEq($startingLine, 1); + Assert::greaterThanEq($lineCount, 0); + + $this->filePath = $filePath; + $this->startingLine = $startingLine; + $this->lineCount = $lineCount; + if ($content !== null) { + $this->content = trim($content); + } + + $this->isURI = $isURI; + } + + public function getContent(): string + { + if ($this->content === null || $this->content === '') { + $filePath = $this->filePath; + if ($this->isURI) { + $filePath = $this->isUriRelative($this->filePath) + ? str_replace('%2F', '/', rawurlencode($this->filePath)) + : $this->filePath; + } + + return trim($filePath); + } + + return $this->content; + } + + public function getDescription(): ?string + { + return $this->content; + } + + public static function create(string $body): ?Tag + { + // File component: File path in quotes or File URI / Source information + if (!preg_match('/^\s*(?:(\"[^\"]+\")|(\S+))(?:\s+(.*))?$/sux', $body, $matches)) { + return null; + } + + $filePath = null; + $fileUri = null; + if (array_key_exists(1, $matches) && $matches[1] !== '') { + $filePath = $matches[1]; + } else { + $fileUri = array_key_exists(2, $matches) ? $matches[2] : ''; + } + + $startingLine = 1; + $lineCount = 0; + $description = null; + + if (array_key_exists(3, $matches)) { + $description = $matches[3]; + + // Starting line / Number of lines / Description + if (preg_match('/^([1-9]\d*)(?:\s+((?1))\s*)?(.*)$/sux', $matches[3], $contentMatches)) { + $startingLine = (int) $contentMatches[1]; + if (isset($contentMatches[2])) { + $lineCount = (int) $contentMatches[2]; + } + + if (array_key_exists(3, $contentMatches)) { + $description = $contentMatches[3]; + } + } + } + + return new static( + $filePath ?? ($fileUri ?? ''), + $fileUri !== null, + $startingLine, + $lineCount, + $description + ); + } + + /** + * Returns the file path. + * + * @return string Path to a file to use as an example. + * May also be an absolute URI. + */ + public function getFilePath(): string + { + return trim($this->filePath, '"'); + } + + /** + * Returns a string representation for this tag. + */ + public function __toString(): string + { + $filePath = $this->filePath; + $isDefaultLine = $this->startingLine === 1 && $this->lineCount === 0; + $startingLine = !$isDefaultLine ? (string) $this->startingLine : ''; + $lineCount = !$isDefaultLine ? (string) $this->lineCount : ''; + $content = (string) $this->content; + + return $filePath + . ($startingLine !== '' + ? ($filePath !== '' ? ' ' : '') . $startingLine + : '') + . ($lineCount !== '' + ? ($filePath !== '' || $startingLine !== '' ? ' ' : '') . $lineCount + : '') + . ($content !== '' + ? ($filePath !== '' || $startingLine !== '' || $lineCount !== '' ? ' ' : '') . $content + : ''); + } + + /** + * Returns true if the provided URI is relative or contains a complete scheme (and thus is absolute). + */ + private function isUriRelative(string $uri): bool + { + return strpos($uri, ':') === false; + } + + public function getStartingLine(): int + { + return $this->startingLine; + } + + public function getLineCount(): int + { + return $this->lineCount; + } + + public function getName(): string + { + return 'example'; + } + + public function render(?Formatter $formatter = null): string + { + if ($formatter === null) { + $formatter = new Formatter\PassthroughFormatter(); + } + + return $formatter->format($this); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Extends_.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Extends_.php new file mode 100644 index 0000000..583d791 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Extends_.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; + +/** + * Reflection class for a {@}extends tag in a Docblock. + */ +class Extends_ extends TagWithType +{ + public function __construct(Type $type, ?Description $description = null) + { + $this->name = 'extends'; + $this->type = $type; + $this->description = $description; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php new file mode 100644 index 0000000..770a09a --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php @@ -0,0 +1,130 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag; +use phpDocumentor\Reflection\Types\Context as TypeContext; +use PHPStan\PhpDocParser\Lexer\Lexer; +use PHPStan\PhpDocParser\Parser\ConstExprParser; +use PHPStan\PhpDocParser\Parser\ParserException; +use PHPStan\PhpDocParser\Parser\PhpDocParser; +use PHPStan\PhpDocParser\Parser\TokenIterator; +use PHPStan\PhpDocParser\Parser\TypeParser; +use PHPStan\PhpDocParser\ParserConfig; +use RuntimeException; + +use function property_exists; +use function rtrim; +use function str_replace; +use function trim; + +/** + * Factory class creating tags using phpstan's parser + * + * This class uses {@see PHPStanFactory} implementations to create tags + * from the ast of the phpstan docblock parser. + * + * @internal This class is not part of the BC promise of this library. + */ +class AbstractPHPStanFactory implements Factory +{ + private PhpDocParser $parser; + private Lexer $lexer; + /** @var PHPStanFactory[] */ + private array $factories; + + public function __construct(PHPStanFactory ...$factories) + { + $config = new ParserConfig(['indexes' => true, 'lines' => true]); + $this->lexer = new Lexer($config); + $constParser = new ConstExprParser($config); + $this->parser = new PhpDocParser( + $config, + new TypeParser($config, $constParser), + $constParser + ); + + $this->factories = $factories; + } + + public function create(string $tagLine, ?TypeContext $context = null): Tag + { + try { + $tokens = $this->tokenizeLine($tagLine); + $ast = $this->parser->parseTag($tokens); + if (property_exists($ast->value, 'description') === true) { + $ast->value->setAttribute( + 'description', + rtrim($ast->value->description . $tokens->joinUntil(Lexer::TOKEN_END), "\n") + ); + } + } catch (ParserException $e) { + return InvalidTag::create($tagLine, '')->withError($e); + } + + if ($context === null) { + $context = new TypeContext(''); + } + + try { + foreach ($this->factories as $factory) { + if ($factory->supports($ast, $context)) { + return $factory->create($ast, $context); + } + } + } catch (RuntimeException $e) { + return InvalidTag::create((string) $ast->value, 'method')->withError($e); + } catch (ParserException $e) { + return InvalidTag::create((string) $ast->value, $ast->name)->withError($e); + } + + return InvalidTag::create( + (string) $ast->value, + $ast->name + ); + } + + /** + * Solve the issue with the lexer not tokenizing the line correctly + * + * This method is a workaround for the lexer that includes newline tokens with spaces. For + * phpstan this isn't an issue, as it doesn't do a lot of things with the indentation of descriptions. + * But for us is important to keep the indentation of the descriptions, so we need to fix the lexer output. + */ + private function tokenizeLine(string $tagLine): TokenIterator + { + // Prefix continuation lines with "* ", which is consumed by the phpstan parser as TOKEN_PHPDOC_EOL. + $tagLine = str_replace("\n", "\n* ", $tagLine); + $tokens = $this->lexer->tokenize($tagLine . "\n"); + $fixed = []; + foreach ($tokens as $token) { + if ($token[Lexer::TYPE_OFFSET] === Lexer::TOKEN_PHPDOC_EOL) { + // Strip "* " prefix (and other horizontal whitespace) again so it doesn't and up in the + // description when we joinUntil() in create(). + $fixed[] = [ + Lexer::VALUE_OFFSET => trim($token[Lexer::VALUE_OFFSET], "* \t"), + Lexer::TYPE_OFFSET => $token[Lexer::TYPE_OFFSET], + Lexer::LINE_OFFSET => $token[Lexer::LINE_OFFSET] ?? 0, + ]; + + continue; + } + + $fixed[] = $token; + } + + return new TokenIterator($fixed); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ExtendsFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ExtendsFactory.php new file mode 100644 index 0000000..9a5528d --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ExtendsFactory.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\Extends_; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use Webmozart\Assert\Assert; + +use function is_string; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class ExtendsFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof ExtendsTagValueNode && $node->name === '@extends'; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, ExtendsTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new Extends_( + $this->typeResolver->createType($tagValue->type, $context), + $this->descriptionFactory->create($description, $context) + ); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/Factory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/Factory.php new file mode 100644 index 0000000..190d3ff --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/Factory.php @@ -0,0 +1,41 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use InvalidArgumentException; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\Types\Context as TypeContext; + +interface Factory +{ + /** + * Factory method responsible for instantiating the correct sub type. + * + * @param string $tagLine The text for this tag, including description. + * + * @return Tag A new tag object. + * + * @throws InvalidArgumentException If an invalid tag line was presented. + */ + public function create(string $tagLine, ?TypeContext $context = null): Tag; +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ImplementsFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ImplementsFactory.php new file mode 100644 index 0000000..20aed24 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ImplementsFactory.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\Implements_; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use Webmozart\Assert\Assert; + +use function is_string; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class ImplementsFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof ImplementsTagValueNode && $node->name === '@implements'; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, ImplementsTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new Implements_( + $this->typeResolver->createType($tagValue->type, $context), + $this->descriptionFactory->create($description, $context) + ); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/MethodFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/MethodFactory.php new file mode 100644 index 0000000..845a2da --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/MethodFactory.php @@ -0,0 +1,82 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\Method; +use phpDocumentor\Reflection\DocBlock\Tags\MethodParameter; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Mixed_; +use phpDocumentor\Reflection\Types\Void_; +use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueParameterNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use Webmozart\Assert\Assert; + +use function array_map; +use function trim; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class MethodFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, MethodTagValueNode::class); + + return new Method( + $tagValue->methodName, + array_map( + function (MethodTagValueParameterNode $param) use ($context) { + return new MethodParameter( + trim($param->parameterName, '$'), + $param->type === null ? new Mixed_() : $this->typeResolver->createType( + $param->type, + $context + ), + $param->isReference, + $param->isVariadic, + $param->defaultValue === null ? + MethodParameter::NO_DEFAULT_VALUE : + (string) $param->defaultValue + ); + }, + $tagValue->parameters + ), + $this->createReturnType($tagValue, $context), + $tagValue->isStatic, + $this->descriptionFactory->create($tagValue->description, $context), + false, + ); + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof MethodTagValueNode; + } + + private function createReturnType(MethodTagValueNode $tagValue, Context $context): Type + { + if ($tagValue->returnType === null) { + return new Void_(); + } + + return $this->typeResolver->createType($tagValue->returnType, $context); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/MethodParameterFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/MethodParameterFactory.php new file mode 100644 index 0000000..d98237c --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/MethodParameterFactory.php @@ -0,0 +1,100 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use function array_key_last; +use function get_class; +use function gettype; +use function method_exists; +use function ucfirst; +use function var_export; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class MethodParameterFactory +{ + /** + * Formats the given default value to a string-able mixin + * + * @param mixed $defaultValue + */ + public function format($defaultValue): string + { + $method = 'format' . ucfirst(gettype($defaultValue)); + if (method_exists($this, $method)) { + return $this->{$method}($defaultValue); + } + + return ''; + } + + private function formatDouble(float $defaultValue): string + { + return var_export($defaultValue, true); + } + + /** + * @param mixed $defaultValue + */ + private function formatNull($defaultValue): string + { + return 'null'; + } + + private function formatInteger(int $defaultValue): string + { + return var_export($defaultValue, true); + } + + private function formatString(string $defaultValue): string + { + return var_export($defaultValue, true); + } + + private function formatBoolean(bool $defaultValue): string + { + return var_export($defaultValue, true); + } + + /** + * @param array<(array<mixed>|int|float|bool|string|object|null)> $defaultValue + */ + private function formatArray(array $defaultValue): string + { + $formatedValue = '['; + + foreach ($defaultValue as $key => $value) { + $method = 'format' . ucfirst(gettype($value)); + if (!method_exists($this, $method)) { + continue; + } + + $formatedValue .= $this->{$method}($value); + + if ($key === array_key_last($defaultValue)) { + continue; + } + + $formatedValue .= ','; + } + + return $formatedValue . ']'; + } + + private function formatObject(object $defaultValue): string + { + return 'new ' . get_class($defaultValue) . '()'; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/MixinFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/MixinFactory.php new file mode 100644 index 0000000..03e4421 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/MixinFactory.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\Mixin; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\MixinTagValueNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use Webmozart\Assert\Assert; + +use function is_string; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class MixinFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, MixinTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new Mixin( + $this->typeResolver->createType($tagValue->type, $context), + $this->descriptionFactory->create($description, $context) + ); + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof MixinTagValueNode; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/PHPStanFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/PHPStanFactory.php new file mode 100644 index 0000000..cf04a06 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/PHPStanFactory.php @@ -0,0 +1,16 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; + +interface PHPStanFactory +{ + public function create(PhpDocTagNode $node, Context $context): Tag; + + public function supports(PhpDocTagNode $node, Context $context): bool; +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ParamFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ParamFactory.php new file mode 100644 index 0000000..fc74a32 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ParamFactory.php @@ -0,0 +1,84 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag; +use phpDocumentor\Reflection\DocBlock\Tags\Param; +use phpDocumentor\Reflection\Exception\ParserException; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\InvalidTagValueNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; +use PHPStan\PhpDocParser\Ast\Type\OffsetAccessTypeNode; +use Webmozart\Assert\Assert; + +use function is_string; +use function trim; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class ParamFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + + if ($tagValue instanceof InvalidTagValueNode) { + return InvalidTag::create($tagValue->value, 'param')->withError( + ParserException::from($tagValue->exception) + ); + } + + Assert::isInstanceOfAny( + $tagValue, + [ + ParamTagValueNode::class, + TypelessParamTagValueNode::class, + ] + ); + + if (($tagValue->type ?? null) instanceof OffsetAccessTypeNode) { + return InvalidTag::create( + (string) $tagValue, + 'param' + ); + } + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new Param( + trim($tagValue->parameterName, '$'), + $this->typeResolver->createType($tagValue->type ?? new IdentifierTypeNode('mixed'), $context), + $tagValue->isVariadic, + $this->descriptionFactory->create($description, $context), + $tagValue->isReference + ); + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof ParamTagValueNode + || $node->value instanceof TypelessParamTagValueNode + || $node->name === '@param'; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/PropertyFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/PropertyFactory.php new file mode 100644 index 0000000..b744ed0 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/PropertyFactory.php @@ -0,0 +1,54 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\Property; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode; +use Webmozart\Assert\Assert; + +use function is_string; +use function trim; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class PropertyFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, PropertyTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new Property( + trim($tagValue->propertyName, '$'), + $this->typeResolver->createType($tagValue->type, $context), + $this->descriptionFactory->create($description, $context) + ); + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof PropertyTagValueNode && $node->name === '@property'; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/PropertyReadFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/PropertyReadFactory.php new file mode 100644 index 0000000..b0898aa --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/PropertyReadFactory.php @@ -0,0 +1,54 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode; +use Webmozart\Assert\Assert; + +use function is_string; +use function trim; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class PropertyReadFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->typeResolver = $typeResolver; + $this->descriptionFactory = $descriptionFactory; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, PropertyTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new PropertyRead( + trim($tagValue->propertyName, '$'), + $this->typeResolver->createType($tagValue->type, $context), + $this->descriptionFactory->create($description, $context) + ); + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof PropertyTagValueNode && $node->name === '@property-read'; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/PropertyWriteFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/PropertyWriteFactory.php new file mode 100644 index 0000000..749b1ed --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/PropertyWriteFactory.php @@ -0,0 +1,54 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode; +use Webmozart\Assert\Assert; + +use function is_string; +use function trim; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class PropertyWriteFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, PropertyTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new PropertyWrite( + trim($tagValue->propertyName, '$'), + $this->typeResolver->createType($tagValue->type, $context), + $this->descriptionFactory->create($description, $context) + ); + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof PropertyTagValueNode && $node->name === '@property-write'; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ReturnFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ReturnFactory.php new file mode 100644 index 0000000..4a17dc2 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ReturnFactory.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\Return_; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; +use Webmozart\Assert\Assert; + +use function is_string; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class ReturnFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, ReturnTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new Return_( + $this->typeResolver->createType($tagValue->type, $context), + $this->descriptionFactory->create($description, $context) + ); + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof ReturnTagValueNode; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/TemplateCovariantFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/TemplateCovariantFactory.php new file mode 100644 index 0000000..329a997 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/TemplateCovariantFactory.php @@ -0,0 +1,53 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\TemplateCovariant; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; +use Webmozart\Assert\Assert; + +use function is_string; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class TemplateCovariantFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof TemplateTagValueNode && $node->name === '@template-covariant'; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, TemplateTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new TemplateCovariant( + $this->typeResolver->createType(new IdentifierTypeNode($tagValue->name), $context), + $this->descriptionFactory->create($description, $context) + ); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/TemplateFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/TemplateFactory.php new file mode 100644 index 0000000..9e4b3c8 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/TemplateFactory.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\Template; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode; +use Webmozart\Assert\Assert; + +use function is_string; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class TemplateFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + + Assert::isInstanceOf($tagValue, TemplateTagValueNode::class); + $name = $tagValue->name; + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new Template( + $name, + $this->typeResolver->createType($tagValue->bound, $context), + $this->typeResolver->createType($tagValue->default, $context), + $this->descriptionFactory->create($description, $context) + ); + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof TemplateTagValueNode && $node->name === '@template'; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ThrowsFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ThrowsFactory.php new file mode 100644 index 0000000..e547adc --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ThrowsFactory.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\Throws; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\ThrowsTagValueNode; +use Webmozart\Assert\Assert; + +use function is_string; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class ThrowsFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, ThrowsTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new Throws( + $this->typeResolver->createType($tagValue->type, $context), + $this->descriptionFactory->create($description, $context) + ); + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof ThrowsTagValueNode; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/VarFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/VarFactory.php new file mode 100644 index 0000000..479ceb2 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/VarFactory.php @@ -0,0 +1,54 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; + +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\Var_; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; +use Webmozart\Assert\Assert; + +use function is_string; +use function trim; + +/** + * @internal This class is not part of the BC promise of this library. + */ +final class VarFactory implements PHPStanFactory +{ + private DescriptionFactory $descriptionFactory; + private TypeResolver $typeResolver; + + public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, VarTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new Var_( + trim($tagValue->variableName, '$'), + $this->typeResolver->createType($tagValue->type, $context), + $this->descriptionFactory->create($description, $context) + ); + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof VarTagValueNode; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Formatter.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Formatter.php new file mode 100644 index 0000000..36b9983 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Formatter.php @@ -0,0 +1,24 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Tag; + +interface Formatter +{ + /** + * Formats a tag into a string representation according to a specific format, such as Markdown. + */ + public function format(Tag $tag): string; +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Formatter/AlignFormatter.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Formatter/AlignFormatter.php new file mode 100644 index 0000000..ea5c16f --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Formatter/AlignFormatter.php @@ -0,0 +1,50 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags\Formatter; + +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\Formatter; + +use function max; +use function str_repeat; +use function strlen; + +class AlignFormatter implements Formatter +{ + /** @var int The maximum tag name length. */ + protected int $maxLen = 0; + + /** + * @param Tag[] $tags All tags that should later be aligned with the formatter. + */ + public function __construct(array $tags) + { + foreach ($tags as $tag) { + $this->maxLen = max($this->maxLen, strlen($tag->getName())); + } + } + + /** + * Formats the given tag to return a simple plain text version. + */ + public function format(Tag $tag): string + { + return '@' . $tag->getName() . + str_repeat( + ' ', + $this->maxLen - strlen($tag->getName()) + 1 + ) . + $tag; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Formatter/PassthroughFormatter.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Formatter/PassthroughFormatter.php new file mode 100644 index 0000000..2afdfe5 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Formatter/PassthroughFormatter.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags\Formatter; + +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\Formatter; + +use function trim; + +class PassthroughFormatter implements Formatter +{ + /** + * Formats the given tag to return a simple plain text version. + */ + public function format(Tag $tag): string + { + return trim('@' . $tag->getName() . ' ' . $tag); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Generic.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Generic.php new file mode 100644 index 0000000..1445b16 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Generic.php @@ -0,0 +1,89 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use InvalidArgumentException; +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; +use phpDocumentor\Reflection\Types\Context as TypeContext; +use Webmozart\Assert\Assert; + +use function preg_match; + +/** + * Parses a tag definition for a DocBlock. + */ +final class Generic extends BaseTag +{ + /** + * Parses a tag and populates the member variables. + * + * @param string $name Name of the tag. + * @param Description $description The contents of the given tag. + */ + public function __construct(string $name, ?Description $description = null) + { + $this->validateTagName($name); + + $this->name = $name; + $this->description = $description; + } + + /** + * Creates a new tag that represents any unknown tag type. + * + * @return static + */ + public static function create( + string $body, + string $name = '', + ?DescriptionFactory $descriptionFactory = null, + ?TypeContext $context = null + ): self { + Assert::stringNotEmpty($name); + Assert::notNull($descriptionFactory); + + $description = $body !== '' ? $descriptionFactory->create($body, $context) : null; + + return new static($name, $description); + } + + /** + * Returns the tag as a serialized string + */ + public function __toString(): string + { + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + return $description; + } + + /** + * Validates if the tag name matches the expected format, otherwise throws an exception. + */ + private function validateTagName(string $name): void + { + if (!preg_match('/^' . StandardTagFactory::REGEX_TAGNAME . '$/u', $name)) { + throw new InvalidArgumentException( + 'The tag name "' . $name . '" is not wellformed. Tags may only consist of letters, underscores, ' + . 'hyphens and backslashes.' + ); + } + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Implements_.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Implements_.php new file mode 100644 index 0000000..4c8ce5e --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Implements_.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; + +/** + * Reflection class for a {@}implements tag in a Docblock. + */ +class Implements_ extends TagWithType +{ + public function __construct(Type $type, ?Description $description = null) + { + $this->name = 'implements'; + $this->type = $type; + $this->description = $description; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/InvalidTag.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/InvalidTag.php new file mode 100644 index 0000000..848f34d --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/InvalidTag.php @@ -0,0 +1,150 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use Closure; +use Exception; +use phpDocumentor\Reflection\DocBlock\Tag; +use ReflectionClass; +use ReflectionException; +use ReflectionFunction; +use Throwable; + +use function array_map; +use function get_class; +use function get_resource_type; +use function is_array; +use function is_object; +use function is_resource; +use function sprintf; + +use const PHP_VERSION_ID; + +/** + * This class represents an exception during the tag creation + * + * Since the internals of the library are relaying on the correct syntax of a docblock + * we cannot simply throw exceptions at all time because the exceptions will break the creation of a + * docklock. Just silently ignore the exceptions is not an option because the user as an issue to fix. + * + * This tag holds that error information until a using application is able to display it. The object will just behave + * like any normal tag. So the normal application flow will not break. + */ +final class InvalidTag implements Tag +{ + private string $name; + + private string $body; + + private ?Throwable $throwable = null; + + private function __construct(string $name, string $body) + { + $this->name = $name; + $this->body = $body; + } + + public function getException(): ?Throwable + { + return $this->throwable; + } + + public function getName(): string + { + return $this->name; + } + + public static function create(string $body, string $name = ''): self + { + return new self($name, $body); + } + + public function withError(Throwable $exception): self + { + $this->flattenExceptionBacktrace($exception); + $tag = new self($this->name, $this->body); + $tag->throwable = $exception; + + return $tag; + } + + /** + * Removes all complex types from backtrace + * + * Not all objects are serializable. So we need to remove them from the + * stored exception to be sure that we do not break existing library usage. + */ + private function flattenExceptionBacktrace(Throwable $exception): void + { + $traceProperty = (new ReflectionClass(Exception::class))->getProperty('trace'); + if (PHP_VERSION_ID < 80100) { + $traceProperty->setAccessible(true); + } + + do { + $trace = $exception->getTrace(); + if (isset($trace[0]['args'])) { + $trace = array_map( + function (array $call): array { + $call['args'] = array_map([$this, 'flattenArguments'], $call['args'] ?? []); + + return $call; + }, + $trace + ); + } + + $traceProperty->setValue($exception, $trace); + $exception = $exception->getPrevious(); + } while ($exception !== null); + + if (PHP_VERSION_ID >= 80100) { + return; + } + + $traceProperty->setAccessible(false); + } + + /** + * @param mixed $value + * + * @return mixed + * + * @throws ReflectionException + */ + private function flattenArguments($value) + { + if ($value instanceof Closure) { + $closureReflection = new ReflectionFunction($value); + $value = sprintf( + '(Closure at %s:%s)', + $closureReflection->getFileName(), + $closureReflection->getStartLine() + ); + } elseif (is_object($value)) { + $value = sprintf('object(%s)', get_class($value)); + } elseif (is_resource($value)) { + $value = sprintf('resource(%s)', get_resource_type($value)); + } elseif (is_array($value)) { + $value = array_map([$this, 'flattenArguments'], $value); + } + + return $value; + } + + public function render(?Formatter $formatter = null): string + { + if ($formatter === null) { + $formatter = new Formatter\PassthroughFormatter(); + } + + return $formatter->format($this); + } + + public function __toString(): string + { + return $this->body; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Link.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Link.php new file mode 100644 index 0000000..8ce615d --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Link.php @@ -0,0 +1,76 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\Types\Context as TypeContext; +use phpDocumentor\Reflection\Utils; +use Webmozart\Assert\Assert; + +/** + * Reflection class for a {@}link tag in a Docblock. + */ +final class Link extends BaseTag +{ + protected string $name = 'link'; + + private string $link; + + /** + * Initializes a link to a URL. + */ + public function __construct(string $link, ?Description $description = null) + { + $this->link = $link; + $this->description = $description; + } + + public static function create( + string $body, + ?DescriptionFactory $descriptionFactory = null, + ?TypeContext $context = null + ): self { + Assert::notNull($descriptionFactory); + + $parts = Utils::pregSplit('/\s+/Su', $body, 2); + $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; + + return new static($parts[0], $description); + } + + /** + * Gets the link + */ + public function getLink(): string + { + return $this->link; + } + + /** + * Returns a string representation for this tag. + */ + public function __toString(): string + { + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $link = $this->link; + + return $link . ($description !== '' ? ($link !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Method.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Method.php new file mode 100644 index 0000000..66d1167 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Method.php @@ -0,0 +1,135 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Exception\CannotCreateTag; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Void_; +use Webmozart\Assert\Assert; + +use function implode; +/** + * Reflection class for an {@}method in a Docblock. + */ + +final class Method extends BaseTag +{ + protected string $name = 'method'; + + private string $methodName; + + private bool $isStatic; + + private Type $returnType; + + private bool $returnsReference; + + /** @var MethodParameter[] */ + private array $parameters; + + /** + * @param MethodParameter[] $parameters + */ + public function __construct( + string $methodName, + array $parameters = [], + ?Type $returnType = null, + bool $static = false, + ?Description $description = null, + bool $returnsReference = false + ) { + Assert::stringNotEmpty($methodName); + + if ($returnType === null) { + $returnType = new Void_(); + } + + $this->methodName = $methodName; + $this->returnType = $returnType; + $this->isStatic = $static; + $this->description = $description; + $this->returnsReference = $returnsReference; + $this->parameters = $parameters; + } + + /** + * Retrieves the method name. + */ + public function getMethodName(): string + { + return $this->methodName; + } + + /** @return MethodParameter[] */ + public function getParameters(): array + { + return $this->parameters; + } + + /** + * Checks whether the method tag describes a static method or not. + * + * @return bool TRUE if the method declaration is for a static method, FALSE otherwise. + */ + public function isStatic(): bool + { + return $this->isStatic; + } + + public function getReturnType(): Type + { + return $this->returnType; + } + + public function returnsReference(): bool + { + return $this->returnsReference; + } + + public function __toString(): string + { + $arguments = []; + foreach ($this->parameters as $parameter) { + $arguments[] = (string) $parameter; + } + + $argumentStr = '(' . implode(', ', $arguments) . ')'; + + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $static = $this->isStatic ? 'static' : ''; + + $returnType = (string) $this->returnType; + + $methodName = $this->methodName; + + $reference = $this->returnsReference ? '&' : ''; + + return $static + . ($returnType !== '' ? ($static !== '' ? ' ' : '') . $returnType : '') + . ($methodName !== '' ? ($static !== '' || $returnType !== '' ? ' ' : '') . $reference . $methodName : '') + . $argumentStr + . ($description !== '' ? ' ' . $description : ''); + } + + public static function create(string $body): void + { + throw new CannotCreateTag('Method tag cannot be created'); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/MethodParameter.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/MethodParameter.php new file mode 100644 index 0000000..68c7ca9 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/MethodParameter.php @@ -0,0 +1,91 @@ +<?php +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Tags\Factory\MethodParameterFactory; +use phpDocumentor\Reflection\Type; + +final class MethodParameter +{ + private Type $type; + + private bool $isReference; + + private bool $isVariadic; + + private string $name; + + /** @var mixed */ + private $defaultValue; + + public const NO_DEFAULT_VALUE = '__NO_VALUE__'; + + /** + * @param mixed $defaultValue + */ + public function __construct( + string $name, + Type $type, + bool $isReference = false, + bool $isVariadic = false, + $defaultValue = self::NO_DEFAULT_VALUE + ) { + $this->type = $type; + $this->isReference = $isReference; + $this->isVariadic = $isVariadic; + $this->name = $name; + $this->defaultValue = $defaultValue; + } + + public function getName(): string + { + return $this->name; + } + + public function getType(): Type + { + return $this->type; + } + + public function isReference(): bool + { + return $this->isReference; + } + + public function isVariadic(): bool + { + return $this->isVariadic; + } + + public function getDefaultValue(): ?string + { + if ($this->defaultValue === self::NO_DEFAULT_VALUE) { + return null; + } + + return (new MethodParameterFactory())->format($this->defaultValue); + } + + public function __toString(): string + { + return $this->getType() . ' ' . + ($this->isReference() ? '&' : '') . + ($this->isVariadic() ? '...' : '') . + '$' . $this->getName() . + ( + $this->defaultValue !== self::NO_DEFAULT_VALUE ? + ' = ' . (new MethodParameterFactory())->format($this->defaultValue) : + '' + ); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Mixin.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Mixin.php new file mode 100644 index 0000000..2b0909c --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Mixin.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; + +/** + * Reflection class for a {@}mixin tag in a Docblock. + */ +final class Mixin extends TagWithType +{ + public function __construct(Type $type, ?Description $description = null) + { + $this->name = 'mixin'; + $this->type = $type; + $this->description = $description; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Param.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Param.php new file mode 100644 index 0000000..1653365 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Param.php @@ -0,0 +1,94 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; + +/** + * Reflection class for the {@}param tag in a Docblock. + */ +final class Param extends TagWithType +{ + private ?string $variableName = null; + + /** @var bool determines whether this is a variadic argument */ + private bool $isVariadic; + + /** @var bool determines whether this is passed by reference */ + private bool $isReference; + + public function __construct( + ?string $variableName, + ?Type $type = null, + bool $isVariadic = false, + ?Description $description = null, + bool $isReference = false + ) { + $this->name = 'param'; + $this->variableName = $variableName; + $this->type = $type; + $this->isVariadic = $isVariadic; + $this->description = $description; + $this->isReference = $isReference; + } + + /** + * Returns the variable's name. + */ + public function getVariableName(): ?string + { + return $this->variableName; + } + + /** + * Returns whether this tag is variadic. + */ + public function isVariadic(): bool + { + return $this->isVariadic; + } + + /** + * Returns whether this tag is passed by reference. + */ + public function isReference(): bool + { + return $this->isReference; + } + + /** + * Returns a string representation for this tag. + */ + public function __toString(): string + { + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $variableName = ''; + if ($this->variableName !== null && $this->variableName !== '') { + $variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : ''); + $variableName .= '$' . $this->variableName; + } + + $type = (string) $this->type; + + return $type + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Property.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Property.php new file mode 100644 index 0000000..b7bd958 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Property.php @@ -0,0 +1,68 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; +use Webmozart\Assert\Assert; + +/** + * Reflection class for a {@}property tag in a Docblock. + */ +final class Property extends TagWithType +{ + protected ?string $variableName = null; + + public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) + { + Assert::string($variableName); + + $this->name = 'property'; + $this->variableName = $variableName; + $this->type = $type; + $this->description = $description; + } + + /** + * Returns the variable's name. + */ + public function getVariableName(): ?string + { + return $this->variableName; + } + + /** + * Returns a string representation for this tag. + */ + public function __toString(): string + { + if ($this->description !== null) { + $description = $this->description->render(); + } else { + $description = ''; + } + + if ($this->variableName !== null && $this->variableName !== '') { + $variableName = '$' . $this->variableName; + } else { + $variableName = ''; + } + + $type = (string) $this->type; + + return $type + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/PropertyRead.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/PropertyRead.php new file mode 100644 index 0000000..bcb0e0d --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/PropertyRead.php @@ -0,0 +1,68 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; +use Webmozart\Assert\Assert; + +/** + * Reflection class for a {@}property-read tag in a Docblock. + */ +final class PropertyRead extends TagWithType +{ + protected ?string $variableName = null; + + public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) + { + Assert::string($variableName); + + $this->name = 'property-read'; + $this->variableName = $variableName; + $this->type = $type; + $this->description = $description; + } + + /** + * Returns the variable's name. + */ + public function getVariableName(): ?string + { + return $this->variableName; + } + + /** + * Returns a string representation for this tag. + */ + public function __toString(): string + { + if ($this->description !== null) { + $description = $this->description->render(); + } else { + $description = ''; + } + + if ($this->variableName !== null && $this->variableName !== '') { + $variableName = '$' . $this->variableName; + } else { + $variableName = ''; + } + + $type = (string) $this->type; + + return $type + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/PropertyWrite.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/PropertyWrite.php new file mode 100644 index 0000000..a5ee9e9 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/PropertyWrite.php @@ -0,0 +1,68 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; +use Webmozart\Assert\Assert; + +/** + * Reflection class for a {@}property-write tag in a Docblock. + */ +final class PropertyWrite extends TagWithType +{ + protected string $variableName; + + public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) + { + Assert::string($variableName); + + $this->name = 'property-write'; + $this->variableName = $variableName; + $this->type = $type; + $this->description = $description; + } + + /** + * Returns the variable's name. + */ + public function getVariableName(): ?string + { + return $this->variableName; + } + + /** + * Returns a string representation for this tag. + */ + public function __toString(): string + { + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + if ($this->variableName) { + $variableName = '$' . $this->variableName; + } else { + $variableName = ''; + } + + $type = (string) $this->type; + + return $type + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Reference/Fqsen.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Reference/Fqsen.php new file mode 100644 index 0000000..e4e7e31 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Reference/Fqsen.php @@ -0,0 +1,37 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags\Reference; + +use phpDocumentor\Reflection\Fqsen as RealFqsen; + +/** + * Fqsen reference used by {@see \phpDocumentor\Reflection\DocBlock\Tags\See} + */ +final class Fqsen implements Reference +{ + private RealFqsen $fqsen; + + public function __construct(RealFqsen $fqsen) + { + $this->fqsen = $fqsen; + } + + /** + * @return string string representation of the referenced fqsen + */ + public function __toString(): string + { + return (string) $this->fqsen; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Reference/Reference.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Reference/Reference.php new file mode 100644 index 0000000..e7dea86 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Reference/Reference.php @@ -0,0 +1,22 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags\Reference; + +/** + * Interface for references in {@see \phpDocumentor\Reflection\DocBlock\Tags\See} + */ +interface Reference +{ + public function __toString(): string; +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Reference/Url.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Reference/Url.php new file mode 100644 index 0000000..5954a47 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Reference/Url.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags\Reference; + +use Webmozart\Assert\Assert; + +/** + * Url reference used by {@see \phpDocumentor\Reflection\DocBlock\Tags\See} + */ +final class Url implements Reference +{ + private string $uri; + + public function __construct(string $uri) + { + Assert::stringNotEmpty($uri); + $this->uri = $uri; + } + + public function __toString(): string + { + return $this->uri; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Return_.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Return_.php new file mode 100644 index 0000000..bc93a79 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Return_.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; + +/** + * Reflection class for a {@}return tag in a Docblock. + */ +final class Return_ extends TagWithType +{ + public function __construct(Type $type, ?Description $description = null) + { + $this->name = 'return'; + $this->type = $type; + $this->description = $description; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/See.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/See.php new file mode 100644 index 0000000..f8242d4 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/See.php @@ -0,0 +1,104 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as FqsenRef; +use phpDocumentor\Reflection\DocBlock\Tags\Reference\Reference; +use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url; +use phpDocumentor\Reflection\Fqsen; +use phpDocumentor\Reflection\FqsenResolver; +use phpDocumentor\Reflection\Types\Context as TypeContext; +use phpDocumentor\Reflection\Utils; +use Webmozart\Assert\Assert; + +use function array_key_exists; +use function explode; +use function preg_match; + +/** + * Reflection class for an {@}see tag in a Docblock. + */ +final class See extends BaseTag +{ + protected string $name = 'see'; + + protected Reference $refers; + + /** + * Initializes this tag. + */ + public function __construct(Reference $refers, ?Description $description = null) + { + $this->refers = $refers; + $this->description = $description; + } + + public static function create( + string $body, + ?FqsenResolver $typeResolver = null, + ?DescriptionFactory $descriptionFactory = null, + ?TypeContext $context = null + ): self { + Assert::notNull($descriptionFactory); + + $parts = Utils::pregSplit('/\s+/Su', $body, 2); + $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; + + // https://tools.ietf.org/html/rfc2396#section-3 + if (preg_match('#\w://\w#', $parts[0])) { + return new static(new Url($parts[0]), $description); + } + + return new static(new FqsenRef(self::resolveFqsen($parts[0], $typeResolver, $context)), $description); + } + + private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context): Fqsen + { + Assert::notNull($fqsenResolver); + $fqsenParts = explode('::', $parts); + $resolved = $fqsenResolver->resolve($fqsenParts[0], $context); + + if (!array_key_exists(1, $fqsenParts)) { + return $resolved; + } + + return new Fqsen($resolved . '::' . $fqsenParts[1]); + } + + /** + * Returns the ref of this tag. + */ + public function getReference(): Reference + { + return $this->refers; + } + + /** + * Returns a string representation of this tag. + */ + public function __toString(): string + { + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $refers = (string) $this->refers; + + return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Since.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Since.php new file mode 100644 index 0000000..abfc750 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Since.php @@ -0,0 +1,102 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\Types\Context as TypeContext; +use Webmozart\Assert\Assert; + +use function preg_match; + +/** + * Reflection class for a {@}since tag in a Docblock. + */ +final class Since extends BaseTag +{ + protected string $name = 'since'; + + /** + * PCRE regular expression matching a version vector. + * Assumes the "x" modifier. + */ + public const REGEX_VECTOR = '(?: + # Normal release vectors. + \d\S* + | + # VCS version vectors. Per PHPCS, they are expected to + # follow the form of the VCS name, followed by ":", followed + # by the version vector itself. + # By convention, popular VCSes like CVS, SVN and GIT use "$" + # around the actual version vector. + [^\s\:]+\:\s*\$[^\$]+\$ + )'; + + /** @var string|null The version vector. */ + private ?string $version = null; + + public function __construct(?string $version = null, ?Description $description = null) + { + Assert::nullOrNotEmpty($version); + + $this->version = $version; + $this->description = $description; + } + + public static function create( + ?string $body, + ?DescriptionFactory $descriptionFactory = null, + ?TypeContext $context = null + ): ?self { + if ($body === null || $body === '') { + return new static(); + } + + $matches = []; + if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { + return null; + } + + Assert::notNull($descriptionFactory); + + return new static( + $matches[1], + $descriptionFactory->create($matches[2] ?? '', $context) + ); + } + + /** + * Gets the version section of the tag. + */ + public function getVersion(): ?string + { + return $this->version; + } + + /** + * Returns a string representation for this tag. + */ + public function __toString(): string + { + if ($this->description !== null) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $version = (string) $this->version; + + return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Source.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Source.php new file mode 100644 index 0000000..71eefcd --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Source.php @@ -0,0 +1,115 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\Types\Context as TypeContext; +use Webmozart\Assert\Assert; + +use function preg_match; + +/** + * Reflection class for a {@}source tag in a Docblock. + */ +final class Source extends BaseTag +{ + protected string $name = 'source'; + + /** @var int The starting line, relative to the structural element's location. */ + private int $startingLine; + + /** @var int|null The number of lines, relative to the starting line. NULL means "to the end". */ + private ?int $lineCount = null; + + /** + * @param int|string $startingLine should be a to int convertible value + * @param int|string|null $lineCount should be a to int convertible value + */ + public function __construct($startingLine, $lineCount = null, ?Description $description = null) + { + Assert::integerish($startingLine); + Assert::nullOrIntegerish($lineCount); + + $this->startingLine = (int) $startingLine; + $this->lineCount = $lineCount !== null ? (int) $lineCount : null; + $this->description = $description; + } + + public static function create( + string $body, + ?DescriptionFactory $descriptionFactory = null, + ?TypeContext $context = null + ): self { + Assert::stringNotEmpty($body); + Assert::notNull($descriptionFactory); + + $startingLine = 1; + $lineCount = null; + $description = null; + + // Starting line / Number of lines / Description + if (preg_match('/^([1-9]\d*)\s*(?:((?1))\s+)?(.*)$/sux', $body, $matches)) { + $startingLine = (int) $matches[1]; + if (isset($matches[2]) && $matches[2] !== '') { + $lineCount = (int) $matches[2]; + } + + $description = $matches[3]; + } + + return new static($startingLine, $lineCount, $descriptionFactory->create($description ?? '', $context)); + } + + /** + * Gets the starting line. + * + * @return int The starting line, relative to the structural element's + * location. + */ + public function getStartingLine(): int + { + return $this->startingLine; + } + + /** + * Returns the number of lines. + * + * @return int|null The number of lines, relative to the starting line. NULL + * means "to the end". + */ + public function getLineCount(): ?int + { + return $this->lineCount; + } + + public function __toString(): string + { + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $startingLine = (string) $this->startingLine; + + $lineCount = $this->lineCount !== null ? ' ' . $this->lineCount : ''; + + return $startingLine + . $lineCount + . ($description !== '' + ? ' ' . $description + : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/TagWithType.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/TagWithType.php new file mode 100644 index 0000000..36f43be --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/TagWithType.php @@ -0,0 +1,50 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\Exception\CannotCreateTag; +use phpDocumentor\Reflection\Type; + +abstract class TagWithType extends BaseTag +{ + /** @var ?Type */ + protected ?Type $type = null; + + /** + * Returns the type section of the variable. + */ + public function getType(): ?Type + { + return $this->type; + } + + final public static function create(string $body): Tag + { + throw new CannotCreateTag('Typed tag cannot be created'); + } + + public function __toString(): string + { + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $type = (string) $this->type; + + return $type . ($description !== '' ? ($type !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Template.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Template.php new file mode 100644 index 0000000..5009879 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Template.php @@ -0,0 +1,85 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\Exception\CannotCreateTag; +use phpDocumentor\Reflection\Type; + +/** + * Reflection class for a {@}template tag in a Docblock. + */ +final class Template extends BaseTag +{ + /** @var non-empty-string */ + private string $templateName; + + /** @var ?Type The real type */ + private ?Type $bound; + + private ?Type $default; + + /** @param non-empty-string $templateName */ + public function __construct( + string $templateName, + ?Type $bound = null, + ?Type $default = null, + ?Description $description = null + ) { + $this->name = 'template'; + $this->templateName = $templateName; + $this->bound = $bound; + $this->default = $default; + $this->description = $description; + } + + /** + * @deprecated Create using static factory is deprecated, + * this method should not be called directly by library consumers + */ + public static function create(string $body): ?Tag + { + throw new CannotCreateTag('Template tag cannot be created'); + } + + public function getTemplateName(): string + { + return $this->templateName; + } + + public function getBound(): ?Type + { + return $this->bound; + } + + public function getDefault(): ?Type + { + return $this->default; + } + + public function __toString(): string + { + $bound = $this->bound !== null ? ' of ' . $this->bound : ''; + $default = $this->default !== null ? ' = ' . $this->default : ''; + + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + return $this->templateName . $bound . $default . ($description !== '' ? ' ' . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/TemplateCovariant.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/TemplateCovariant.php new file mode 100644 index 0000000..4ce2a94 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/TemplateCovariant.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; + +/** + * Reflection class for a {@}template-covariant tag in a Docblock. + */ +final class TemplateCovariant extends TagWithType +{ + public function __construct(Type $type, ?Description $description = null) + { + $this->name = 'template-covariant'; + $this->type = $type; + $this->description = $description; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/TemplateExtends.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/TemplateExtends.php new file mode 100644 index 0000000..8de4681 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/TemplateExtends.php @@ -0,0 +1,29 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; + +/** + * Reflection class for a {@}template-extends tag in a Docblock. + */ +final class TemplateExtends extends Extends_ +{ + public function __construct(Type $type, ?Description $description = null) + { + parent::__construct($type, $description); + $this->name = 'template-extends'; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/TemplateImplements.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/TemplateImplements.php new file mode 100644 index 0000000..1fb073d --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/TemplateImplements.php @@ -0,0 +1,29 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; + +/** + * Reflection class for a {@}template-implements tag in a Docblock. + */ +final class TemplateImplements extends Implements_ +{ + public function __construct(Type $type, ?Description $description = null) + { + parent::__construct($type, $description); + $this->name = 'template-implements'; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Throws.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Throws.php new file mode 100644 index 0000000..675b6f0 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Throws.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; + +/** + * Reflection class for a {@}throws tag in a Docblock. + */ +final class Throws extends TagWithType +{ + public function __construct(Type $type, ?Description $description = null) + { + $this->name = 'throws'; + $this->type = $type; + $this->description = $description; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Uses.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Uses.php new file mode 100644 index 0000000..8a9849a --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Uses.php @@ -0,0 +1,98 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\Fqsen; +use phpDocumentor\Reflection\FqsenResolver; +use phpDocumentor\Reflection\Types\Context as TypeContext; +use phpDocumentor\Reflection\Utils; +use Webmozart\Assert\Assert; + +use function array_key_exists; +use function explode; + +/** + * Reflection class for a {@}uses tag in a Docblock. + */ +final class Uses extends BaseTag +{ + protected string $name = 'uses'; + + protected Fqsen $refers; + + /** + * Initializes this tag. + */ + public function __construct(Fqsen $refers, ?Description $description = null) + { + $this->refers = $refers; + $this->description = $description; + } + + public static function create( + string $body, + ?FqsenResolver $resolver = null, + ?DescriptionFactory $descriptionFactory = null, + ?TypeContext $context = null + ): self { + Assert::notNull($resolver); + Assert::notNull($descriptionFactory); + + $parts = Utils::pregSplit('/\s+/Su', $body, 2); + + return new static( + self::resolveFqsen($parts[0], $resolver, $context), + $descriptionFactory->create($parts[1] ?? '', $context) + ); + } + + private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context): Fqsen + { + Assert::notNull($fqsenResolver); + $fqsenParts = explode('::', $parts); + $resolved = $fqsenResolver->resolve($fqsenParts[0], $context); + + if (!array_key_exists(1, $fqsenParts)) { + return $resolved; + } + + return new Fqsen($resolved . '::' . $fqsenParts[1]); + } + + /** + * Returns the structural element this tag refers to. + */ + public function getReference(): Fqsen + { + return $this->refers; + } + + /** + * Returns a string representation of this tag. + */ + public function __toString(): string + { + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $refers = (string) $this->refers; + + return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Var_.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Var_.php new file mode 100644 index 0000000..495d16f --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Var_.php @@ -0,0 +1,68 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\Type; +use Webmozart\Assert\Assert; + +/** + * Reflection class for a {@}var tag in a Docblock. + */ +final class Var_ extends TagWithType +{ + protected ?string $variableName = ''; + + public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) + { + Assert::string($variableName); + + $this->name = 'var'; + $this->variableName = $variableName; + $this->type = $type; + $this->description = $description; + } + + /** + * Returns the variable's name. + */ + public function getVariableName(): ?string + { + return $this->variableName; + } + + /** + * Returns a string representation for this tag. + */ + public function __toString(): string + { + if ($this->description !== null) { + $description = $this->description->render(); + } else { + $description = ''; + } + + if ($this->variableName !== null && $this->variableName !== '') { + $variableName = '$' . $this->variableName; + } else { + $variableName = ''; + } + + $type = (string) $this->type; + + return $type + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Version.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Version.php new file mode 100644 index 0000000..951c8e5 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Version.php @@ -0,0 +1,105 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\Types\Context as TypeContext; +use Webmozart\Assert\Assert; + +use function preg_match; + +/** + * Reflection class for a {@}version tag in a Docblock. + */ +final class Version extends BaseTag +{ + protected string $name = 'version'; + + /** + * PCRE regular expression matching a version vector. + * Assumes the "x" modifier. + */ + public const REGEX_VECTOR = '(?: + # Normal release vectors. + \d\S* + | + # VCS version vectors. Per PHPCS, they are expected to + # follow the form of the VCS name, followed by ":", followed + # by the version vector itself. + # By convention, popular VCSes like CVS, SVN and GIT use "$" + # around the actual version vector. + [^\s\:]+\:\s*\$[^\$]+\$ + )'; + + /** @var string|null The version vector. */ + private ?string $version = null; + + public function __construct(?string $version = null, ?Description $description = null) + { + Assert::nullOrStringNotEmpty($version); + + $this->version = $version; + $this->description = $description; + } + + public static function create( + ?string $body, + ?DescriptionFactory $descriptionFactory = null, + ?TypeContext $context = null + ): ?self { + if ($body === null || $body === '') { + return new static(); + } + + $matches = []; + if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { + return null; + } + + $description = null; + if ($descriptionFactory !== null) { + $description = $descriptionFactory->create($matches[2] ?? '', $context); + } + + return new static( + $matches[1], + $description + ); + } + + /** + * Gets the version section of the tag. + */ + public function getVersion(): ?string + { + return $this->version; + } + + /** + * Returns a string representation for this tag. + */ + public function __toString(): string + { + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $version = (string) $this->version; + + return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlockFactory.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlockFactory.php new file mode 100644 index 0000000..bdd29d1 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlockFactory.php @@ -0,0 +1,284 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +use InvalidArgumentException; +use LogicException; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\TagFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory; +use Webmozart\Assert\Assert; + +use function array_shift; +use function count; +use function explode; +use function is_object; +use function method_exists; +use function preg_match; +use function preg_replace; +use function str_replace; +use function strpos; +use function substr; +use function trim; + +final class DocBlockFactory implements DocBlockFactoryInterface +{ + private DocBlock\DescriptionFactory $descriptionFactory; + + private TagFactory $tagFactory; + + /** + * Initializes this factory with the required subcontractors. + */ + public function __construct(DescriptionFactory $descriptionFactory, TagFactory $tagFactory) + { + $this->descriptionFactory = $descriptionFactory; + $this->tagFactory = $tagFactory; + } + + /** + * Factory method for easy instantiation. + * + * @param array<string, class-string<Tag>|Factory> $additionalTags + */ + public static function createInstance(array $additionalTags = []): DocBlockFactoryInterface + { + $fqsenResolver = new FqsenResolver(); + $tagFactory = StandardTagFactory::createInstance($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + + $docBlockFactory = new self($descriptionFactory, $tagFactory); + foreach ($additionalTags as $tagName => $tagHandler) { + $docBlockFactory->registerTagHandler($tagName, $tagHandler); + } + + return $docBlockFactory; + } + + /** + * @param object|string $docblock A string containing the DocBlock to parse or an object supporting the + * getDocComment method (such as a ReflectionClass object). + */ + public function create($docblock, ?Types\Context $context = null, ?Location $location = null): DocBlock + { + if (is_object($docblock)) { + if (!method_exists($docblock, 'getDocComment')) { + $exceptionMessage = 'Invalid object passed; the given object must support the getDocComment method'; + + throw new InvalidArgumentException($exceptionMessage); + } + + $docblock = $docblock->getDocComment(); + Assert::string($docblock); + } + + Assert::stringNotEmpty($docblock); + + if ($context === null) { + $context = new Types\Context(''); + } + + $parts = $this->splitDocBlock($this->stripDocComment($docblock)); + + [$templateMarker, $summary, $description, $tags] = $parts; + + return new DocBlock( + $summary, + $description ? $this->descriptionFactory->create($description, $context) : null, + $this->parseTagBlock($tags, $context), + $context, + $location, + $templateMarker === '#@+', + $templateMarker === '#@-' + ); + } + + /** + * @param class-string<Tag>|Factory $handler + */ + public function registerTagHandler(string $tagName, $handler): void + { + $this->tagFactory->registerTagHandler($tagName, $handler); + } + + /** + * Strips the asterisks from the DocBlock comment. + * + * @param string $comment String containing the comment text. + */ + private function stripDocComment(string $comment): string + { + $comment = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]?(.*)?#u', '$1', $comment); + Assert::string($comment); + $comment = trim($comment); + + // reg ex above is not able to remove */ from a single line docblock + if (substr($comment, -2) === '*/') { + $comment = trim(substr($comment, 0, -2)); + } + + return str_replace(["\r\n", "\r"], "\n", $comment); + } + + // phpcs:disable + + /** + * Splits the DocBlock into a template marker, summary, description and block of tags. + * + * @param string $comment Comment to split into the sub-parts. + * + * @return string[] containing the template marker (if any), summary, description and a string containing the tags. + * + * @author Mike van Riel <me@mikevanriel.com> for extending the regex with template marker support. + * + * @author Richard van Velzen (@_richardJ) Special thanks to Richard for the regex responsible for the split. + */ + private function splitDocBlock(string $comment): array + { + // phpcs:enable + // Performance improvement cheat: if the first character is an @ then only tags are in this DocBlock. This + // method does not split tags so we return this verbatim as the fourth result (tags). This saves us the + // performance impact of running a regular expression + if (strpos($comment, '@') === 0) { + return ['', '', '', $comment]; + } + + // clears all extra horizontal whitespace from the line endings to prevent parsing issues + $comment = preg_replace('/\h*$/Sum', '', $comment); + Assert::string($comment); + /* + * Splits the docblock into a template marker, summary, description and tags section. + * + * - The template marker is empty, #@+ or #@- if the DocBlock starts with either of those (a newline may + * occur after it and will be stripped). + * - The short description is started from the first character until a dot is encountered followed by a + * newline OR two consecutive newlines (horizontal whitespace is taken into account to consider spacing + * errors). This is optional. + * - The long description, any character until a new line is encountered followed by an @ and word + * characters (a tag). This is optional. + * - Tags; the remaining characters + * + * Big thanks to RichardJ for contributing this Regular Expression + */ + preg_match( + '/ + \A + # 1. Extract the template marker + (?:(\#\@\+|\#\@\-)\n?)? + + # 2. Extract the summary + (?: + (?! @\pL ) # The summary may not start with an @ + ( + [^\n.]+ + (?: + (?! \. \n | \n{2} ) # End summary upon a dot followed by newline or two newlines + [\n.]* (?! [ \t]* @\pL ) # End summary when an @ is found as first character on a new line + [^\n.]+ # Include anything else + )* + \.? + )? + ) + + # 3. Extract the description + (?: + \s* # Some form of whitespace _must_ precede a description because a summary must be there + (?! @\pL ) # The description may not start with an @ + ( + [^\n]+ + (?: \n+ + (?! [ \t]* @\pL ) # End description when an @ is found as first character on a new line + [^\n]+ # Include anything else + )* + ) + )? + + # 4. Extract the tags (anything that follows) + (\s+ [\s\S]*)? # everything that follows + /ux', + $comment, + $matches + ); + array_shift($matches); + + while (count($matches) < 4) { + $matches[] = ''; + } + + return $matches; + } + + /** + * Creates the tag objects. + * + * @param string $tags Tag block to parse. + * @param Types\Context $context Context of the parsed Tag + * + * @return DocBlock\Tag[] + */ + private function parseTagBlock(string $tags, Types\Context $context): array + { + $tags = $this->filterTagBlock($tags); + if ($tags === null) { + return []; + } + + $result = []; + $lines = $this->splitTagBlockIntoTagLines($tags); + foreach ($lines as $key => $tagLine) { + $result[$key] = $this->tagFactory->create(trim($tagLine), $context); + } + + return $result; + } + + /** + * @return string[] + */ + private function splitTagBlockIntoTagLines(string $tags): array + { + $result = []; + foreach (explode("\n", $tags) as $tagLine) { + if ($tagLine !== '' && strpos($tagLine, '@') === 0) { + $result[] = $tagLine; + } else { + $result[count($result) - 1] .= "\n" . $tagLine; + } + } + + return $result; + } + + private function filterTagBlock(string $tags): ?string + { + $tags = trim($tags); + if (!$tags) { + return null; + } + + if ($tags[0] !== '@') { + // @codeCoverageIgnoreStart + // Can't simulate this; this only happens if there is an error with the parsing of the DocBlock that + // we didn't foresee. + + throw new LogicException('A tag block started with text instead of an at-sign(@): ' . $tags); + + // @codeCoverageIgnoreEnd + } + + return $tags; + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/DocBlockFactoryInterface.php b/vendor/phpdocumentor/reflection-docblock/src/DocBlockFactoryInterface.php new file mode 100644 index 0000000..cacc382 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/DocBlockFactoryInterface.php @@ -0,0 +1,23 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection; + +use phpDocumentor\Reflection\DocBlock\Tag; + +// phpcs:ignore SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix +interface DocBlockFactoryInterface +{ + /** + * Factory method for easy instantiation. + * + * @param array<string, class-string<Tag>> $additionalTags + */ + public static function createInstance(array $additionalTags = []): self; + + /** + * @param string|object $docblock + */ + public function create($docblock, ?Types\Context $context = null, ?Location $location = null): DocBlock; +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/Exception/CannotCreateTag.php b/vendor/phpdocumentor/reflection-docblock/src/Exception/CannotCreateTag.php new file mode 100644 index 0000000..a66884a --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/Exception/CannotCreateTag.php @@ -0,0 +1,11 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\Exception; + +use LogicException; + +final class CannotCreateTag extends LogicException +{ +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/Exception/ParserException.php b/vendor/phpdocumentor/reflection-docblock/src/Exception/ParserException.php new file mode 100644 index 0000000..2a2ce80 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/Exception/ParserException.php @@ -0,0 +1,19 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\Exception; + +use InvalidArgumentException; + +final class ParserException extends InvalidArgumentException implements ReflectionDocblockException +{ + public static function from(\PHPStan\PhpDocParser\Parser\ParserException $exception): self + { + return new self( + 'Failed to parse docblock: ' . $exception->getMessage(), + 0, + $exception + ); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/Exception/PcreException.php b/vendor/phpdocumentor/reflection-docblock/src/Exception/PcreException.php new file mode 100644 index 0000000..b8b6da8 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/Exception/PcreException.php @@ -0,0 +1,44 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\Exception; + +use InvalidArgumentException; + +use const PREG_BACKTRACK_LIMIT_ERROR; +use const PREG_BAD_UTF8_ERROR; +use const PREG_BAD_UTF8_OFFSET_ERROR; +use const PREG_INTERNAL_ERROR; +use const PREG_JIT_STACKLIMIT_ERROR; +use const PREG_NO_ERROR; +use const PREG_RECURSION_LIMIT_ERROR; + +final class PcreException extends InvalidArgumentException +{ + public static function createFromPhpError(int $errorCode): self + { + switch ($errorCode) { + case PREG_BACKTRACK_LIMIT_ERROR: + return new self('Backtrack limit error'); + + case PREG_RECURSION_LIMIT_ERROR: + return new self('Recursion limit error'); + + case PREG_BAD_UTF8_ERROR: + return new self('Bad UTF8 error'); + + case PREG_BAD_UTF8_OFFSET_ERROR: + return new self('Bad UTF8 offset error'); + + case PREG_JIT_STACKLIMIT_ERROR: + return new self('Jit stacklimit error'); + + case PREG_NO_ERROR: + case PREG_INTERNAL_ERROR: + default: + } + + return new self('Unknown Pcre error'); + } +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/Exception/ReflectionDocblockException.php b/vendor/phpdocumentor/reflection-docblock/src/Exception/ReflectionDocblockException.php new file mode 100644 index 0000000..1cb6641 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/Exception/ReflectionDocblockException.php @@ -0,0 +1,11 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\Exception; + +use Throwable; + +interface ReflectionDocblockException extends Throwable +{ +} diff --git a/vendor/phpdocumentor/reflection-docblock/src/Utils.php b/vendor/phpdocumentor/reflection-docblock/src/Utils.php new file mode 100644 index 0000000..fe311c9 --- /dev/null +++ b/vendor/phpdocumentor/reflection-docblock/src/Utils.php @@ -0,0 +1,62 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +use phpDocumentor\Reflection\Exception\PcreException; +use Webmozart\Assert\Assert; + +use function preg_last_error; +use function preg_split as php_preg_split; + +abstract class Utils +{ + /** + * Wrapper function for phps preg_split + * + * This function is inspired by {@link https://github.com/thecodingmachine/safe/blob/master/generated/pcre.php}. But + * since this library is all about performance we decided to strip everything we don't need. Reducing the amount + * of files that have to be loaded, etc. + * + * @param string $pattern The pattern to search for, as a string. + * @param string $subject The input string. + * @param int $limit If specified, then only substrings up to limit are returned with the + * rest of the string being placed in the last substring. A limit of -1 or 0 means "no limit". + * @param int $flags flags can be any combination of the following flags (combined with the | bitwise operator): + * *PREG_SPLIT_NO_EMPTY* + * If this flag is set, only non-empty pieces will be returned by preg_split(). + * *PREG_SPLIT_DELIM_CAPTURE* + * If this flag is set, parenthesized expression in the delimiter pattern will be captured + * and returned as well. + * *PREG_SPLIT_OFFSET_CAPTURE* + * If this flag is set, for every occurring match the appendant string offset will also be returned. + * Note that this changes the return value in an array where every element is an array consisting of the + * matched string at offset 0 and its string offset into subject at offset 1. + * + * @return string[] Returns an array containing substrings of subject + * split along boundaries matched by pattern + * + * @throws PcreException + */ + public static function pregSplit(string $pattern, string $subject, int $limit = -1, int $flags = 0): array + { + $parts = php_preg_split($pattern, $subject, $limit, $flags); + if ($parts === false) { + throw PcreException::createFromPhpError(preg_last_error()); + } + + Assert::allString($parts); + + return $parts; + } +} diff --git a/vendor/phpdocumentor/type-resolver/.phpdoc/template/base.html.twig b/vendor/phpdocumentor/type-resolver/.phpdoc/template/base.html.twig new file mode 100644 index 0000000..194b219 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/.phpdoc/template/base.html.twig @@ -0,0 +1,15 @@ +{% extends 'layout.html.twig' %} + +{% set topMenu = { + "menu": [ + { "name": "About", "url": "https://phpdoc.org/"}, + { "name": "Components", "url": "https://phpdoc.org/components.html"}, + { "name": "Documentation", "url": "https://docs.phpdoc.org/"}, + ], + "social": [ + { "iconClass": "fab fa-mastodon", "url": "https://phpc.social/@phpdoc"}, + { "iconClass": "fab fa-github", "url": "https://github.com/phpdocumentor/typeresolver"}, + { "iconClass": "fas fa-envelope-open-text", "url": "https://github.com/orgs/phpDocumentor/discussions"} + ] +} +%} diff --git a/vendor/phpdocumentor/type-resolver/LICENSE b/vendor/phpdocumentor/type-resolver/LICENSE new file mode 100644 index 0000000..792e404 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2010 Mike van Riel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/phpdocumentor/type-resolver/README.md b/vendor/phpdocumentor/type-resolver/README.md new file mode 100644 index 0000000..f30d3a2 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/README.md @@ -0,0 +1,177 @@ +[](https://opensource.org/licenses/MIT) + +[](https://coveralls.io/github/phpDocumentor/TypeResolver?branch=1.x) +[](https://scrutinizer-ci.com/g/phpDocumentor/TypeResolver/?branch=1.x) +[](https://scrutinizer-ci.com/g/phpDocumentor/TypeResolver/?branch=1.x) + + + +TypeResolver and FqsenResolver +============================== + +The specification on types in DocBlocks (PSR-5) describes various keywords and special constructs +but also how to statically resolve the partial name of a Class into a Fully Qualified Class Name (FQCN). + +PSR-5 also introduces an additional way to describe deeper elements than Classes, Interfaces and Traits +called the Fully Qualified Structural Element Name (FQSEN). Using this it is possible to refer to methods, +properties and class constants but also functions and global constants. + +This package provides two Resolvers that are capable of + +1. Returning a series of Value Object for given expression while resolving any partial class names, and +2. Returning an FQSEN object after resolving any partial Structural Element Names into Fully Qualified Structural + Element names. + +## Installing + +The easiest way to install this library is with [Composer](https://getcomposer.org) using the following command: + + $ composer require phpdocumentor/type-resolver + +## Examples + +Ready to dive in and don't want to read through all that text below? Just consult the [examples](examples) folder and check which type of action that your want to accomplish. + +## On Types and Element Names + +This component can be used in one of two ways + +1. To resolve a Type or +2. To resolve a Fully Qualified Structural Element Name + +The big difference between these two is in the number of things it can resolve. + +The TypeResolver can resolve: + +- a php primitive or pseudo-primitive such as a string or void (`@var string` or `@return void`). +- a composite such as an array of string (`@var string[]`). +- a compound such as a string or integer (`@var string|integer`). +- an array expression (`@var (string|TypeResolver)[]`) +- an object or interface such as the TypeResolver class (`@var TypeResolver` + or `@var \phpDocumentor\Reflection\TypeResolver`) + + > please note that if you want to pass partial class names that additional steps are necessary, see the + > chapter `Resolving partial classes and FQSENs` for more information. + +Where the FqsenResolver can resolve: + +- Constant expressions (i.e. `@see \MyNamespace\MY_CONSTANT`) +- Function expressions (i.e. `@see \MyNamespace\myFunction()`) +- Class expressions (i.e. `@see \MyNamespace\MyClass`) +- Interface expressions (i.e. `@see \MyNamespace\MyInterface`) +- Trait expressions (i.e. `@see \MyNamespace\MyTrait`) +- Class constant expressions (i.e. `@see \MyNamespace\MyClass::MY_CONSTANT`) +- Property expressions (i.e. `@see \MyNamespace\MyClass::$myProperty`) +- Method expressions (i.e. `@see \MyNamespace\MyClass::myMethod()`) + +## Resolving a type + +In order to resolve a type you will have to instantiate the class `\phpDocumentor\Reflection\TypeResolver` and call its `resolve` method like this: + +```php +$typeResolver = new \phpDocumentor\Reflection\TypeResolver(); +$type = $typeResolver->resolve('string|integer'); +``` + +In this example you will receive a Value Object of class `\phpDocumentor\Reflection\Types\Compound` that has two +elements, one of type `\phpDocumentor\Reflection\Types\String_` and one of type +`\phpDocumentor\Reflection\Types\Integer`. + +The real power of this resolver is in its capability to expand partial class names into fully qualified class names; but in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will inform the resolver in which namespace the given expression occurs and which namespace aliases (or imports) apply. + +### Resolving nullable types + +Php 7.1 introduced nullable types e.g. `?string`. Type resolver will resolve the original type without the nullable notation `?` +just like it would do without the `?`. After that the type is wrapped in a `\phpDocumentor\Reflection\Types\Nullable` object. +The `Nullable` type has a method to fetch the actual type. + +## Resolving an FQSEN + +A Fully Qualified Structural Element Name is a reference to another element in your code bases and can be resolved using the `\phpDocumentor\Reflection\FqsenResolver` class' `resolve` method, like this: + +```php +$fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver(); +$fqsen = $fqsenResolver->resolve('\phpDocumentor\Reflection\FqsenResolver::resolve()'); +``` + +In this example we resolve a Fully Qualified Structural Element Name (meaning that it includes the full namespace, class name and element name) and receive a Value Object of type `\phpDocumentor\Reflection\Fqsen`. + +The real power of this resolver is in its capability to expand partial element names into Fully Qualified Structural Element Names; but in order to do that we need an additional `\phpDocumentor\Reflection\Types\Context` class that will inform the resolver in which namespace the given expression occurs and which namespace aliases (or imports) apply. + +## Resolving partial Classes and Structural Element Names + +Perhaps the best feature of this library is that it knows how to resolve partial class names into fully qualified class names. + +For example, you have this file: + +```php +namespace My\Example; + +use phpDocumentor\Reflection\Types; + +class Classy +{ + /** + * @var Types\Context + * @see Classy::otherFunction() + */ + public function __construct($context) {} + + public function otherFunction(){} +} +``` + +Suppose that you would want to resolve (and expand) the type in the `@var` tag and the element name in the `@see` tag. + +For the resolvers to know how to expand partial names you have to provide a bit of _Context_ for them by instantiating a new class named `\phpDocumentor\Reflection\Types\Context` with the name of the namespace and the aliases that are in play. + +### Creating a Context + +You can do this by manually creating a Context like this: + +```php +$context = new \phpDocumentor\Reflection\Types\Context( + '\My\Example', + [ 'Types' => '\phpDocumentor\Reflection\Types'] +); +``` + +Or by using the `\phpDocumentor\Reflection\Types\ContextFactory` to instantiate a new context based on a Reflector object or by providing the namespace that you'd like to extract and the source code of the file in which the given type expression occurs. + +```php +$contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory(); +$context = $contextFactory->createFromReflector(new ReflectionMethod('\My\Example\Classy', '__construct')); +``` + +or + +```php +$contextFactory = new \phpDocumentor\Reflection\Types\ContextFactory(); +$context = $contextFactory->createForNamespace('\My\Example', file_get_contents('My/Example/Classy.php')); +``` + +### Using the Context + +After you have obtained a Context it is just a matter of passing it along with the `resolve` method of either Resolver class as second argument and the Resolvers will take this into account when resolving partial names. + +To obtain the resolved class name for the `@var` tag in the example above you can do: + +```php +$typeResolver = new \phpDocumentor\Reflection\TypeResolver(); +$type = $typeResolver->resolve('Types\Context', $context); +``` + +When you do this you will receive an object of class `\phpDocumentor\Reflection\Types\Object_` for which you can call the `getFqsen` method to receive a Value Object that represents the complete FQSEN. So that would be `phpDocumentor\Reflection\Types\Context`. + +> Why is the FQSEN wrapped in another object `Object_`? +> +> The resolve method of the TypeResolver only returns object with the interface `Type` and the FQSEN is a common type that does not represent a Type. Also: in some cases a type can represent an "Untyped Object", meaning that it is an object (signified by the `object` keyword) but does not refer to a specific element using an FQSEN. + +Another example is on how to resolve the FQSEN of a method as can be seen with the `@see` tag in the example above. To resolve that you can do the following: + +```php +$fqsenResolver = new \phpDocumentor\Reflection\FqsenResolver(); +$type = $fqsenResolver->resolve('Classy::otherFunction()', $context); +``` + +Because Classy is a Class in the current namespace its FQSEN will have the `My\Example` namespace and by calling the `resolve` method of the FQSEN Resolver you will receive an `Fqsen` object that refers to `\My\Example\Classy::otherFunction()`. diff --git a/vendor/phpdocumentor/type-resolver/composer.json b/vendor/phpdocumentor/type-resolver/composer.json new file mode 100644 index 0000000..631eca6 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/composer.json @@ -0,0 +1,51 @@ +{ + "name": "phpdocumentor/type-resolver", + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "require": { + "php": "^7.4 || ^8.0", + "phpdocumentor/reflection-common": "^2.0", + "phpstan/phpdoc-parser": "^2.0", + "doctrine/deprecations": "^1.0" + }, + "require-dev": { + "ext-tokenizer": "*", + "phpunit/phpunit": "^9.5", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/extension-installer": "^1.4", + "phpbench/phpbench": "^1.2", + "psalm/phar": "^4" + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "phpDocumentor\\Reflection\\": ["tests/unit", "tests/benchmark"] + } + }, + "extra": { + "branch-alias": { + "dev-1.x": "1.x-dev", + "dev-2.x": "2.x-dev" + } + }, + "config": { + "platform": { + "php": "7.4.0" + }, + "allow-plugins": { + "phpstan/extension-installer": true + } + } +} diff --git a/vendor/phpdocumentor/type-resolver/docs/generics.rst b/vendor/phpdocumentor/type-resolver/docs/generics.rst new file mode 100644 index 0000000..f306432 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/docs/generics.rst @@ -0,0 +1,29 @@ +======== +Generics +======== + +This project is capable of parsing generics notation as used by PHPStan. But it has some limitations, in regards to +PHPStan. The main difference is that PHPStan does scan your whole codebase to find out what types are used in generics, +while this library only parses the types as they are given to it. + +This means that if you use a generic type like. + +.. code:: php + + namespace MyApp; + + /** + * @template T of Item + */ + class Collection { + + /** + * @return T[] + */ + public function getItems() : array { + // ... + } + } + +The type resolver will not be able to determine what ``T`` is. In fact there is no difference between ``T`` and any other relative +used classname like ``Item``. The resolver will handle ``T`` as a normal class name. In this example it will resolve ``T`` to ``\MyApp\T``. diff --git a/vendor/phpdocumentor/type-resolver/docs/getting-started.rst b/vendor/phpdocumentor/type-resolver/docs/getting-started.rst new file mode 100644 index 0000000..1c8ea67 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/docs/getting-started.rst @@ -0,0 +1,32 @@ +=============== +Getting started +=============== + +On this page you will find a brief introduction on how to use the TypeResolver in your project. + +Installation +============ + +The TypeResolver is available on Packagist and can be installed using Composer: + +.. code:: bash + composer require phpdocumentor/type-resolver + + +General usage +=========== + +After you installed the TypeResolver you can use it in your project. This can be done by creating a new instance +of the :php:class:`\phpDocumentor\Reflection\TypeResolver` class and calling +:php:method:`\phpDocumentor\Reflection\TypeResolver::resolve()` with the type you want to resolve. + +.. code:: php + $typeResolver = new \phpDocumentor\Reflection\TypeResolver(); + $type = $typeResolver->resolve('string'); + echo get_class($type); // phpDocumentor\Reflection\Types\String_ + +The real power of this resolver is in its capability to expand partial class names into fully qualified class names; +but in order to do that we need an additional :php:class:`\phpDocumentor\Reflection\Types\Context` class that +will inform the resolver in which namespace the given expression occurs and which namespace aliases (or imports) apply. + +Read more about the Context class in the next section. diff --git a/vendor/phpdocumentor/type-resolver/docs/index.rst b/vendor/phpdocumentor/type-resolver/docs/index.rst new file mode 100644 index 0000000..1512983 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/docs/index.rst @@ -0,0 +1,19 @@ +============= +Type resolver +============= + +This project part of the phpDocumentor project. It is capable of creating an object structure of the type +specifications found in the PHPDoc blocks of a project. This can be useful for static analysis of a project +or other behavior that requires knowledge of the types used in a project like automatically build forms. + +This project aims to cover all types that are available in PHPDoc and PHP itself. And is open for extension by +third party developers. + +.. toctree:: + :maxdepth: 2 + :hidden: + + index + getting-started + generics + upgrade-v1-to-v2 diff --git a/vendor/phpdocumentor/type-resolver/docs/upgrade-v1-to-v2.rst b/vendor/phpdocumentor/type-resolver/docs/upgrade-v1-to-v2.rst new file mode 100644 index 0000000..4f63ad3 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/docs/upgrade-v1-to-v2.rst @@ -0,0 +1,40 @@ +==================== +Upgrade to Version 2 +==================== + +Version 2 of the Type Resolver introduces several breaking changes and new features. This guide will help you +upgrade your codebase to be compatible with the latest version. The usage of the TypeResolver remains the same. However, +some classes have been moved or replaced, and the minimum PHP version requirement has been raised. + +PHP Version +----------- + +Version 2 requires PHP 7.4 or higher. We have been supporting PHP 7.3 in version 1, but due to changing constraints +in our dependencies, we have had to raise the minimum PHP version. At the moment of writing this, PHP 7.3 is used by 2% +of all installations of this package according to Packagist. We believe this is a reasonable trade-off to ensure we +can continue to deliver new features and improvements. + +Moved classes +------------- + +- ``phpDocumentor\Reflection\Types\InterfaceString`` => :php:class:`phpDocumentor\Reflection\PseudoTypes\InterfaceString` +- ``phpDocumentor\Reflection\Types\ClassString`` => :php:class:`phpDocumentor\Reflection\PseudoTypes\ClassString` +- ``phpDocumentor\Reflection\Types\ArrayKey`` => :php:class:`phpDocumentor\Reflection\PseudoTypes\ArrayKey` +- ``phpDocumentor\Reflection\Types\True_`` => :php:class:`phpDocumentor\Reflection\PseudoTypes\True_` +- ``phpDocumentor\Reflection\Types\False_`` => :php:class:`phpDocumentor\Reflection\PseudoTypes\False_` + +Replaced classes +----------------- + +- ``phpDocumentor\Reflection\Types\Collection`` => :php:class:`phpDocumentor\Reflection\PseudoTypes\Generic` + +Since the introduction of generics in PHP this library was not capable of parsing them correctly. The old Collection +was blocking the use of generics. The new Generic type is a representation of generics like supported in the eco system. + +Changed implementations +----------------------- + +:php:class:`phpDocumentor\Reflection\PseudoTypes\InterfaceString`, :php:class:`phpDocumentor\Reflection\PseudoTypes\ClassString` and +:php:class:`phpDocumentor\Reflection\PseudoTypes\TraitString` are no longer returning a :php:class:`phpDocumentor\Reflection\Fqsen` since +support for generics these classes can have type arguments like any other generic. + diff --git a/vendor/phpdocumentor/type-resolver/phpdoc.dist.xml b/vendor/phpdocumentor/type-resolver/phpdoc.dist.xml new file mode 100644 index 0000000..6c98991 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/phpdoc.dist.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<phpdocumentor + configVersion="3" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="https://www.phpdoc.org" + xsi:noNamespaceSchemaLocation="data/xsd/phpdoc.xsd" +> + <title>Type Resolver</title> + <paths> + <output>build/docs</output> + </paths> + <version number="0.2.0"> + <folder>latest</folder> + <api> + <source dsn="./"> + <path>src/</path> + </source> + <output>api</output> + <ignore hidden="true" symlinks="true"> + <path>tests/**/*</path> + <path>build/**/*</path> + <path>var/**/*</path> + <path>vendor/**/*</path> + </ignore> + <extensions> + <extension>php</extension> + </extensions> + <ignore-tags> + <ignore-tag>template</ignore-tag> + <ignore-tag>template-extends</ignore-tag> + <ignore-tag>template-implements</ignore-tag> + <ignore-tag>extends</ignore-tag> + <ignore-tag>implements</ignore-tag> + </ignore-tags> + <default-package-name>phpDocumentor</default-package-name> + </api> + <guide> + <source dsn="."> + <path>docs</path> + </source> + <output>guides</output> + </guide> + </version> + <setting name="guides.enabled" value="true"/> + <template name="default" /> +</phpdocumentor> diff --git a/vendor/phpdocumentor/type-resolver/src/FqsenResolver.php b/vendor/phpdocumentor/type-resolver/src/FqsenResolver.php new file mode 100644 index 0000000..068fa20 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/FqsenResolver.php @@ -0,0 +1,80 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +use InvalidArgumentException; +use phpDocumentor\Reflection\Types\Context; + +use function explode; +use function implode; +use function strpos; + +/** + * Resolver for Fqsen using Context information + * + * @psalm-immutable + */ +class FqsenResolver +{ + /** @var string Definition of the NAMESPACE operator in PHP */ + private const OPERATOR_NAMESPACE = '\\'; + + public function resolve(string $fqsen, ?Context $context = null): Fqsen + { + if ($context === null) { + $context = new Context(''); + } + + if ($this->isFqsen($fqsen)) { + return new Fqsen($fqsen); + } + + return $this->resolvePartialStructuralElementName($fqsen, $context); + } + + /** + * Tests whether the given type is a Fully Qualified Structural Element Name. + */ + private function isFqsen(string $type): bool + { + return strpos($type, self::OPERATOR_NAMESPACE) === 0; + } + + /** + * Resolves a partial Structural Element Name (i.e. `Reflection\DocBlock`) to its FQSEN representation + * (i.e. `\phpDocumentor\Reflection\DocBlock`) based on the Namespace and aliases mentioned in the Context. + * + * @throws InvalidArgumentException When type is not a valid FQSEN. + */ + private function resolvePartialStructuralElementName(string $type, Context $context): Fqsen + { + $typeParts = explode(self::OPERATOR_NAMESPACE, $type, 2); + + $namespaceAliases = $context->getNamespaceAliases(); + + // if the first segment is not an alias; prepend namespace name and return + if (!isset($namespaceAliases[$typeParts[0]])) { + $namespace = $context->getNamespace(); + if ($namespace !== '') { + $namespace .= self::OPERATOR_NAMESPACE; + } + + return new Fqsen(self::OPERATOR_NAMESPACE . $namespace . $type); + } + + $typeParts[0] = $namespaceAliases[$typeParts[0]]; + + return new Fqsen(self::OPERATOR_NAMESPACE . implode(self::OPERATOR_NAMESPACE, $typeParts)); + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoType.php b/vendor/phpdocumentor/type-resolver/src/PseudoType.php new file mode 100644 index 0000000..dd91ed7 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoType.php @@ -0,0 +1,19 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +interface PseudoType extends Type +{ + public function underlyingType(): Type; +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ArrayKey.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ArrayKey.php new file mode 100644 index 0000000..ce3dd80 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ArrayKey.php @@ -0,0 +1,44 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\AggregatedType; +use phpDocumentor\Reflection\Types\Compound; +use phpDocumentor\Reflection\Types\Integer; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type `array-key`. + * + * @psalm-immutable + */ +class ArrayKey extends AggregatedType implements PseudoType +{ + public function __construct() + { + parent::__construct([new String_(), new Integer()], '|'); + } + + public function underlyingType(): Type + { + return new Compound([new String_(), new Integer()]); + } + + public function __toString(): string + { + return 'array-key'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ArrayShape.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ArrayShape.php new file mode 100644 index 0000000..bceac60 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ArrayShape.php @@ -0,0 +1,53 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Array_; +use phpDocumentor\Reflection\Types\Mixed_; + +use function implode; + +/** @psalm-immutable */ +class ArrayShape extends Array_ implements PseudoType +{ + /** @var ArrayShapeItem[] */ + private $items; + + public function __construct(ArrayShapeItem ...$items) + { + parent::__construct(new Mixed_(), new ArrayKey()); + + $this->items = $items; + } + + /** + * @return ArrayShapeItem[] + */ + public function getItems(): array + { + return $this->items; + } + + public function underlyingType(): Type + { + return new Array_(new Mixed_(), new ArrayKey()); + } + + public function __toString(): string + { + return 'array{' . implode(', ', $this->items) . '}'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ArrayShapeItem.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ArrayShapeItem.php new file mode 100644 index 0000000..81187d9 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ArrayShapeItem.php @@ -0,0 +1,18 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +class ArrayShapeItem extends ShapeItem +{ +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/CallableArray.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/CallableArray.php new file mode 100644 index 0000000..2ccaaf0 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/CallableArray.php @@ -0,0 +1,43 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Array_; +use phpDocumentor\Reflection\Types\Integer; +use phpDocumentor\Reflection\Types\Mixed_; + +/** + * Value Object representing the type 'callable-array'. + * + * @psalm-immutable + */ +final class CallableArray extends Array_ implements PseudoType +{ + public function __construct() + { + parent::__construct(new Mixed_(), new Integer()); + } + + public function underlyingType(): Type + { + return new Array_(new Mixed_(), new Integer()); + } + + public function __toString(): string + { + return 'callable-array'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/CallableString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/CallableString.php new file mode 100644 index 0000000..ff50497 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/CallableString.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type 'callable-string'. + * + * @psalm-immutable + */ +final class CallableString extends String_ implements PseudoType +{ + public function underlyingType(): Type + { + return new String_(); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'callable-string'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ClassString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ClassString.php new file mode 100644 index 0000000..1f5d658 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ClassString.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type 'class-string'. + * + * @psalm-immutable + */ +final class ClassString extends String_ implements PseudoType +{ + /** @var Type|null */ + private $genericType; + + public function __construct(?Type $genericType = null) + { + $this->genericType = $genericType; + } + + public function underlyingType(): Type + { + return new String_(); + } + + public function getGenericType(): ?Type + { + return $this->genericType; + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + if ($this->genericType === null) { + return 'class-string'; + } + + return 'class-string<' . (string) $this->genericType . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ClosedResource.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ClosedResource.php new file mode 100644 index 0000000..bb7dce1 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ClosedResource.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Resource_; + +/** + * Value Object representing the type 'closed-resource'. + * + * @psalm-immutable + */ +final class ClosedResource extends Resource_ implements PseudoType +{ + public function underlyingType(): Type + { + return new Resource_(); + } + + public function __toString(): string + { + return 'closed-resource'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Conditional.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Conditional.php new file mode 100644 index 0000000..dbccd89 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Conditional.php @@ -0,0 +1,90 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Mixed_; + +use function sprintf; + +/** + * Value Object representing the conditional type. + * + * @psalm-immutable + */ +final class Conditional extends Mixed_ implements PseudoType +{ + /** @var bool */ + private $negated; + /** @var Type */ + private $subjectType; + /** @var Type */ + private $targetType; + /** @var Type */ + private $if; + /** @var Type */ + private $else; + + public function __construct(bool $negated, Type $subjectType, Type $targetType, Type $if, Type $else) + { + $this->negated = $negated; + $this->subjectType = $subjectType; + $this->targetType = $targetType; + $this->if = $if; + $this->else = $else; + } + + public function isNegated(): bool + { + return $this->negated; + } + + public function getSubjectType(): Type + { + return $this->subjectType; + } + + public function getTargetType(): Type + { + return $this->targetType; + } + + public function getIf(): Type + { + return $this->if; + } + + public function getElse(): Type + { + return $this->else; + } + + public function underlyingType(): Type + { + return new Mixed_(); + } + + public function __toString(): string + { + return sprintf( + '(%s %s %s ? %s : %s)', + (string) $this->subjectType, + $this->negated ? 'is not' : 'is', + (string) $this->targetType, + (string) $this->if, + (string) $this->else + ); + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ConditionalForParameter.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ConditionalForParameter.php new file mode 100644 index 0000000..a9fccc5 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ConditionalForParameter.php @@ -0,0 +1,90 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Mixed_; + +use function sprintf; + +/** + * Value Object representing the conditional type for parameter. + * + * @psalm-immutable + */ +final class ConditionalForParameter extends Mixed_ implements PseudoType +{ + /** @var bool */ + private $negated; + /** @var string */ + private $parameterName; + /** @var Type */ + private $targetType; + /** @var Type */ + private $if; + /** @var Type */ + private $else; + + public function __construct(bool $negated, string $parameterName, Type $targetType, Type $if, Type $else) + { + $this->negated = $negated; + $this->parameterName = $parameterName; + $this->targetType = $targetType; + $this->if = $if; + $this->else = $else; + } + + public function isNegated(): bool + { + return $this->negated; + } + + public function getParameterName(): string + { + return $this->parameterName; + } + + public function getTargetType(): Type + { + return $this->targetType; + } + + public function getIf(): Type + { + return $this->if; + } + + public function getElse(): Type + { + return $this->else; + } + + public function underlyingType(): Type + { + return new Mixed_(); + } + + public function __toString(): string + { + return sprintf( + '(%s %s %s ? %s : %s)', + '$' . $this->parameterName, + $this->negated ? 'is not' : 'is', + (string) $this->targetType, + (string) $this->if, + (string) $this->else + ); + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ConstExpression.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ConstExpression.php new file mode 100644 index 0000000..a03612a --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ConstExpression.php @@ -0,0 +1,55 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Mixed_; + +use function sprintf; + +/** @psalm-immutable */ +final class ConstExpression extends Mixed_ implements PseudoType +{ + /** @var Type */ + private $owner; + /** @var string */ + private $expression; + + public function __construct(Type $owner, string $expression) + { + $this->owner = $owner; + $this->expression = $expression; + } + + public function getOwner(): Type + { + return $this->owner; + } + + public function getExpression(): string + { + return $this->expression; + } + + public function underlyingType(): Type + { + return new Mixed_(); + } + + public function __toString(): string + { + return sprintf('%s::%s', (string) $this->owner, $this->expression); + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/EnumString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/EnumString.php new file mode 100644 index 0000000..87d1a77 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/EnumString.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type 'enum-string'. + * + * @psalm-immutable + */ +final class EnumString extends String_ implements PseudoType +{ + /** @var Type|null */ + private $genericType; + + public function __construct(?Type $genericType = null) + { + $this->genericType = $genericType; + } + + public function underlyingType(): Type + { + return new String_(); + } + + public function getGenericType(): ?Type + { + return $this->genericType; + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + if ($this->genericType === null) { + return 'enum-string'; + } + + return 'enum-string<' . (string) $this->genericType . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/False_.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/False_.php new file mode 100644 index 0000000..daa7317 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/False_.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link https://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Boolean; + +/** + * Value Object representing the PseudoType 'False', which is a Boolean type. + * + * @psalm-immutable + */ +final class False_ extends Boolean implements PseudoType +{ + public function underlyingType(): Type + { + return new Boolean(); + } + + public function __toString(): string + { + return 'false'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/FloatValue.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/FloatValue.php new file mode 100644 index 0000000..0c3cc96 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/FloatValue.php @@ -0,0 +1,45 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Float_; + +/** @psalm-immutable */ +class FloatValue extends Float_ implements PseudoType +{ + /** @var float */ + private $value; + + public function __construct(float $value) + { + $this->value = $value; + } + + public function getValue(): float + { + return $this->value; + } + + public function underlyingType(): Type + { + return new Float_(); + } + + public function __toString(): string + { + return (string) $this->value; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Generic.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Generic.php new file mode 100644 index 0000000..21e27ac --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Generic.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\Fqsen; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Object_; + +use function implode; + +/** + * Value Object representing a type with generics. + * + * @psalm-immutable + */ +final class Generic extends Object_ +{ + /** @var Type[] */ + private $types; + + /** + * @param Type[] $types + */ + public function __construct(?Fqsen $fqsen, array $types) + { + parent::__construct($fqsen); + + $this->types = $types; + } + + /** + * @return Type[] + */ + public function getTypes(): array + { + return $this->types; + } + + public function __toString(): string + { + $objectType = (string) ($this->fqsen ?? 'object'); + + return $objectType . '<' . implode(', ', $this->types) . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/HtmlEscapedString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/HtmlEscapedString.php new file mode 100644 index 0000000..295c275 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/HtmlEscapedString.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type 'html-escaped-string'. + * + * @psalm-immutable + */ +final class HtmlEscapedString extends String_ implements PseudoType +{ + public function underlyingType(): Type + { + return new String_(); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'html-escaped-string'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntMask.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntMask.php new file mode 100644 index 0000000..a4b50b9 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntMask.php @@ -0,0 +1,54 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Integer; + +use function implode; + +/** + * Value Object representing the `int-mask` type. + * + * @psalm-immutable + */ +final class IntMask extends Integer implements PseudoType +{ + /** @var Type[] */ + private $types; + + public function __construct(Type ...$types) + { + $this->types = $types; + } + + /** + * @return Type[] + */ + public function getTypes(): array + { + return $this->types; + } + + public function underlyingType(): Type + { + return new Integer(); + } + + public function __toString(): string + { + return 'int-mask<' . implode(', ', $this->types) . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntMaskOf.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntMaskOf.php new file mode 100644 index 0000000..80340e6 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntMaskOf.php @@ -0,0 +1,49 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Integer; + +/** + * Value Object representing the `int-mask-of` type. + * + * @psalm-immutable + */ +final class IntMaskOf extends Integer implements PseudoType +{ + /** @var Type */ + private $type; + + public function __construct(Type $type) + { + $this->type = $type; + } + + public function getType(): Type + { + return $this->type; + } + + public function underlyingType(): Type + { + return new Integer(); + } + + public function __toString(): string + { + return 'int-mask-of<' . $this->type . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntegerRange.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntegerRange.php new file mode 100644 index 0000000..c5a3bc5 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntegerRange.php @@ -0,0 +1,61 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Integer; + +/** + * Value Object representing the type 'int'. + * + * @psalm-immutable + */ +final class IntegerRange extends Integer implements PseudoType +{ + /** @var string */ + private $minValue; + + /** @var string */ + private $maxValue; + + public function __construct(string $minValue, string $maxValue) + { + $this->minValue = $minValue; + $this->maxValue = $maxValue; + } + + public function underlyingType(): Type + { + return new Integer(); + } + + public function getMinValue(): string + { + return $this->minValue; + } + + public function getMaxValue(): string + { + return $this->maxValue; + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'int<' . $this->minValue . ', ' . $this->maxValue . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntegerValue.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntegerValue.php new file mode 100644 index 0000000..4cc68de --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntegerValue.php @@ -0,0 +1,45 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Integer; + +/** @psalm-immutable */ +final class IntegerValue extends Integer implements PseudoType +{ + /** @var int */ + private $value; + + public function __construct(int $value) + { + $this->value = $value; + } + + public function getValue(): int + { + return $this->value; + } + + public function underlyingType(): Type + { + return new Integer(); + } + + public function __toString(): string + { + return (string) $this->value; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/InterfaceString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/InterfaceString.php new file mode 100644 index 0000000..719914c --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/InterfaceString.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type `interface-string`. + * + * @psalm-immutable + */ +final class InterfaceString extends String_ implements PseudoType +{ + /** @var Type|null */ + private $genericType; + + public function __construct(?Type $genericType = null) + { + $this->genericType = $genericType; + } + + public function underlyingType(): Type + { + return new String_(); + } + + public function getGenericType(): ?Type + { + return $this->genericType; + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + if ($this->genericType === null) { + return 'interface-string'; + } + + return 'interface-string<' . (string) $this->genericType . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/KeyOf.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/KeyOf.php new file mode 100644 index 0000000..0f26b09 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/KeyOf.php @@ -0,0 +1,48 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing the `key-of` type. + * + * @psalm-immutable + */ +final class KeyOf extends ArrayKey implements PseudoType +{ + /** @var Type */ + private $type; + + public function __construct(Type $type) + { + $this->type = $type; + } + + public function getType(): Type + { + return $this->type; + } + + public function underlyingType(): Type + { + return new ArrayKey(); + } + + public function __toString(): string + { + return 'key-of<' . $this->type . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ListShape.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ListShape.php new file mode 100644 index 0000000..deef3ab --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ListShape.php @@ -0,0 +1,16 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use function implode; + +/** @psalm-immutable */ +final class ListShape extends ArrayShape +{ + public function __toString(): string + { + return 'list{' . implode(', ', $this->getItems()) . '}'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ListShapeItem.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ListShapeItem.php new file mode 100644 index 0000000..d3eb7d7 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ListShapeItem.php @@ -0,0 +1,9 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +final class ListShapeItem extends ArrayShapeItem +{ +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/List_.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/List_.php new file mode 100644 index 0000000..3488731 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/List_.php @@ -0,0 +1,49 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Array_; +use phpDocumentor\Reflection\Types\Integer; + +/** + * Value Object representing the type 'list'. + * + * @psalm-immutable + */ +final class List_ extends Array_ implements PseudoType +{ + public function underlyingType(): Type + { + return new Array_(); + } + + public function __construct(?Type $valueType = null) + { + parent::__construct($valueType, new Integer()); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + if ($this->valueType === null) { + return 'list'; + } + + return 'list<' . $this->valueType . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/LiteralString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/LiteralString.php new file mode 100644 index 0000000..a38518b --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/LiteralString.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type 'literal-string'. + * + * @psalm-immutable + */ +final class LiteralString extends String_ implements PseudoType +{ + public function underlyingType(): Type + { + return new String_(); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'literal-string'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/LowercaseString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/LowercaseString.php new file mode 100644 index 0000000..f73d100 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/LowercaseString.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type 'lowercase-string'. + * + * @psalm-immutable + */ +final class LowercaseString extends String_ implements PseudoType +{ + public function underlyingType(): Type + { + return new String_(); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'lowercase-string'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NegativeInteger.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NegativeInteger.php new file mode 100644 index 0000000..ebcab6f --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NegativeInteger.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Integer; + +/** + * Value Object representing the type 'negative-int'. + * + * @psalm-immutable + */ +final class NegativeInteger extends Integer implements PseudoType +{ + public function underlyingType(): Type + { + return new Integer(); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'negative-int'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NeverReturn.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NeverReturn.php new file mode 100644 index 0000000..b2e87f7 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NeverReturn.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Never_; + +/** + * Value Object representing the type 'never-return'. + * + * @psalm-immutable + */ +final class NeverReturn extends Never_ implements PseudoType +{ + public function underlyingType(): Type + { + return new Never_(); + } + + public function __toString(): string + { + return 'never-return'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NeverReturns.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NeverReturns.php new file mode 100644 index 0000000..4c2a1a5 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NeverReturns.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Never_; + +/** + * Value Object representing the type 'never-returns'. + * + * @psalm-immutable + */ +final class NeverReturns extends Never_ implements PseudoType +{ + public function underlyingType(): Type + { + return new Never_(); + } + + public function __toString(): string + { + return 'never-returns'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NoReturn.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NoReturn.php new file mode 100644 index 0000000..b05d9bd --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NoReturn.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Never_; + +/** + * Value Object representing the type 'no-return'. + * + * @psalm-immutable + */ +final class NoReturn extends Never_ implements PseudoType +{ + public function underlyingType(): Type + { + return new Never_(); + } + + public function __toString(): string + { + return 'no-return'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyArray.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyArray.php new file mode 100644 index 0000000..4aa3720 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyArray.php @@ -0,0 +1,47 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Array_; + +/** + * Value Object representing the type 'non-empty-array'. + * + * @psalm-immutable + */ +final class NonEmptyArray extends Array_ implements PseudoType +{ + public function underlyingType(): Type + { + return new Array_($this->valueType, $this->keyType); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + if ($this->valueType === null) { + return 'non-empty-array'; + } + + if ($this->keyType) { + return 'non-empty-array<' . $this->keyType . ', ' . $this->valueType . '>'; + } + + return 'non-empty-array<' . $this->valueType . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyList.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyList.php new file mode 100644 index 0000000..e44f590 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyList.php @@ -0,0 +1,49 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Array_; +use phpDocumentor\Reflection\Types\Integer; + +/** + * Value Object representing the type 'non-empty-list'. + * + * @psalm-immutable + */ +final class NonEmptyList extends Array_ implements PseudoType +{ + public function underlyingType(): Type + { + return new Array_($this->valueType, $this->keyType); + } + + public function __construct(?Type $valueType = null) + { + parent::__construct($valueType, new Integer()); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + if ($this->valueType === null) { + return 'non-empty-list'; + } + + return 'non-empty-list<' . $this->valueType . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyLowercaseString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyLowercaseString.php new file mode 100644 index 0000000..c2f2b49 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyLowercaseString.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type 'non-empty-lowercase-string'. + * + * @psalm-immutable + */ +final class NonEmptyLowercaseString extends String_ implements PseudoType +{ + public function underlyingType(): Type + { + return new String_(); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'non-empty-lowercase-string'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyString.php new file mode 100644 index 0000000..afa782a --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyString.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type 'non-empty-string'. + * + * @psalm-immutable + */ +final class NonEmptyString extends String_ implements PseudoType +{ + public function underlyingType(): Type + { + return new String_(); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'non-empty-string'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonFalsyString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonFalsyString.php new file mode 100644 index 0000000..9063f74 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonFalsyString.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type 'non-falsy-string'. + * + * @psalm-immutable + */ +final class NonFalsyString extends String_ implements PseudoType +{ + public function underlyingType(): Type + { + return new String_(); + } + + public function __toString(): string + { + return 'non-falsy-string'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonNegativeInteger.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonNegativeInteger.php new file mode 100644 index 0000000..3b941a0 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonNegativeInteger.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Integer; + +/** + * Value Object representing the type 'non-negative-int'. + * + * @psalm-immutable + */ +final class NonNegativeInteger extends Integer implements PseudoType +{ + public function underlyingType(): Type + { + return new Integer(); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'non-negative-int'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonPositiveInteger.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonPositiveInteger.php new file mode 100644 index 0000000..a66125c --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonPositiveInteger.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Integer; + +/** + * Value Object representing the type 'non-positive-int'. + * + * @psalm-immutable + */ +final class NonPositiveInteger extends Integer implements PseudoType +{ + public function underlyingType(): Type + { + return new Integer(); + } + + public function __toString(): string + { + return 'non-positive-int'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonZeroInteger.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonZeroInteger.php new file mode 100644 index 0000000..41e0c4c --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonZeroInteger.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Integer; + +/** + * Value Object representing the type 'non-zero-int'. + * + * @psalm-immutable + */ +final class NonZeroInteger extends Integer implements PseudoType +{ + public function underlyingType(): Type + { + return new Integer(); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'non-zero-int'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NumericString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NumericString.php new file mode 100644 index 0000000..f45ec1d --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NumericString.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type 'numeric-string'. + * + * @psalm-immutable + */ +final class NumericString extends String_ implements PseudoType +{ + public function underlyingType(): Type + { + return new String_(); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'numeric-string'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Numeric_.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Numeric_.php new file mode 100644 index 0000000..46620cd --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Numeric_.php @@ -0,0 +1,47 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\AggregatedType; +use phpDocumentor\Reflection\Types\Compound; +use phpDocumentor\Reflection\Types\Float_; +use phpDocumentor\Reflection\Types\Integer; + +/** + * Value Object representing the 'numeric' pseudo-type, which is either a numeric-string, integer or float. + * + * @psalm-immutable + */ +final class Numeric_ extends AggregatedType implements PseudoType +{ + public function __construct() + { + AggregatedType::__construct([new NumericString(), new Integer(), new Float_()], '|'); + } + + public function underlyingType(): Type + { + return new Compound([new NumericString(), new Integer(), new Float_()]); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'numeric'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ObjectShape.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ObjectShape.php new file mode 100644 index 0000000..a02beb2 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ObjectShape.php @@ -0,0 +1,41 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Object_; + +use function implode; + +/** @psalm-immutable */ +final class ObjectShape extends Object_ implements PseudoType +{ + /** @var ObjectShapeItem[] */ + private $items; + + public function __construct(ObjectShapeItem ...$items) + { + $this->items = $items; + } + + /** + * @return ObjectShapeItem[] + */ + public function getItems(): array + { + return $this->items; + } + + public function underlyingType(): Type + { + return new Object_(); + } + + public function __toString(): string + { + return 'object{' . implode(', ', $this->items) . '}'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ObjectShapeItem.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ObjectShapeItem.php new file mode 100644 index 0000000..3aaecfd --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ObjectShapeItem.php @@ -0,0 +1,9 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +final class ObjectShapeItem extends ShapeItem +{ +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/OffsetAccess.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/OffsetAccess.php new file mode 100644 index 0000000..5d0d0b6 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/OffsetAccess.php @@ -0,0 +1,67 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Callable_; +use phpDocumentor\Reflection\Types\Mixed_; +use phpDocumentor\Reflection\Types\Nullable; + +/** + * Value Object representing the offset access type. + * + * @psalm-immutable + */ +final class OffsetAccess extends Mixed_ implements PseudoType +{ + /** @var Type */ + private $type; + /** @var Type */ + private $offset; + + public function __construct(Type $type, Type $offset) + { + $this->type = $type; + $this->offset = $offset; + } + + public function getType(): Type + { + return $this->type; + } + + public function getOffset(): Type + { + return $this->offset; + } + + public function underlyingType(): Type + { + return new Mixed_(); + } + + public function __toString(): string + { + if ( + $this->type instanceof Callable_ + || $this->type instanceof ConstExpression + || $this->type instanceof Nullable + ) { + return '(' . $this->type . ')[' . $this->offset . ']'; + } + + return $this->type . '[' . $this->offset . ']'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/OpenResource.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/OpenResource.php new file mode 100644 index 0000000..a2e8fe7 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/OpenResource.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Resource_; + +/** + * Value Object representing the type 'open-resource'. + * + * @psalm-immutable + */ +final class OpenResource extends Resource_ implements PseudoType +{ + public function underlyingType(): Type + { + return new Resource_(); + } + + public function __toString(): string + { + return 'open-resource'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PositiveInteger.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PositiveInteger.php new file mode 100644 index 0000000..3980544 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PositiveInteger.php @@ -0,0 +1,39 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Integer; + +/** + * Value Object representing the type 'positive-int'. + * + * @psalm-immutable + */ +final class PositiveInteger extends Integer implements PseudoType +{ + public function underlyingType(): Type + { + return new Integer(); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'positive-int'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PrivatePropertiesOf.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PrivatePropertiesOf.php new file mode 100644 index 0000000..bcf8f84 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PrivatePropertiesOf.php @@ -0,0 +1,27 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +/** + * Value Object representing the `private-properties-of` type. + * + * @psalm-immutable + */ +final class PrivatePropertiesOf extends PropertiesOf +{ + public function __toString(): string + { + return 'private-properties-of<' . $this->type . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PropertiesOf.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PropertiesOf.php new file mode 100644 index 0000000..644ae88 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PropertiesOf.php @@ -0,0 +1,53 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Array_; +use phpDocumentor\Reflection\Types\Mixed_; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the `properties-of` type. + * + * @psalm-immutable + */ +class PropertiesOf extends Array_ implements PseudoType +{ + /** @var Type */ + protected $type; + + public function __construct(Type $type) + { + parent::__construct(new Mixed_(), new String_()); + + $this->type = $type; + } + + public function getType(): Type + { + return $this->type; + } + + public function underlyingType(): Type + { + return new Array_(new Mixed_(), new String_()); + } + + public function __toString(): string + { + return 'properties-of<' . $this->type . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ProtectedPropertiesOf.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ProtectedPropertiesOf.php new file mode 100644 index 0000000..74ef8de --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ProtectedPropertiesOf.php @@ -0,0 +1,27 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +/** + * Value Object representing the `protected-properties-of` type. + * + * @psalm-immutable + */ +final class ProtectedPropertiesOf extends PropertiesOf +{ + public function __toString(): string + { + return 'protected-properties-of<' . $this->type . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PublicPropertiesOf.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PublicPropertiesOf.php new file mode 100644 index 0000000..eef0491 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PublicPropertiesOf.php @@ -0,0 +1,27 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +/** + * Value Object representing the `public-properties-of` type. + * + * @psalm-immutable + */ +final class PublicPropertiesOf extends PropertiesOf +{ + public function __toString(): string + { + return 'public-properties-of<' . $this->type . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Scalar.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Scalar.php new file mode 100644 index 0000000..127ef23 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Scalar.php @@ -0,0 +1,43 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Boolean; +use phpDocumentor\Reflection\Types\Compound; +use phpDocumentor\Reflection\Types\Float_; +use phpDocumentor\Reflection\Types\Integer; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the 'scalar' pseudo-type, which is either a string, integer, float or boolean. + * + * @psalm-immutable + */ +final class Scalar implements PseudoType +{ + public function underlyingType(): Type + { + return new Compound([new String_(), new Integer(), new Float_(), new Boolean()]); + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'scalar'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ShapeItem.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ShapeItem.php new file mode 100644 index 0000000..10a9a89 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ShapeItem.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Mixed_; + +use function sprintf; + +abstract class ShapeItem +{ + /** @var string|null */ + private $key; + /** @var Type */ + private $value; + /** @var bool */ + private $optional; + + public function __construct(?string $key, ?Type $value, bool $optional) + { + $this->key = $key; + $this->value = $value ?? new Mixed_(); + $this->optional = $optional; + } + + public function getKey(): ?string + { + return $this->key; + } + + public function getValue(): Type + { + return $this->value; + } + + public function isOptional(): bool + { + return $this->optional; + } + + public function __toString(): string + { + if ($this->key !== null && $this->key !== '') { + return sprintf( + '%s%s: %s', + $this->key, + $this->optional ? '?' : '', + (string) $this->value + ); + } + + return (string) $this->value; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/StringValue.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/StringValue.php new file mode 100644 index 0000000..cb61562 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/StringValue.php @@ -0,0 +1,47 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +use function sprintf; + +/** @psalm-immutable */ +class StringValue extends String_ implements PseudoType +{ + /** @var string */ + private $value; + + public function __construct(string $value) + { + $this->value = $value; + } + + public function getValue(): string + { + return $this->value; + } + + public function underlyingType(): Type + { + return new String_(); + } + + public function __toString(): string + { + return sprintf('"%s"', $this->value); + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/TraitString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/TraitString.php new file mode 100644 index 0000000..1298e3f --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/TraitString.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type `trait-string`. + * + * @psalm-immutable + */ +final class TraitString extends String_ implements PseudoType +{ + /** @var Type|null */ + private $genericType; + + public function __construct(?Type $genericType = null) + { + $this->genericType = $genericType; + } + + public function underlyingType(): Type + { + return new String_(); + } + + public function getGenericType(): ?Type + { + return $this->genericType; + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + if ($this->genericType === null) { + return 'trait-string'; + } + + return 'trait-string<' . (string) $this->genericType . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/True_.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/True_.php new file mode 100644 index 0000000..a8c1836 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/True_.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link https://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Boolean; + +/** + * Value Object representing the PseudoType 'False', which is a Boolean type. + * + * @psalm-immutable + */ +final class True_ extends Boolean implements PseudoType +{ + public function underlyingType(): Type + { + return new Boolean(); + } + + public function __toString(): string + { + return 'true'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/TruthyString.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/TruthyString.php new file mode 100644 index 0000000..4cb8687 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/TruthyString.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\String_; + +/** + * Value Object representing the type 'truthy-string'. + * + * @psalm-immutable + */ +final class TruthyString extends String_ implements PseudoType +{ + public function underlyingType(): Type + { + return new String_(); + } + + public function __toString(): string + { + return 'truthy-string'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ValueOf.php b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ValueOf.php new file mode 100644 index 0000000..608b634 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/PseudoTypes/ValueOf.php @@ -0,0 +1,49 @@ +<?php +/* + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + * + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\PseudoTypes; + +use phpDocumentor\Reflection\PseudoType; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\Types\Mixed_; + +/** + * Value Object representing the `value-of` type. + * + * @psalm-immutable + */ +final class ValueOf extends Mixed_ implements PseudoType +{ + /** @var Type */ + private $type; + + public function __construct(Type $type) + { + $this->type = $type; + } + + public function getType(): Type + { + return $this->type; + } + + public function underlyingType(): Type + { + return new Mixed_(); + } + + public function __toString(): string + { + return 'value-of<' . $this->type . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Type.php b/vendor/phpdocumentor/type-resolver/src/Type.php new file mode 100644 index 0000000..c71d8b0 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Type.php @@ -0,0 +1,25 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +/** + * @psalm-immutable + */ +interface Type +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string; +} diff --git a/vendor/phpdocumentor/type-resolver/src/TypeResolver.php b/vendor/phpdocumentor/type-resolver/src/TypeResolver.php new file mode 100644 index 0000000..9b6cfb7 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/TypeResolver.php @@ -0,0 +1,692 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +use Doctrine\Deprecations\Deprecation; +use InvalidArgumentException; +use phpDocumentor\Reflection\PseudoTypes\ArrayKey; +use phpDocumentor\Reflection\PseudoTypes\ArrayShape; +use phpDocumentor\Reflection\PseudoTypes\ArrayShapeItem; +use phpDocumentor\Reflection\PseudoTypes\CallableArray; +use phpDocumentor\Reflection\PseudoTypes\CallableString; +use phpDocumentor\Reflection\PseudoTypes\ClassString; +use phpDocumentor\Reflection\PseudoTypes\ClosedResource; +use phpDocumentor\Reflection\PseudoTypes\Conditional; +use phpDocumentor\Reflection\PseudoTypes\ConditionalForParameter; +use phpDocumentor\Reflection\PseudoTypes\ConstExpression; +use phpDocumentor\Reflection\PseudoTypes\EnumString; +use phpDocumentor\Reflection\PseudoTypes\False_; +use phpDocumentor\Reflection\PseudoTypes\FloatValue; +use phpDocumentor\Reflection\PseudoTypes\Generic; +use phpDocumentor\Reflection\PseudoTypes\HtmlEscapedString; +use phpDocumentor\Reflection\PseudoTypes\IntegerRange; +use phpDocumentor\Reflection\PseudoTypes\IntegerValue; +use phpDocumentor\Reflection\PseudoTypes\InterfaceString; +use phpDocumentor\Reflection\PseudoTypes\IntMask; +use phpDocumentor\Reflection\PseudoTypes\IntMaskOf; +use phpDocumentor\Reflection\PseudoTypes\KeyOf; +use phpDocumentor\Reflection\PseudoTypes\List_; +use phpDocumentor\Reflection\PseudoTypes\ListShape; +use phpDocumentor\Reflection\PseudoTypes\ListShapeItem; +use phpDocumentor\Reflection\PseudoTypes\LiteralString; +use phpDocumentor\Reflection\PseudoTypes\LowercaseString; +use phpDocumentor\Reflection\PseudoTypes\NegativeInteger; +use phpDocumentor\Reflection\PseudoTypes\NeverReturn; +use phpDocumentor\Reflection\PseudoTypes\NeverReturns; +use phpDocumentor\Reflection\PseudoTypes\NonEmptyArray; +use phpDocumentor\Reflection\PseudoTypes\NonEmptyList; +use phpDocumentor\Reflection\PseudoTypes\NonEmptyLowercaseString; +use phpDocumentor\Reflection\PseudoTypes\NonEmptyString; +use phpDocumentor\Reflection\PseudoTypes\NonFalsyString; +use phpDocumentor\Reflection\PseudoTypes\NonNegativeInteger; +use phpDocumentor\Reflection\PseudoTypes\NonPositiveInteger; +use phpDocumentor\Reflection\PseudoTypes\NonZeroInteger; +use phpDocumentor\Reflection\PseudoTypes\NoReturn; +use phpDocumentor\Reflection\PseudoTypes\Numeric_; +use phpDocumentor\Reflection\PseudoTypes\NumericString; +use phpDocumentor\Reflection\PseudoTypes\ObjectShape; +use phpDocumentor\Reflection\PseudoTypes\ObjectShapeItem; +use phpDocumentor\Reflection\PseudoTypes\OffsetAccess; +use phpDocumentor\Reflection\PseudoTypes\OpenResource; +use phpDocumentor\Reflection\PseudoTypes\PositiveInteger; +use phpDocumentor\Reflection\PseudoTypes\PrivatePropertiesOf; +use phpDocumentor\Reflection\PseudoTypes\PropertiesOf; +use phpDocumentor\Reflection\PseudoTypes\ProtectedPropertiesOf; +use phpDocumentor\Reflection\PseudoTypes\PublicPropertiesOf; +use phpDocumentor\Reflection\PseudoTypes\Scalar; +use phpDocumentor\Reflection\PseudoTypes\StringValue; +use phpDocumentor\Reflection\PseudoTypes\TraitString; +use phpDocumentor\Reflection\PseudoTypes\True_; +use phpDocumentor\Reflection\PseudoTypes\TruthyString; +use phpDocumentor\Reflection\PseudoTypes\ValueOf; +use phpDocumentor\Reflection\Types\AggregatedType; +use phpDocumentor\Reflection\Types\Array_; +use phpDocumentor\Reflection\Types\Boolean; +use phpDocumentor\Reflection\Types\Callable_; +use phpDocumentor\Reflection\Types\CallableParameter; +use phpDocumentor\Reflection\Types\Compound; +use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Expression; +use phpDocumentor\Reflection\Types\Float_; +use phpDocumentor\Reflection\Types\Integer; +use phpDocumentor\Reflection\Types\Intersection; +use phpDocumentor\Reflection\Types\Iterable_; +use phpDocumentor\Reflection\Types\Mixed_; +use phpDocumentor\Reflection\Types\Never_; +use phpDocumentor\Reflection\Types\Null_; +use phpDocumentor\Reflection\Types\Nullable; +use phpDocumentor\Reflection\Types\Object_; +use phpDocumentor\Reflection\Types\Parent_; +use phpDocumentor\Reflection\Types\Resource_; +use phpDocumentor\Reflection\Types\Self_; +use phpDocumentor\Reflection\Types\Static_; +use phpDocumentor\Reflection\Types\String_; +use phpDocumentor\Reflection\Types\This; +use phpDocumentor\Reflection\Types\Void_; +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprFloatNode; +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode; +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode; +use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode; +use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode; +use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode; +use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode; +use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode; +use PHPStan\PhpDocParser\Ast\Type\CallableTypeParameterNode; +use PHPStan\PhpDocParser\Ast\Type\ConditionalTypeForParameterNode; +use PHPStan\PhpDocParser\Ast\Type\ConditionalTypeNode; +use PHPStan\PhpDocParser\Ast\Type\ConstTypeNode; +use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; +use PHPStan\PhpDocParser\Ast\Type\IntersectionTypeNode; +use PHPStan\PhpDocParser\Ast\Type\NullableTypeNode; +use PHPStan\PhpDocParser\Ast\Type\ObjectShapeItemNode; +use PHPStan\PhpDocParser\Ast\Type\ObjectShapeNode; +use PHPStan\PhpDocParser\Ast\Type\OffsetAccessTypeNode; +use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode; +use PHPStan\PhpDocParser\Ast\Type\TypeNode; +use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode; +use PHPStan\PhpDocParser\Lexer\Lexer; +use PHPStan\PhpDocParser\Parser\ConstExprParser; +use PHPStan\PhpDocParser\Parser\ParserException; +use PHPStan\PhpDocParser\Parser\TokenIterator; +use PHPStan\PhpDocParser\Parser\TypeParser; +use PHPStan\PhpDocParser\ParserConfig; +use RuntimeException; + +use function array_key_exists; +use function array_map; +use function array_reverse; +use function class_exists; +use function class_implements; +use function get_class; +use function in_array; +use function sprintf; +use function strpos; +use function strtolower; +use function substr; +use function trim; + +final class TypeResolver +{ + /** @var string Definition of the NAMESPACE operator in PHP */ + private const OPERATOR_NAMESPACE = '\\'; + + /** + * @var array<string, string> List of recognized keywords and unto which Value Object they map + * @psalm-var array<string, class-string<Type>> + */ + private $keywords = [ + 'string' => String_::class, + 'class-string' => ClassString::class, + 'interface-string' => InterfaceString::class, + 'html-escaped-string' => HtmlEscapedString::class, + 'lowercase-string' => LowercaseString::class, + 'non-empty-lowercase-string' => NonEmptyLowercaseString::class, + 'non-empty-string' => NonEmptyString::class, + 'numeric-string' => NumericString::class, + 'numeric' => Numeric_::class, + 'trait-string' => TraitString::class, + 'enum-string' => EnumString::class, + 'int' => Integer::class, + 'integer' => Integer::class, + 'positive-int' => PositiveInteger::class, + 'negative-int' => NegativeInteger::class, + 'bool' => Boolean::class, + 'boolean' => Boolean::class, + 'real' => Float_::class, + 'float' => Float_::class, + 'double' => Float_::class, + 'object' => Object_::class, + 'mixed' => Mixed_::class, + 'array' => Array_::class, + 'callable-array' => CallableArray::class, + 'array-key' => ArrayKey::class, + 'non-empty-array' => NonEmptyArray::class, + 'resource' => Resource_::class, + 'open-resource' => OpenResource::class, + 'closed-resource' => ClosedResource::class, + 'void' => Void_::class, + 'null' => Null_::class, + 'scalar' => Scalar::class, + 'callback' => Callable_::class, + 'callable' => Callable_::class, + 'callable-string' => CallableString::class, + 'false' => False_::class, + 'true' => True_::class, + 'literal-string' => LiteralString::class, + 'self' => Self_::class, + '$this' => This::class, + 'static' => Static_::class, + 'parent' => Parent_::class, + 'iterable' => Iterable_::class, + 'never' => Never_::class, + 'never-return' => NeverReturn::class, + 'never-returns' => NeverReturns::class, + 'no-return' => NoReturn::class, + 'list' => List_::class, + 'non-empty-list' => NonEmptyList::class, + 'non-falsy-string' => NonFalsyString::class, + 'truthy-string' => TruthyString::class, + 'non-positive-int' => NonPositiveInteger::class, + 'non-negative-int' => NonNegativeInteger::class, + 'non-zero-int' => NonZeroInteger::class, + ]; + + /** + * @psalm-readonly + * @var FqsenResolver + */ + private $fqsenResolver; + /** + * @psalm-readonly + * @var TypeParser + */ + private $typeParser; + /** + * @psalm-readonly + * @var Lexer + */ + private $lexer; + + /** + * Initializes this TypeResolver with the means to create and resolve Fqsen objects. + */ + public function __construct(?FqsenResolver $fqsenResolver = null) + { + $this->fqsenResolver = $fqsenResolver ?: new FqsenResolver(); + $this->typeParser = new TypeParser(new ParserConfig([]), new ConstExprParser(new ParserConfig([]))); + $this->lexer = new Lexer(new ParserConfig([])); + } + + /** + * Analyzes the given type and returns the FQCN variant. + * + * When a type is provided this method checks whether it is not a keyword or + * Fully Qualified Class Name. If so it will use the given namespace and + * aliases to expand the type to a FQCN representation. + * + * This method only works as expected if the namespace and aliases are set; + * no dynamic reflection is being performed here. + * + * @uses Context::getNamespace() to determine with what to prefix the type name. + * @uses Context::getNamespaceAliases() to check whether the first part of the relative type name should not be + * replaced with another namespace. + * + * @param string $type The relative or absolute type. + */ + public function resolve(string $type, ?Context $context = null): Type + { + $type = trim($type); + if (!$type) { + throw new InvalidArgumentException('Attempted to resolve "' . $type . '" but it appears to be empty'); + } + + if ($context === null) { + $context = new Context(''); + } + + $tokens = $this->lexer->tokenize($type); + $tokenIterator = new TokenIterator($tokens); + + $ast = $this->parse($tokenIterator); + $type = $this->createType($ast, $context); + + if ( + $tokenIterator->isCurrentTokenType(Lexer::TOKEN_UNION) || + $tokenIterator->isCurrentTokenType(Lexer::TOKEN_INTERSECTION) + ) { + Deprecation::trigger( + 'phpdocumentor/type-resolver', + 'https://github.com/phpDocumentor/TypeResolver/issues/184', + 'Legacy nullable type detected, please update your code as + you are using nullable types in a docblock. support is removed in v2.0.0' + ); + } + + return $type; + } + + public function createType(?TypeNode $type, Context $context): Type + { + if ($type === null) { + return new Mixed_(); + } + + switch (get_class($type)) { + case ArrayTypeNode::class: + return new Array_( + $this->createType($type->type, $context) + ); + + case ArrayShapeNode::class: + switch ($type->kind) { + case ArrayShapeNode::KIND_ARRAY: + return new ArrayShape( + ...array_map( + function (ArrayShapeItemNode $item) use ($context): ArrayShapeItem { + return new ArrayShapeItem( + $item->keyName !== null ? (string) $item->keyName : null, + $this->createType($item->valueType, $context), + $item->optional + ); + }, + $type->items + ) + ); + + case ArrayShapeNode::KIND_LIST: + return new ListShape( + ...array_map( + function (ArrayShapeItemNode $item) use ($context): ListShapeItem { + return new ListShapeItem( + null, + $this->createType($item->valueType, $context), + $item->optional + ); + }, + $type->items + ) + ); + + default: + throw new RuntimeException('Unsupported array shape kind'); + } + case ObjectShapeNode::class: + return new ObjectShape( + ...array_map( + function (ObjectShapeItemNode $item) use ($context): ObjectShapeItem { + return new ObjectShapeItem( + (string) $item->keyName, + $this->createType($item->valueType, $context), + $item->optional + ); + }, + $type->items + ) + ); + + case CallableTypeNode::class: + return $this->createFromCallable($type, $context); + + case ConstTypeNode::class: + return $this->createFromConst($type, $context); + + case GenericTypeNode::class: + return $this->createFromGeneric($type, $context); + + case IdentifierTypeNode::class: + return $this->resolveSingleType($type->name, $context); + + case IntersectionTypeNode::class: + return new Intersection( + array_map( + function (TypeNode $nestedType) use ($context): Type { + $type = $this->createType($nestedType, $context); + if ($type instanceof AggregatedType) { + return new Expression($type); + } + + return $type; + }, + $type->types + ) + ); + + case NullableTypeNode::class: + $nestedType = $this->createType($type->type, $context); + + return new Nullable($nestedType); + + case UnionTypeNode::class: + return new Compound( + array_map( + function (TypeNode $nestedType) use ($context): Type { + $type = $this->createType($nestedType, $context); + if ($type instanceof AggregatedType) { + return new Expression($type); + } + + return $type; + }, + $type->types + ) + ); + + case ThisTypeNode::class: + return new This(); + + case ConditionalTypeNode::class: + return new Conditional( + $type->negated, + $this->createType($type->subjectType, $context), + $this->createType($type->targetType, $context), + $this->createType($type->if, $context), + $this->createType($type->else, $context), + ); + + case ConditionalTypeForParameterNode::class: + return new ConditionalForParameter( + $type->negated, + substr($type->parameterName, 1), + $this->createType($type->targetType, $context), + $this->createType($type->if, $context), + $this->createType($type->else, $context), + ); + + case OffsetAccessTypeNode::class: + return new OffsetAccess( + $this->createType($type->type, $context), + $this->createType($type->offset, $context) + ); + + default: + return new Mixed_(); + } + } + + private function createFromGeneric(GenericTypeNode $type, Context $context): Type + { + switch (strtolower($type->type->name)) { + case 'array': + $genericTypes = array_reverse($this->createTypesByTypeNodes($type->genericTypes, $context)); + + return new Array_(...$genericTypes); + + case 'non-empty-array': + $genericTypes = array_reverse($this->createTypesByTypeNodes($type->genericTypes, $context)); + + return new NonEmptyArray(...$genericTypes); + + case 'class-string': + return new ClassString($this->createType($type->genericTypes[0], $context)); + + case 'interface-string': + return new InterfaceString($this->createType($type->genericTypes[0], $context)); + + case 'trait-string': + return new TraitString($this->createType($type->genericTypes[0], $context)); + + case 'enum-string': + return new EnumString($this->createType($type->genericTypes[0], $context)); + + case 'list': + return new List_( + $this->createType($type->genericTypes[0], $context) + ); + + case 'non-empty-list': + return new NonEmptyList( + $this->createType($type->genericTypes[0], $context) + ); + + case 'int': + if (isset($type->genericTypes[1]) === false) { + throw new RuntimeException('int<min,max> has not the correct format'); + } + + return new IntegerRange((string) $type->genericTypes[0], (string) $type->genericTypes[1]); + + case 'iterable': + return new Iterable_(...array_reverse($this->createTypesByTypeNodes($type->genericTypes, $context))); + + case 'key-of': + return new KeyOf($this->createType($type->genericTypes[0], $context)); + + case 'value-of': + return new ValueOf($this->createType($type->genericTypes[0], $context)); + + case 'properties-of': + return new PropertiesOf($this->createType($type->genericTypes[0], $context)); + + case 'public-properties-of': + return new PublicPropertiesOf($this->createType($type->genericTypes[0], $context)); + + case 'protected-properties-of': + return new ProtectedPropertiesOf($this->createType($type->genericTypes[0], $context)); + + case 'private-properties-of': + return new PrivatePropertiesOf($this->createType($type->genericTypes[0], $context)); + + case 'int-mask': + return new IntMask(...$this->createTypesByTypeNodes($type->genericTypes, $context)); + + case 'int-mask-of': + return new IntMaskOf($this->createType($type->genericTypes[0], $context)); + + case 'static': + return new Static_(...$this->createTypesByTypeNodes($type->genericTypes, $context)); + + case 'self': + return new Self_(...$this->createTypesByTypeNodes($type->genericTypes, $context)); + + default: + $mainType = $this->createType($type->type, $context); + if ($mainType instanceof Object_ === false) { + throw new RuntimeException(sprintf('%s is an unsupported generic', (string) $mainType)); + } + + $types = $this->createTypesByTypeNodes($type->genericTypes, $context); + + return new Generic($mainType->getFqsen(), $types); + } + } + + private function createFromCallable(CallableTypeNode $type, Context $context): Callable_ + { + return new Callable_( + (string) $type->identifier, + array_map( + function (CallableTypeParameterNode $param) use ($context): CallableParameter { + return new CallableParameter( + $this->createType($param->type, $context), + $param->parameterName !== '' ? trim($param->parameterName, '$') : null, + $param->isReference, + $param->isVariadic, + $param->isOptional + ); + }, + $type->parameters + ), + $this->createType($type->returnType, $context) + ); + } + + private function createFromConst(ConstTypeNode $type, Context $context): Type + { + switch (true) { + case $type->constExpr instanceof ConstExprIntegerNode: + return new IntegerValue((int) $type->constExpr->value); + + case $type->constExpr instanceof ConstExprFloatNode: + return new FloatValue((float) $type->constExpr->value); + + case $type->constExpr instanceof ConstExprStringNode: + return new StringValue($type->constExpr->value); + + case $type->constExpr instanceof ConstFetchNode: + return new ConstExpression( + $this->resolve($type->constExpr->className, $context), + $type->constExpr->name + ); + + default: + throw new RuntimeException(sprintf('Unsupported constant type %s', get_class($type))); + } + } + + /** + * resolve the given type into a type object + * + * @param string $type the type string, representing a single type + * + * @return Type|Array_|Object_ + * + * @psalm-mutation-free + */ + private function resolveSingleType(string $type, Context $context): object + { + switch (true) { + case $this->isKeyword($type): + return $this->resolveKeyword($type); + + case $this->isFqsen($type): + return $this->resolveTypedObject($type); + + case $this->isPartialStructuralElementName($type): + return $this->resolveTypedObject($type, $context); + + // @codeCoverageIgnoreStart + default: + // I haven't got the foggiest how the logic would come here but added this as a defense. + throw new RuntimeException( + 'Unable to resolve type "' . $type . '", there is no known method to resolve it' + ); + } + + // @codeCoverageIgnoreEnd + } + + /** + * Adds a keyword to the list of Keywords and associates it with a specific Value Object. + * + * @psalm-param class-string<Type> $typeClassName + */ + public function addKeyword(string $keyword, string $typeClassName): void + { + if (!class_exists($typeClassName)) { + throw new InvalidArgumentException( + 'The Value Object that needs to be created with a keyword "' . $keyword . '" must be an existing class' + . ' but we could not find the class ' . $typeClassName + ); + } + + $interfaces = class_implements($typeClassName); + if ($interfaces === false) { + throw new InvalidArgumentException( + 'The Value Object that needs to be created with a keyword "' . $keyword . '" must be an existing class' + . ' but we could not find the class ' . $typeClassName + ); + } + + if (!in_array(Type::class, $interfaces, true)) { + throw new InvalidArgumentException( + 'The class "' . $typeClassName . '" must implement the interface "phpDocumentor\Reflection\Type"' + ); + } + + $this->keywords[$keyword] = $typeClassName; + } + + /** + * Detects whether the given type represents a PHPDoc keyword. + * + * @param string $type A relative or absolute type as defined in the phpDocumentor documentation. + * + * @psalm-mutation-free + */ + private function isKeyword(string $type): bool + { + return array_key_exists(strtolower($type), $this->keywords); + } + + /** + * Detects whether the given type represents a relative structural element name. + * + * @param string $type A relative or absolute type as defined in the phpDocumentor documentation. + * + * @psalm-mutation-free + */ + private function isPartialStructuralElementName(string $type): bool + { + return (isset($type[0]) && $type[0] !== self::OPERATOR_NAMESPACE) && !$this->isKeyword($type); + } + + /** + * Tests whether the given type is a Fully Qualified Structural Element Name. + * + * @psalm-mutation-free + */ + private function isFqsen(string $type): bool + { + return strpos($type, self::OPERATOR_NAMESPACE) === 0; + } + + /** + * Resolves the given keyword (such as `string`) into a Type object representing that keyword. + * + * @psalm-mutation-free + */ + private function resolveKeyword(string $type): Type + { + $className = $this->keywords[strtolower($type)]; + + return new $className(); + } + + /** + * Resolves the given FQSEN string into an FQSEN object. + * + * @psalm-mutation-free + */ + private function resolveTypedObject(string $type, ?Context $context = null): Object_ + { + return new Object_($this->fqsenResolver->resolve($type, $context)); + } + + private function parse(TokenIterator $tokenIterator): TypeNode + { + try { + $ast = $this->typeParser->parse($tokenIterator); + } catch (ParserException $e) { + throw new RuntimeException($e->getMessage(), 0, $e); + } + + return $ast; + } + + /** + * @param TypeNode[] $nodes + * + * @return Type[] + */ + private function createTypesByTypeNodes(array $nodes, Context $context): array + { + return array_map( + function (TypeNode $node) use ($context): Type { + return $this->createType($node, $context); + }, + $nodes + ); + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/AbstractList.php b/vendor/phpdocumentor/type-resolver/src/Types/AbstractList.php new file mode 100644 index 0000000..e8e8c6b --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/AbstractList.php @@ -0,0 +1,73 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Represents a list of values. This is an abstract class for Array_ and List_. + * + * @psalm-immutable + */ +abstract class AbstractList implements Type +{ + /** @var Type|null */ + protected $valueType; + + /** @var Type|null */ + protected $keyType; + + /** @var Type */ + protected $defaultKeyType; + + /** @var Type */ + protected $defaultValueType; + + /** + * Initializes this representation of an array with the given Type. + */ + public function __construct(?Type $valueType = null, ?Type $keyType = null) + { + $this->defaultValueType = new Mixed_(); + $this->valueType = $valueType; + $this->defaultKeyType = new Compound([new String_(), new Integer()]); + $this->keyType = $keyType; + } + + public function getOriginalKeyType(): ?Type + { + return $this->keyType; + } + + public function getOriginalValueType(): ?Type + { + return $this->valueType; + } + + /** + * Returns the type for the keys of this array. + */ + public function getKeyType(): Type + { + return $this->keyType ?? $this->defaultKeyType; + } + + /** + * Returns the type for the values of this array. + */ + public function getValueType(): Type + { + return $this->valueType ?? $this->defaultValueType; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/AggregatedType.php b/vendor/phpdocumentor/type-resolver/src/Types/AggregatedType.php new file mode 100644 index 0000000..e1da6cb --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/AggregatedType.php @@ -0,0 +1,125 @@ +<?php +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\Types; + +use ArrayIterator; +use IteratorAggregate; +use phpDocumentor\Reflection\Type; + +use function array_key_exists; +use function implode; + +/** + * Base class for aggregated types like Compound and Intersection + * + * A Aggregated Type is not so much a special keyword or object reference but is a series of Types that are separated + * using separator. + * + * @psalm-immutable + * @template-implements IteratorAggregate<int, Type> + */ +abstract class AggregatedType implements Type, IteratorAggregate +{ + /** + * @psalm-allow-private-mutation + * @var array<int, Type> + */ + private $types = []; + + /** @var string */ + private $token; + + /** + * @param array<Type> $types + */ + public function __construct(array $types, string $token) + { + foreach ($types as $type) { + $this->add($type); + } + + $this->token = $token; + } + + /** + * Returns the type at the given index. + */ + public function get(int $index): ?Type + { + if (!$this->has($index)) { + return null; + } + + return $this->types[$index]; + } + + /** + * Tests if this compound type has a type with the given index. + */ + public function has(int $index): bool + { + return array_key_exists($index, $this->types); + } + + /** + * Tests if this compound type contains the given type. + */ + public function contains(Type $type): bool + { + foreach ($this->types as $typePart) { + // if the type is duplicate; do not add it + if ((string) $typePart === (string) $type) { + return true; + } + } + + return false; + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return implode($this->token, $this->types); + } + + /** + * @return ArrayIterator<int, Type> + */ + public function getIterator(): ArrayIterator + { + return new ArrayIterator($this->types); + } + + /** + * @psalm-suppress ImpureMethodCall + */ + private function add(Type $type): void + { + if ($type instanceof static) { + foreach ($type->getIterator() as $subType) { + $this->add($subType); + } + + return; + } + + // if the type is duplicate; do not add it + if ($this->contains($type)) { + return; + } + + $this->types[] = $type; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Array_.php b/vendor/phpdocumentor/type-resolver/src/Types/Array_.php new file mode 100644 index 0000000..b5e7eab --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Array_.php @@ -0,0 +1,50 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use function preg_match; +use function substr; + +/** + * Represents an array type as described in the PSR-5, the PHPDoc Standard. + * + * An array can be represented in two forms: + * + * 1. Untyped (`array`), where the key and value type is unknown and hence classified as 'Mixed_'. + * 2. Types (`string[]`), where the value type is provided by preceding an opening and closing square bracket with a + * type name. + * + * @psalm-immutable + */ +class Array_ extends AbstractList +{ + public function __toString(): string + { + if ($this->valueType === null) { + return 'array'; + } + + $valueTypeString = (string) $this->valueType; + + if ($this->keyType) { + return 'array<' . $this->keyType . ', ' . $valueTypeString . '>'; + } + + if (!preg_match('/[^\w\\\\]/', $valueTypeString) || substr($valueTypeString, -2, 2) === '[]') { + return $valueTypeString . '[]'; + } + + return 'array<' . $valueTypeString . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Boolean.php b/vendor/phpdocumentor/type-resolver/src/Types/Boolean.php new file mode 100644 index 0000000..8b1a3f3 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Boolean.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing a Boolean type. + * + * @psalm-immutable + */ +class Boolean implements Type +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'bool'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/CallableParameter.php b/vendor/phpdocumentor/type-resolver/src/Types/CallableParameter.php new file mode 100644 index 0000000..84a6a7b --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/CallableParameter.php @@ -0,0 +1,89 @@ +<?php +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +use function trim; + +/** + * Value Object representing a Callable parameters. + * + * @psalm-immutable + */ +final class CallableParameter +{ + /** @var Type */ + private $type; + + /** @var bool */ + private $isReference; + + /** @var bool */ + private $isVariadic; + + /** @var bool */ + private $isOptional; + + /** @var string|null */ + private $name; + + public function __construct( + Type $type, + ?string $name = null, + bool $isReference = false, + bool $isVariadic = false, + bool $isOptional = false + ) { + $this->type = $type; + $this->isReference = $isReference; + $this->isVariadic = $isVariadic; + $this->isOptional = $isOptional; + $this->name = $name; + } + + public function getName(): ?string + { + return $this->name; + } + + public function getType(): Type + { + return $this->type; + } + + public function isReference(): bool + { + return $this->isReference; + } + + public function isVariadic(): bool + { + return $this->isVariadic; + } + + public function isOptional(): bool + { + return $this->isOptional; + } + + public function __toString(): string + { + $reference = $this->isReference ? '&' : ''; + $variadic = $this->isVariadic ? '...' : ''; + $optional = $this->isOptional ? '=' : ''; + $name = $this->name !== null ? '$' . $this->name : ''; + + return trim($this->type . ' ' . $reference . $variadic . $name . $optional); + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Callable_.php b/vendor/phpdocumentor/type-resolver/src/Types/Callable_.php new file mode 100644 index 0000000..f06325b --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Callable_.php @@ -0,0 +1,80 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +use function implode; + +/** + * Value Object representing a Callable type. + * + * @psalm-immutable + */ +final class Callable_ implements Type +{ + /** @var string */ + private $identifier; + /** @var Type|null */ + private $returnType; + /** @var CallableParameter[] */ + private $parameters; + + /** + * @param CallableParameter[] $parameters + */ + public function __construct( + string $identifier = 'callable', + array $parameters = [], + ?Type $returnType = null + ) { + $this->identifier = $identifier; + $this->parameters = $parameters; + $this->returnType = $returnType; + } + + public function getIdentifier(): string + { + return $this->identifier; + } + + /** @return CallableParameter[] */ + public function getParameters(): array + { + return $this->parameters; + } + + public function getReturnType(): ?Type + { + return $this->returnType; + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + if (!$this->parameters && $this->returnType === null) { + return $this->identifier; + } + + if ($this->returnType instanceof self) { + $returnType = '(' . (string) $this->returnType . ')'; + } else { + $returnType = (string) $this->returnType; + } + + return $this->identifier . '(' . implode(', ', $this->parameters) . '): ' . $returnType; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Compound.php b/vendor/phpdocumentor/type-resolver/src/Types/Compound.php new file mode 100644 index 0000000..ad426cc --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Compound.php @@ -0,0 +1,38 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing a Compound Type. + * + * A Compound Type is not so much a special keyword or object reference but is a series of Types that are separated + * using an OR operator (`|`). This combination of types signifies that whatever is associated with this compound type + * may contain a value with any of the given types. + * + * @psalm-immutable + */ +final class Compound extends AggregatedType +{ + /** + * Initializes a compound type (i.e. `string|int`) and tests if the provided types all implement the Type interface. + * + * @param array<Type> $types + */ + public function __construct(array $types) + { + parent::__construct($types, '|'); + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Context.php b/vendor/phpdocumentor/type-resolver/src/Types/Context.php new file mode 100644 index 0000000..bb3b6ef --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Context.php @@ -0,0 +1,95 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use function strlen; +use function substr; +use function trim; + +/** + * Provides information about the Context in which the DocBlock occurs that receives this context. + * + * A DocBlock does not know of its own accord in which namespace it occurs and which namespace aliases are applicable + * for the block of code in which it is in. This information is however necessary to resolve Class names in tags since + * you can provide a short form or make use of namespace aliases. + * + * The phpDocumentor Reflection component knows how to create this class but if you use the DocBlock parser from your + * own application it is possible to generate a Context class using the ContextFactory; this will analyze the file in + * which an associated class resides for its namespace and imports. + * + * @see ContextFactory::createFromReflector() + * @see ContextFactory::createForNamespace() + * + * @psalm-immutable + */ +final class Context +{ + /** @var string The current namespace. */ + private $namespace; + + /** + * @var string[] List of namespace aliases => Fully Qualified Namespace. + * @psalm-var array<string, string> + */ + private $namespaceAliases; + + /** + * Initializes the new context and normalizes all passed namespaces to be in Qualified Namespace Name (QNN) + * format (without a preceding `\`). + * + * @param string $namespace The namespace where this DocBlock resides in. + * @param string[] $namespaceAliases List of namespace aliases => Fully Qualified Namespace. + * @psalm-param array<string, string> $namespaceAliases + */ + public function __construct(string $namespace, array $namespaceAliases = []) + { + $this->namespace = $namespace !== 'global' && $namespace !== 'default' + ? trim($namespace, '\\') + : ''; + + foreach ($namespaceAliases as $alias => $fqnn) { + if ($fqnn[0] === '\\') { + $fqnn = substr($fqnn, 1); + } + + if ($fqnn[strlen($fqnn) - 1] === '\\') { + $fqnn = substr($fqnn, 0, -1); + } + + $namespaceAliases[$alias] = $fqnn; + } + + $this->namespaceAliases = $namespaceAliases; + } + + /** + * Returns the Qualified Namespace Name (thus without `\` in front) where the associated element is in. + */ + public function getNamespace(): string + { + return $this->namespace; + } + + /** + * Returns a list of Qualified Namespace Names (thus without `\` in front) that are imported, the keys represent + * the alias for the imported Namespace. + * + * @return string[] + * @psalm-return array<string, string> + */ + public function getNamespaceAliases(): array + { + return $this->namespaceAliases; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php b/vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php new file mode 100644 index 0000000..2018ff5 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php @@ -0,0 +1,422 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use ArrayIterator; +use InvalidArgumentException; +use ReflectionClass; +use ReflectionClassConstant; +use ReflectionMethod; +use ReflectionParameter; +use ReflectionProperty; +use Reflector; +use RuntimeException; +use UnexpectedValueException; + +use function define; +use function defined; +use function file_exists; +use function file_get_contents; +use function get_class; +use function in_array; +use function is_string; +use function strrpos; +use function substr; +use function token_get_all; +use function trim; + +use const T_AS; +use const T_CLASS; +use const T_CURLY_OPEN; +use const T_DOLLAR_OPEN_CURLY_BRACES; +use const T_NAME_FULLY_QUALIFIED; +use const T_NAME_QUALIFIED; +use const T_NAMESPACE; +use const T_NS_SEPARATOR; +use const T_STRING; +use const T_TRAIT; +use const T_USE; + +if (!defined('T_NAME_QUALIFIED')) { + define('T_NAME_QUALIFIED', 10001); +} + +if (!defined('T_NAME_FULLY_QUALIFIED')) { + define('T_NAME_FULLY_QUALIFIED', 10002); +} + +/** + * Convenience class to create a Context for DocBlocks when not using the Reflection Component of phpDocumentor. + * + * For a DocBlock to be able to resolve types that use partial namespace names or rely on namespace imports we need to + * provide a bit of context so that the DocBlock can read that and based on it decide how to resolve the types to + * Fully Qualified names. + * + * @see Context for more information. + */ +final class ContextFactory +{ + /** The literal used at the end of a use statement. */ + private const T_LITERAL_END_OF_USE = ';'; + + /** The literal used between sets of use statements */ + private const T_LITERAL_USE_SEPARATOR = ','; + + /** + * Build a Context given a Class Reflection. + * + * @see Context for more information on Contexts. + */ + public function createFromReflector(Reflector $reflector): Context + { + if ($reflector instanceof ReflectionClass) { + //phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable + /** @var ReflectionClass<object> $reflector */ + + return $this->createFromReflectionClass($reflector); + } + + if ($reflector instanceof ReflectionParameter) { + return $this->createFromReflectionParameter($reflector); + } + + if ($reflector instanceof ReflectionMethod) { + return $this->createFromReflectionMethod($reflector); + } + + if ($reflector instanceof ReflectionProperty) { + return $this->createFromReflectionProperty($reflector); + } + + if ($reflector instanceof ReflectionClassConstant) { + return $this->createFromReflectionClassConstant($reflector); + } + + throw new UnexpectedValueException('Unhandled \Reflector instance given: ' . get_class($reflector)); + } + + private function createFromReflectionParameter(ReflectionParameter $parameter): Context + { + $class = $parameter->getDeclaringClass(); + if (!$class) { + throw new InvalidArgumentException('Unable to get class of ' . $parameter->getName()); + } + + return $this->createFromReflectionClass($class); + } + + private function createFromReflectionMethod(ReflectionMethod $method): Context + { + $class = $method->getDeclaringClass(); + + return $this->createFromReflectionClass($class); + } + + private function createFromReflectionProperty(ReflectionProperty $property): Context + { + $class = $property->getDeclaringClass(); + + return $this->createFromReflectionClass($class); + } + + private function createFromReflectionClassConstant(ReflectionClassConstant $constant): Context + { + //phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable + /** @phpstan-var ReflectionClass<object> $class */ + $class = $constant->getDeclaringClass(); + + return $this->createFromReflectionClass($class); + } + + /** + * @phpstan-param ReflectionClass<object> $class + */ + private function createFromReflectionClass(ReflectionClass $class): Context + { + $fileName = $class->getFileName(); + $namespace = $class->getNamespaceName(); + + if (is_string($fileName) && file_exists($fileName)) { + $contents = file_get_contents($fileName); + if ($contents === false) { + throw new RuntimeException('Unable to read file "' . $fileName . '"'); + } + + return $this->createForNamespace($namespace, $contents); + } + + return new Context($namespace, []); + } + + /** + * Build a Context for a namespace in the provided file contents. + * + * @see Context for more information on Contexts. + * + * @param string $namespace It does not matter if a `\` precedes the namespace name, + * this method first normalizes. + * @param string $fileContents The file's contents to retrieve the aliases from with the given namespace. + */ + public function createForNamespace(string $namespace, string $fileContents): Context + { + $namespace = trim($namespace, '\\'); + $useStatements = []; + $currentNamespace = ''; + $tokens = new ArrayIterator(token_get_all($fileContents)); + + while ($tokens->valid()) { + $currentToken = $tokens->current(); + switch ($currentToken[0]) { + case T_NAMESPACE: + $currentNamespace = $this->parseNamespace($tokens); + break; + case T_CLASS: + case T_TRAIT: + // Fast-forward the iterator through the class so that any + // T_USE tokens found within are skipped - these are not + // valid namespace use statements so should be ignored. + $braceLevel = 0; + $firstBraceFound = false; + while ($tokens->valid() && ($braceLevel > 0 || !$firstBraceFound)) { + $currentToken = $tokens->current(); + if ( + $currentToken === '{' + || in_array($currentToken[0], [T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES], true) + ) { + if (!$firstBraceFound) { + $firstBraceFound = true; + } + + ++$braceLevel; + } + + if ($currentToken === '}') { + --$braceLevel; + } + + $tokens->next(); + } + + break; + case T_USE: + if ($currentNamespace === $namespace) { + $useStatements += $this->parseUseStatement($tokens); + } + + break; + } + + $tokens->next(); + } + + return new Context($namespace, $useStatements); + } + + /** + * Deduce the name from tokens when we are at the T_NAMESPACE token. + * + * @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens + */ + private function parseNamespace(ArrayIterator $tokens): string + { + // skip to the first string or namespace separator + $this->skipToNextStringOrNamespaceSeparator($tokens); + + $name = ''; + $acceptedTokens = [T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED]; + while ($tokens->valid() && in_array($tokens->current()[0], $acceptedTokens, true)) { + $name .= $tokens->current()[1]; + $tokens->next(); + } + + return $name; + } + + /** + * Deduce the names of all imports when we are at the T_USE token. + * + * @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens + * + * @return string[] + * @psalm-return array<string, string> + */ + private function parseUseStatement(ArrayIterator $tokens): array + { + $uses = []; + + while ($tokens->valid()) { + $this->skipToNextStringOrNamespaceSeparator($tokens); + + $uses += $this->extractUseStatements($tokens); + $currentToken = $tokens->current(); + if ($currentToken[0] === self::T_LITERAL_END_OF_USE) { + return $uses; + } + } + + return $uses; + } + + /** + * Fast-forwards the iterator as longs as we don't encounter a T_STRING or T_NS_SEPARATOR token. + * + * @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens + */ + private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens): void + { + while ($tokens->valid()) { + $currentToken = $tokens->current(); + if (in_array($currentToken[0], [T_STRING, T_NS_SEPARATOR], true)) { + break; + } + + if ($currentToken[0] === T_NAME_QUALIFIED) { + break; + } + + if (defined('T_NAME_FULLY_QUALIFIED') && $currentToken[0] === T_NAME_FULLY_QUALIFIED) { + break; + } + + $tokens->next(); + } + } + + /** + * Deduce the namespace name and alias of an import when we are at the T_USE token or have not reached the end of + * a USE statement yet. This will return a key/value array of the alias => namespace. + * + * @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens + * + * @return string[] + * @psalm-return array<string, string> + * + * @psalm-suppress TypeDoesNotContainType + */ + private function extractUseStatements(ArrayIterator $tokens): array + { + $extractedUseStatements = []; + $groupedNs = ''; + $currentNs = ''; + $currentAlias = ''; + $state = 'start'; + + while ($tokens->valid()) { + $currentToken = $tokens->current(); + $tokenId = is_string($currentToken) ? $currentToken : $currentToken[0]; + $tokenValue = is_string($currentToken) ? null : $currentToken[1]; + switch ($state) { + case 'start': + switch ($tokenId) { + case T_STRING: + case T_NS_SEPARATOR: + $currentNs .= (string) $tokenValue; + $currentAlias = $tokenValue; + break; + case T_NAME_QUALIFIED: + case T_NAME_FULLY_QUALIFIED: + $currentNs .= (string) $tokenValue; + $currentAlias = substr( + (string) $tokenValue, + (int) (strrpos((string) $tokenValue, '\\')) + 1 + ); + break; + case T_CURLY_OPEN: + case '{': + $state = 'grouped'; + $groupedNs = $currentNs; + break; + case T_AS: + $state = 'start-alias'; + break; + case self::T_LITERAL_USE_SEPARATOR: + case self::T_LITERAL_END_OF_USE: + $state = 'end'; + break; + default: + break; + } + + break; + case 'start-alias': + switch ($tokenId) { + case T_STRING: + $currentAlias = $tokenValue; + break; + case self::T_LITERAL_USE_SEPARATOR: + case self::T_LITERAL_END_OF_USE: + $state = 'end'; + break; + default: + break; + } + + break; + case 'grouped': + switch ($tokenId) { + case T_STRING: + case T_NS_SEPARATOR: + $currentNs .= (string) $tokenValue; + $currentAlias = $tokenValue; + break; + case T_AS: + $state = 'grouped-alias'; + break; + case self::T_LITERAL_USE_SEPARATOR: + $state = 'grouped'; + $extractedUseStatements[(string) $currentAlias] = $currentNs; + $currentNs = $groupedNs; + $currentAlias = ''; + break; + case self::T_LITERAL_END_OF_USE: + $state = 'end'; + break; + default: + break; + } + + break; + case 'grouped-alias': + switch ($tokenId) { + case T_STRING: + $currentAlias = $tokenValue; + break; + case self::T_LITERAL_USE_SEPARATOR: + $state = 'grouped'; + $extractedUseStatements[(string) $currentAlias] = $currentNs; + $currentNs = $groupedNs; + $currentAlias = ''; + break; + case self::T_LITERAL_END_OF_USE: + $state = 'end'; + break; + default: + break; + } + } + + if ($state === 'end') { + break; + } + + $tokens->next(); + } + + if ($groupedNs !== $currentNs) { + $extractedUseStatements[(string) $currentAlias] = $currentNs; + } + + return $extractedUseStatements; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Expression.php b/vendor/phpdocumentor/type-resolver/src/Types/Expression.php new file mode 100644 index 0000000..da5f65d --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Expression.php @@ -0,0 +1,51 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Represents an expression type as described in the PSR-5, the PHPDoc Standard. + * + * @psalm-immutable + */ +final class Expression implements Type +{ + /** @var Type */ + protected $valueType; + + /** + * Initializes this representation of an array with the given Type. + */ + public function __construct(Type $valueType) + { + $this->valueType = $valueType; + } + + /** + * Returns the value for the keys of this array. + */ + public function getValueType(): Type + { + return $this->valueType; + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return '(' . $this->valueType . ')'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Float_.php b/vendor/phpdocumentor/type-resolver/src/Types/Float_.php new file mode 100644 index 0000000..85313a7 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Float_.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing a Float. + * + * @psalm-immutable + */ +class Float_ implements Type +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'float'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Integer.php b/vendor/phpdocumentor/type-resolver/src/Types/Integer.php new file mode 100644 index 0000000..10ce3c5 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Integer.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value object representing Integer type + * + * @psalm-immutable + */ +class Integer implements Type +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'int'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Intersection.php b/vendor/phpdocumentor/type-resolver/src/Types/Intersection.php new file mode 100644 index 0000000..80ac822 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Intersection.php @@ -0,0 +1,37 @@ +<?php +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing a Intersection Type. + * + * A Intersection Type is not so much a special keyword or object reference but is a series of Types that are separated + * using an AND operator (`&`). This combination of types signifies that whatever is associated with this Intersection + * type may contain a value with any of the given types. + * + * @psalm-immutable + */ +final class Intersection extends AggregatedType +{ + /** + * Initializes a intersection type (i.e. `\A&\B`) and tests if the provided types all implement the Type interface. + * + * @param array<Type> $types + */ + public function __construct(array $types) + { + parent::__construct($types, '&'); + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Iterable_.php b/vendor/phpdocumentor/type-resolver/src/Types/Iterable_.php new file mode 100644 index 0000000..3ac6ef6 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Iterable_.php @@ -0,0 +1,38 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +/** + * Value Object representing iterable type + * + * @psalm-immutable + */ +final class Iterable_ extends AbstractList +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + if ($this->valueType === null) { + return 'iterable'; + } + + if ($this->keyType) { + return 'iterable<' . $this->keyType . ', ' . $this->valueType . '>'; + } + + return 'iterable<' . $this->valueType . '>'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Mixed_.php b/vendor/phpdocumentor/type-resolver/src/Types/Mixed_.php new file mode 100644 index 0000000..908f45e --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Mixed_.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing an unknown, or mixed, type. + * + * @psalm-immutable + */ +class Mixed_ implements Type +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'mixed'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Never_.php b/vendor/phpdocumentor/type-resolver/src/Types/Never_.php new file mode 100644 index 0000000..fefc0a4 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Never_.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing the return-type 'never'. + * + * Never is generally only used when working with return types as it signifies that the method that only + * ever throw or exit. + * + * @psalm-immutable + */ +class Never_ implements Type +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'never'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Null_.php b/vendor/phpdocumentor/type-resolver/src/Types/Null_.php new file mode 100644 index 0000000..7ae802c --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Null_.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing a null value or type. + * + * @psalm-immutable + */ +final class Null_ implements Type +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'null'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Nullable.php b/vendor/phpdocumentor/type-resolver/src/Types/Nullable.php new file mode 100644 index 0000000..a946935 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Nullable.php @@ -0,0 +1,51 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing a nullable type. The real type is wrapped. + * + * @psalm-immutable + */ +final class Nullable implements Type +{ + /** @var Type The actual type that is wrapped */ + private $realType; + + /** + * Initialises this nullable type using the real type embedded + */ + public function __construct(Type $realType) + { + $this->realType = $realType; + } + + /** + * Provide access to the actual type directly, if needed. + */ + public function getActualType(): Type + { + return $this->realType; + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return '?' . $this->realType->__toString(); + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Object_.php b/vendor/phpdocumentor/type-resolver/src/Types/Object_.php new file mode 100644 index 0000000..649f945 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Object_.php @@ -0,0 +1,69 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use InvalidArgumentException; +use phpDocumentor\Reflection\Fqsen; +use phpDocumentor\Reflection\Type; + +use function strpos; + +/** + * Value Object representing an object. + * + * An object can be either typed or untyped. When an object is typed it means that it has an identifier, the FQSEN, + * pointing to an element in PHP. Object types that are untyped do not refer to a specific class but represent objects + * in general. + * + * @psalm-immutable + */ +class Object_ implements Type +{ + /** @var Fqsen|null */ + protected $fqsen; + + /** + * Initializes this object with an optional FQSEN, if not provided this object is considered 'untyped'. + * + * @throws InvalidArgumentException When provided $fqsen is not a valid type. + */ + public function __construct(?Fqsen $fqsen = null) + { + if (strpos((string) $fqsen, '::') !== false || strpos((string) $fqsen, '()') !== false) { + throw new InvalidArgumentException( + 'Object types can only refer to a class, interface or trait but a method, function, constant or ' + . 'property was received: ' . (string) $fqsen + ); + } + + $this->fqsen = $fqsen; + } + + /** + * Returns the FQSEN associated with this object. + */ + public function getFqsen(): ?Fqsen + { + return $this->fqsen; + } + + public function __toString(): string + { + if ($this->fqsen) { + return (string) $this->fqsen; + } + + return 'object'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Parent_.php b/vendor/phpdocumentor/type-resolver/src/Types/Parent_.php new file mode 100644 index 0000000..3483859 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Parent_.php @@ -0,0 +1,34 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing the 'parent' type. + * + * Parent, as a Type, represents the parent class of class in which the associated element was defined. + * + * @psalm-immutable + */ +final class Parent_ implements Type +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'parent'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Resource_.php b/vendor/phpdocumentor/type-resolver/src/Types/Resource_.php new file mode 100644 index 0000000..46ad777 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Resource_.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing the 'resource' Type. + * + * @psalm-immutable + */ +class Resource_ implements Type +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'resource'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Self_.php b/vendor/phpdocumentor/type-resolver/src/Types/Self_.php new file mode 100644 index 0000000..b3fc783 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Self_.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +use function implode; + +/** + * Value Object representing the 'self' type. + * + * Self, as a Type, represents the class in which the associated element was defined. + * + * @psalm-immutable + */ +final class Self_ implements Type +{ + /** @var Type[] */ + private $genericTypes; + + public function __construct(Type ...$genericTypes) + { + $this->genericTypes = $genericTypes; + } + + /** + * @return Type[] + */ + public function getGenericTypes(): array + { + return $this->genericTypes; + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + if ($this->genericTypes) { + return 'self<' . implode(', ', $this->genericTypes) . '>'; + } + + return 'self'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Static_.php b/vendor/phpdocumentor/type-resolver/src/Types/Static_.php new file mode 100644 index 0000000..eb14ecb --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Static_.php @@ -0,0 +1,61 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +use function implode; + +/** + * Value Object representing the 'static' type. + * + * Self, as a Type, represents the class in which the associated element was called. This differs from self as self does + * not take inheritance into account but static means that the return type is always that of the class of the called + * element. + * + * See the documentation on late static binding in the PHP Documentation for more information on the difference between + * static and self. + * + * @psalm-immutable + */ +final class Static_ implements Type +{ + /** @var Type[] */ + private $genericTypes; + + public function __construct(Type ...$genericTypes) + { + $this->genericTypes = $genericTypes; + } + + /** + * @return Type[] + */ + public function getGenericTypes(): array + { + return $this->genericTypes; + } + + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + if ($this->genericTypes) { + return 'static<' . implode(', ', $this->genericTypes) . '>'; + } + + return 'static'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/String_.php b/vendor/phpdocumentor/type-resolver/src/Types/String_.php new file mode 100644 index 0000000..a4bb47f --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/String_.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing the type 'string'. + * + * @psalm-immutable + */ +class String_ implements Type +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'string'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/This.php b/vendor/phpdocumentor/type-resolver/src/Types/This.php new file mode 100644 index 0000000..602fc69 --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/This.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing the '$this' pseudo-type. + * + * $this, as a Type, represents the instance of the class associated with the element as it was called. $this is + * commonly used when documenting fluent interfaces since it represents that the same object is returned. + * + * @psalm-immutable + */ +final class This implements Type +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return '$this'; + } +} diff --git a/vendor/phpdocumentor/type-resolver/src/Types/Void_.php b/vendor/phpdocumentor/type-resolver/src/Types/Void_.php new file mode 100644 index 0000000..23a601d --- /dev/null +++ b/vendor/phpdocumentor/type-resolver/src/Types/Void_.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +/** + * This file is part of phpDocumentor. + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\Types; + +use phpDocumentor\Reflection\Type; + +/** + * Value Object representing the return-type 'void'. + * + * Void is generally only used when working with return types as it signifies that the method intentionally does not + * return any value. + * + * @psalm-immutable + */ +final class Void_ implements Type +{ + /** + * Returns a rendered output of the Type as it would be used in a DocBlock. + */ + public function __toString(): string + { + return 'void'; + } +} |
