From 2c18f0e883a22b0f1559cbc006d06936222314fa Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Sat, 13 Jun 2015 14:30:43 +0200 Subject: [PATCH] Work towards stabilizing the API. - Changed Tag to an interface and flattened hierarchy - Changed Description to accept a list of tags and a template - Allow auto-wiring when constructing tags --- .gitignore | 1 - composer.json | 3 +- composer.lock | 1135 +++++++++++++++++++++++++++ src/DocBlock/Description.php | 19 +- src/DocBlock/DescriptionFactory.php | 15 +- src/DocBlock/Tag.php | 79 +- src/DocBlock/TagFactory.php | 63 +- src/DocBlock/Tags/Author.php | 9 +- src/DocBlock/Tags/BaseTag.php | 55 ++ src/DocBlock/Tags/Covers.php | 23 +- src/DocBlock/Tags/Deprecated.php | 9 +- src/DocBlock/Tags/Other.php | 78 ++ src/DocBlock/Tags/Param.php | 109 ++- src/DocBlock/Tags/Return_.php | 77 +- src/DocBlock/Tags/See.php | 4 +- src/DocBlock/Tags/Version.php | 4 +- src/DocBlockFactory.php | 10 +- 17 files changed, 1463 insertions(+), 230 deletions(-) create mode 100644 composer.lock create mode 100644 src/DocBlock/Tags/BaseTag.php create mode 100644 src/DocBlock/Tags/Other.php diff --git a/.gitignore b/.gitignore index 82cfc4e..3ce5adb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .idea -composer.lock vendor diff --git a/composer.json b/composer.json index 802f3f5..08bbb23 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ ], "require": { "php": ">=5.5", - "phpdocumentor/reflection-common": "dev-master@dev" + "phpdocumentor/reflection-common": "^0.1", + "phpdocumentor/type-resolver": "^1.0@dev" }, "autoload": { "psr-4": {"phpDocumentor\\Reflection\\": ["src/"]} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..22b1fbf --- /dev/null +++ b/composer.lock @@ -0,0 +1,1135 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "3dfae8837b6c37701c1285da903c3426", + "packages": [ + { + "name": "phpdocumentor/reflection-common", + "version": "0.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "f10c8a4e2afd1b106550b0a5b0e8db81742377f1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/f10c8a4e2afd1b106550b0a5b0e8db81742377f1", + "reference": "f10c8a4e2afd1b106550b0a5b0e8db81742377f1", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-06-12 17:27:38" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "2ac0adaea9697334b85b1622ce930014e6b02a11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2ac0adaea9697334b85b1622ce930014e6b02a11", + "reference": "2ac0adaea9697334b85b1622ce930014e6b02a11", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^0.1" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2015-06-12 22:00:00" + } + ], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "2.0.*@ALPHA" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Instantiator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2014-10-13 12:58:55" + }, + { + "name": "hamcrest/hamcrest-php", + "version": "v1.2.2", + "source": { + "type": "git", + "url": "https://github.com/hamcrest/hamcrest-php.git", + "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/b37020aa976fa52d3de9aa904aa2522dc518f79c", + "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "replace": { + "cordoval/hamcrest-php": "*", + "davedevelopment/hamcrest-php": "*", + "kodova/hamcrest-php": "*" + }, + "require-dev": { + "phpunit/php-file-iterator": "1.3.3", + "satooshi/php-coveralls": "dev-master" + }, + "type": "library", + "autoload": { + "classmap": [ + "hamcrest" + ], + "files": [ + "hamcrest/Hamcrest.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD" + ], + "description": "This is the PHP port of Hamcrest Matchers", + "keywords": [ + "test" + ], + "time": "2015-05-11 14:41:42" + }, + { + "name": "mockery/mockery", + "version": "0.9.4", + "source": { + "type": "git", + "url": "https://github.com/padraic/mockery.git", + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/padraic/mockery/zipball/70bba85e4aabc9449626651f48b9018ede04f86b", + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b", + "shasum": "" + }, + "require": { + "hamcrest/hamcrest-php": "~1.1", + "lib-pcre": ">=7.0", + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.9.x-dev" + } + }, + "autoload": { + "psr-0": { + "Mockery": "library/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Padraic Brady", + "email": "padraic.brady@gmail.com", + "homepage": "http://blog.astrumfutura.com" + }, + { + "name": "Dave Marshall", + "email": "dave.marshall@atstsolutions.co.uk", + "homepage": "http://davedevelopment.co.uk" + } + ], + "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.", + "homepage": "http://github.com/padraic/mockery", + "keywords": [ + "BDD", + "TDD", + "library", + "mock", + "mock objects", + "mockery", + "stub", + "test", + "test double", + "testing" + ], + "time": "2015-04-02 19:54:00" + }, + { + "name": "phpspec/prophecy", + "version": "v1.4.1", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "phpdocumentor/reflection-docblock": "~2.0", + "sebastian/comparator": "~1.1" + }, + "require-dev": { + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2015-04-27 22:15:08" + }, + { + "name": "phpunit/php-code-coverage", + "version": "2.1.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "be2286cb8c7e1773eded49d9719219e6f74f9e3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/be2286cb8c7e1773eded49d9719219e6f74f9e3e", + "reference": "be2286cb8c7e1773eded49d9719219e6f74f9e3e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "~1.0", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2015-06-09 13:05:42" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2015-04-02 05:19:05" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2014-01-30 17:20:04" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/83fe1bdc5d47658b727595c14da140da92b3d66d", + "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2015-06-13 07:35:30" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "db63be1159c81df649cd0260e30249a586d4129e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/db63be1159c81df649cd0260e30249a586d4129e", + "reference": "db63be1159c81df649cd0260e30249a586d4129e", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2015-06-12 07:34:24" + }, + { + "name": "phpunit/phpunit", + "version": "4.7.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "41fea1e84ed84d373f5ac099a1276c4358c90708" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/41fea1e84ed84d373f5ac099a1276c4358c90708", + "reference": "41fea1e84ed84d373f5ac099a1276c4358c90708", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpspec/prophecy": "~1.3,>=1.3.1", + "phpunit/php-code-coverage": "~2.1", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "~1.0", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.1", + "sebastian/diff": "~1.2", + "sebastian/environment": "~1.2", + "sebastian/exporter": "~1.2", + "sebastian/global-state": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.1|~3.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.7.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2015-06-11 16:20:25" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "2.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/92408bb1968a81b3217a6fdf6c1a198da83caa35", + "reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "~1.0,>=1.0.2", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2015-06-11 15:55:48" + }, + { + "name": "sebastian/comparator", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2015-01-29 16:28:08" + }, + { + "name": "sebastian/diff", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-02-22 15:13:53" + }, + { + "name": "sebastian/environment", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2015-01-01 10:01:08" + }, + { + "name": "sebastian/exporter", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "84839970d05254c73cde183a721c7af13aede943" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", + "reference": "84839970d05254c73cde183a721c7af13aede943", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2015-01-27 07:23:06" + }, + { + "name": "sebastian/global-state", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2014-10-06 09:23:50" + }, + { + "name": "sebastian/recursion-context", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2015-01-24 09:48:32" + }, + { + "name": "sebastian/version", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2015-02-24 06:35:25" + }, + { + "name": "symfony/yaml", + "version": "v2.7.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/9808e75c609a14f6db02f70fccf4ca4aab53c160", + "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2015-06-10 15:30:22" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "phpdocumentor/type-resolver": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.5" + }, + "platform-dev": [] +} diff --git a/src/DocBlock/Description.php b/src/DocBlock/Description.php index 1e5703b..087aa6a 100644 --- a/src/DocBlock/Description.php +++ b/src/DocBlock/Description.php @@ -15,20 +15,24 @@ namespace phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlock\Description\Formatter; use phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter; - class Description { - /** @var Tag[]|string[] The contents, as an array of strings and Tag objects */ - private $tokens; + /** @var string */ + private $body; + + /** @var Tag[] */ + private $tags; /** * Initializes a this object with a series of tokens of which a description consists. * - * @param Tag[]|string[] $tokens + * @param string $body + * @param Tag[] $tags */ - public function __construct(array $tokens) + public function __construct($body, array $tags = []) { - $this->tokens = $tokens; + $this->body = $body; + $this->tags = $tags; } /** @@ -44,7 +48,6 @@ class Description $formatter = new PassthroughFormatter(); } - return $formatter->format($this->tokens); + return vsprintf($this->body, $formatter->format($this->tags)); } - } diff --git a/src/DocBlock/DescriptionFactory.php b/src/DocBlock/DescriptionFactory.php index 9bcf057..68d44ea 100644 --- a/src/DocBlock/DescriptionFactory.php +++ b/src/DocBlock/DescriptionFactory.php @@ -12,6 +12,8 @@ namespace phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\Types\Context; + final class DescriptionFactory { /** @var TagFactory */ @@ -33,11 +35,13 @@ final class DescriptionFactory * @param string $contents * @param Context $context * - * @return array An array of strings and tag objects, in the order they occur within the description. + * @return Description */ public function create($contents, Context $context = null) { - return new Description($this->parse($this->lex($contents), $context)); + list($text, $tags) = $this->parse($this->lex($contents), $context); + + return new Description($text, $tags); } /** @@ -93,8 +97,11 @@ final class DescriptionFactory private function parse($tokens, Context $context) { $count = count($tokens); + $tagCount = 0; + $tags = []; for ($i = 1; $i < $count; $i += 2) { - $tokens[$i] = $this->tagFactory->create($tokens[$i], $context); + $tokens[$i] = ++$tagCount; + $tags[] = $this->tagFactory->create($tokens[$i], $context); } //In order to allow "literal" inline tags, the otherwise invalid @@ -104,7 +111,7 @@ final class DescriptionFactory $tokens[$i] = str_replace(['{@}', '{}'], ['@', '}'], $tokens[$i]); } - return $tokens; + return [implode('', $tokens), $tags]; } } diff --git a/src/DocBlock/Tag.php b/src/DocBlock/Tag.php index fa9e2a3..5184e04 100644 --- a/src/DocBlock/Tag.php +++ b/src/DocBlock/Tag.php @@ -12,82 +12,13 @@ namespace phpDocumentor\Reflection\DocBlock; -use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Description\Formatter; -/** - * Parses a tag definition for a DocBlock. - */ -class Tag +interface Tag { - /** @var string Name of the tag */ - protected $name = ''; + public static function create($body); - /** @var Description|null Description of the tag. */ - protected $description; + public function render(Formatter $formatter = null); - /** - * Parses a tag and populates the member variables. - * - * We explicitly do not type-hint the $description so that classes inheriting this class can override the - * constructor without running into PHP notices. - * - * @param string $name Name of the tag. - * @param Description $description The contents of the given tag. - */ - public function __construct($name, $description) - { - $this->validateTagName($name); - if (!$description instanceof Description) { - throw new \InvalidArgumentException('The description should be an object of type Description'); - } - - $this->name = $name; - $this->description = $description; - } - - /** - * Gets the name of this tag. - * - * @return string The name of this tag. - */ - public function getName() - { - return $this->name; - } - - public function render(DocBlock\Description\Formatter $formatter = null) - { - if (!$formatter) { - $formatter = new DocBlock\Description\PassthroughFormatter(); - } - - return $formatter->format([$this]); - } - - /** - * Returns the tag as a serialized string - * - * @return string - */ - public function __toString() - { - return "@{$this->getName()} {$this->description->render()}"; - } - - /** - * Validates if the tag name matches the expected format, otherwise throws an exception. - * - * @param string $name - * - * @return void - */ - private function validateTagName($name) - { - if (!preg_match('/^' . TagFactory::REGEX_TAGNAME . '$/u', $name)) { - throw new \InvalidArgumentException( - 'The tag name "' . $name . '" is not wellformed. Tags may only consist of letters, underscores, ' - . 'hyphens and backslashes.' - ); - } - } + public function __toString(); } diff --git a/src/DocBlock/TagFactory.php b/src/DocBlock/TagFactory.php index fc2c2c4..64563fa 100644 --- a/src/DocBlock/TagFactory.php +++ b/src/DocBlock/TagFactory.php @@ -12,7 +12,8 @@ namespace phpDocumentor\Reflection\DocBlock; -use phpDocumentor\Reflection\FqsenFactory; +use phpDocumentor\Reflection\FqsenResolver; +use phpDocumentor\Reflection\Types\Context; final class TagFactory { @@ -44,12 +45,26 @@ final class TagFactory 'version' => '\phpDocumentor\Reflection\DocBlock\Tags\Version' ); - /** @var FqsenFactory */ - private $fqsenFactory; + /** @var FqsenResolver */ + private $fqsenResolver; - public function __construct(FqsenFactory $fqsenFactory) + /** @var mixed[] */ + private $serviceLocator = []; + + public function __construct(FqsenResolver $fqsenResolver) { - $this->fqsenFactory = $fqsenFactory; + $this->fqsenResolver = $fqsenResolver; + $this->addService($fqsenResolver); + } + + public function addParameter($name, $value) + { + $this->serviceLocator[$name] = $value; + } + + public function addService($service) + { + $this->serviceLocator[get_class($service)] = $service; } /** @@ -67,19 +82,47 @@ final class TagFactory if (!$context) { $context = new Context(''); } - list($tagName, $tagDescription) = $this->extractTagParts($tagLine); + list($tagName, $tagBody) = $this->extractTagParts($tagLine); $handler = Tag::class; if (isset($this->tagHandlerMappings[$tagName])) { $handler = $this->tagHandlerMappings[$tagName]; } elseif ($this->isAnnotation($tagName)) { - $tagName = (string)$this->fqsenFactory->create($tagName, $context); + $tagName = (string)$this->fqsenResolver->resolve($tagName, $context); if (isset($this->tagHandlerMappings[$tagName])) { $handler = $this->tagHandlerMappings[$tagName]; } } - return $handler::create($tagName, $tagDescription); + $parameters = (new \ReflectionMethod($handler, 'create'))->getParameters(); + + $wiring = array_merge( + $this->serviceLocator, + [ + 'name' => $tagName, + 'body' => $tagBody, + Context::class => $context + ] + ); + + $arguments = []; + foreach ($parameters as $index => $parameter) { + $typeHint = $parameter->getClass() ? $parameter->getClass()->getName() : null; + if (isset($wiring[$typeHint])) { + $arguments[] = $wiring[$typeHint]; + continue; + } + + $parameterName = $parameter->getName(); + if (isset($wiring[$parameterName])) { + $arguments[] = $wiring[$parameterName]; + continue; + } + + $arguments[] = null; + } + + return call_user_func_array([$handler, 'create'], $arguments); } /** @@ -126,11 +169,11 @@ final class TagFactory ); } - if (count($matches) == 1) { + if (count($matches) < 3) { $matches[] = ''; } - return $matches; + return array_slice($matches, 1); } private function isAnnotation($tag) diff --git a/src/DocBlock/Tags/Author.php b/src/DocBlock/Tags/Author.php index 9b3195d..3805708 100644 --- a/src/DocBlock/Tags/Author.php +++ b/src/DocBlock/Tags/Author.php @@ -13,12 +13,11 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use phpDocumentor\Reflection\DocBlock\Description; -use phpDocumentor\Reflection\DocBlock\Tag; /** * Reflection class for an {@}author tag in a Docblock. */ -final class Author extends Tag +final class Author extends BaseTag { /** @var string register that this is the author tag. */ protected $name = 'author'; @@ -44,7 +43,7 @@ final class Author extends Tag throw new \InvalidArgumentException('The author tag does not have a valid e-mail address'); } - $this->authorName = $authorName; + $this->authorName = $authorName; $this->authorEmail = $authorEmail; } @@ -81,9 +80,9 @@ final class Author extends Tag /** * {@inheritdoc} */ - public static function create($content) + public static function create($body) { - $splitTagContent = preg_match('/^([^\<]*)(?:\<([^\>]*)\>)?$/u', $content, $matches); + $splitTagContent = preg_match('/^([^\<]*)(?:\<([^\>]*)\>)?$/u', $body, $matches); if (!$splitTagContent) { return null; } diff --git a/src/DocBlock/Tags/BaseTag.php b/src/DocBlock/Tags/BaseTag.php new file mode 100644 index 0000000..e4d5e44 --- /dev/null +++ b/src/DocBlock/Tags/BaseTag.php @@ -0,0 +1,55 @@ + + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\TagFactory; +use phpDocumentor\Reflection\Types\Context; + +/** + * Parses a tag definition for a DocBlock. + */ +abstract class BaseTag implements DocBlock\Tag +{ + /** @var string Name of the tag */ + protected $name = ''; + + /** @var Description|null Description of the tag. */ + protected $description; + + /** + * Gets the name of this tag. + * + * @return string The name of this tag. + */ + public function getName() + { + return $this->name; + } + + public function getDescription() + { + return $this->description; + } + + public function render(DocBlock\Description\Formatter $formatter = null) + { + if (!$formatter) { + $formatter = new DocBlock\Description\PassthroughFormatter(); + } + + return $formatter->format([$this]); + } +} diff --git a/src/DocBlock/Tags/Covers.php b/src/DocBlock/Tags/Covers.php index d3e0b20..c2ce19c 100644 --- a/src/DocBlock/Tags/Covers.php +++ b/src/DocBlock/Tags/Covers.php @@ -12,20 +12,17 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; -use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Context; -use DocBlock\Types\Resolver; +use phpDocumentor\Reflection\FqsenResolver; +use phpDocumentor\Reflection\TypeResolver; /** * Reflection class for a @covers tag in a Docblock. - * - * @author Mike van Riel - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org */ -class Covers extends Tag +class Covers extends BaseTag { /** @var Fqsen */ protected $refers = null; @@ -45,14 +42,18 @@ class Covers extends Tag /** * {@inheritdoc} */ - public static function create($content, Context $context) + public static function create( + $body, + DescriptionFactory $descriptionFactory = null, + FqsenResolver $resolver = null, + Context $context = null + ) { - $parts = preg_split('/\s+/Su', $content, 2); - $resolver = new Resolver(); + $parts = preg_split('/\s+/Su', $body, 2); return new static( $resolver->resolve($parts[0], $context), - new Description(isset($parts[1]) ? $parts[1] : '', $context) + $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context) ); } diff --git a/src/DocBlock/Tags/Deprecated.php b/src/DocBlock/Tags/Deprecated.php index f998fa8..1d42a84 100644 --- a/src/DocBlock/Tags/Deprecated.php +++ b/src/DocBlock/Tags/Deprecated.php @@ -14,12 +14,13 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use phpDocumentor\Reflection\DocBlock\Context; use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\Tag; /** * Reflection class for a {@}deprecated tag in a Docblock. */ -final class Deprecated extends Tag +final class Deprecated extends BaseTag { /** * PCRE regular expression matching a version vector. @@ -49,16 +50,16 @@ final class Deprecated extends Tag /** * {@inheritdoc} */ - public static function create($content, Context $context = null) + public static function create($body, DescriptionFactory $descriptionFactory = null, Context $context = null) { $matches = []; - if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $content, $matches)) { + if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { return null; } return new static( $matches[1], - new Description(isset($matches[2]) ? $matches[2] : '', $context) + $descriptionFactory->create(isset($matches[2]) ? $matches[2] : '', $context) ); } diff --git a/src/DocBlock/Tags/Other.php b/src/DocBlock/Tags/Other.php new file mode 100644 index 0000000..50ce765 --- /dev/null +++ b/src/DocBlock/Tags/Other.php @@ -0,0 +1,78 @@ + + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tags; + +use Doctrine\Instantiator\Exception\InvalidArgumentException; +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\TagFactory; +use phpDocumentor\Reflection\Types\Context; + +/** + * Parses a tag definition for a DocBlock. + */ +class Other 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($name, Description $description = null) + { + $this->validateTagName($name); + + $this->name = $name; + $this->description = $description; + } + + public static function create( + $body, + $name = '', + DescriptionFactory $descriptionFactory = null, + Context $context = null + ) + { + $description = $descriptionFactory ? $descriptionFactory->create($body, $context) : null; + + return new static($name, $description); + } + + /** + * Returns the tag as a serialized string + * + * @return string + */ + public function __toString() + { + return "@{$this->getName()} {$this->description->render()}"; + } + + /** + * Validates if the tag name matches the expected format, otherwise throws an exception. + * + * @param string $name + * + * @return void + */ + private function validateTagName($name) + { + if (!preg_match('/^' . TagFactory::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/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 15814ab..1564b35 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -1,28 +1,34 @@ - * @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com) + * @copyright 2010-2015 Mike van Riel * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ namespace phpDocumentor\Reflection\DocBlock\Tags; +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; /** * Reflection class for a @param tag in a Docblock. - * - * @author Mike van Riel - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org */ -class Param extends Return_ +class Param extends BaseTag { + protected $name = 'param'; + + /** @var Type */ + private $type; + /** @var string */ protected $variableName = ''; @@ -30,56 +36,58 @@ class Param extends Return_ protected $isVariadic = false; /** - * {@inheritdoc} + * @param string $variableName + * @param Type $type + * @param bool $isVariadic + * @param Description $description */ - public function getContent() + public function __construct($variableName, Type $type = null, $isVariadic = false, Description $description = null) { - if (null === $this->description) { - $this->description - = "{$this->type} {$this->variableName} {$this->description}"; - } - return $this->description; + $this->variableName = $variableName; + $this->type = $type; + $this->isVariadic = $isVariadic; + $this->description = $description; } + /** * {@inheritdoc} */ - public function setContent($content) + public static function create( + $body, + TypeResolver $typeResolver = null, + DescriptionFactory $descriptionFactory = null, + Context $context = null + ) { - Tag::setContent($content); - $parts = preg_split( - '/(\s+)/Su', - $this->description, - 3, - PREG_SPLIT_DELIM_CAPTURE - ); + $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); + $type = null; + $variableName = ''; + $isVariadic = false; // if the first item that is encountered is not a variable; it is a type - if (isset($parts[0]) - && (strlen($parts[0]) > 0) - && ($parts[0][0] !== '$') - ) { - $this->type = array_shift($parts); + if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) { + $type = $typeResolver->resolve(array_shift($parts), $context); array_shift($parts); } // if the next item starts with a $ or ...$ it must be the variable name - if (isset($parts[0]) - && (strlen($parts[0]) > 0) - && ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$') - ) { - $this->variableName = array_shift($parts); + if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$')) { + $variableName = array_shift($parts); array_shift($parts); - if (substr($this->variableName, 0, 3) === '...') { - $this->isVariadic = true; - $this->variableName = substr($this->variableName, 3); + if (substr($variableName, 0, 3) === '...') { + $isVariadic = true; + $variableName = substr($variableName, 3); + } + + if (substr($variableName, 0, 1) === '$') { + $variableName = substr($variableName, 1); } } - $this->setDescription(implode('', $parts)); + $description = $descriptionFactory->create(implode('', $parts), $context); - $this->description = $content; - return $this; + return new static($variableName, $type, $isVariadic, $description); } /** @@ -92,21 +100,6 @@ class Param extends Return_ return $this->variableName; } - /** - * Sets the variable's name. - * - * @param string $name The new name for this variable. - * - * @return $this - */ - public function setVariableName($name) - { - $this->variableName = $name; - - $this->description = null; - return $this; - } - /** * Returns whether this tag is variadic. * @@ -116,4 +109,10 @@ class Param extends Return_ { return $this->isVariadic; } + + public function __toString() + { + return $this->type . ' ' . ($this->isVariadic() ? '...' : '') . '$' . $this->variableName . ' ' + . $this->description; + } } diff --git a/src/DocBlock/Tags/Return_.php b/src/DocBlock/Tags/Return_.php index b6a765f..98b6357 100644 --- a/src/DocBlock/Tags/Return_.php +++ b/src/DocBlock/Tags/Return_.php @@ -12,84 +12,59 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; -use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Description; +use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\Type\Collection; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; /** * Reflection class for a @return tag in a Docblock. */ -class Return_ extends Tag +final class Return_ extends BaseTag { - /** @var string The raw type component. */ - protected $type = ''; + protected $name = 'return'; - /** @var Collection The parsed type component. */ - protected $types = null; + /** @var Type */ + private $type; - /** - * {@inheritdoc} - */ - public function getContent() + public function __construct(Type $type, Description $description = null) { - if (null === $this->description) { - $this->description = "{$this->type} {$this->description}"; - } - - return $this->description; + $this->description = $description; + $this->type = $type; } /** * {@inheritdoc} */ - public function setContent($content) + public static function create( + $body, + TypeResolver $typeResolver = null, + DescriptionFactory $descriptionFactory = null, + Context $context = null + ) { - parent::setContent($content); + $parts = preg_split('/\s+/Su', $body, 2); - $parts = preg_split('/\s+/Su', $this->description, 2); + $type = $typeResolver->resolve(isset($parts[0]) ? $parts[0] : '', $context); + $description = $descriptionFactory->create(isset($parts[1]) ? $parts[1] : ''); - // any output is considered a type - $this->type = $parts[0]; - $this->types = null; - - $this->setDescription(isset($parts[1]) ? $parts[1] : ''); - - $this->description = $content; - return $this; + return new static($type, $description); } - /** - * Returns the unique types of the variable. - * - * @return string[] - */ - public function getTypes() + public function __toString() { - return $this->getTypesCollection()->getArrayCopy(); + return $this->type . ' ' . $this->description; } /** * Returns the type section of the variable. * - * @return string + * @return Type */ public function getType() { - return (string) $this->getTypesCollection(); - } - - /** - * Returns the type collection. - * - * @return void - */ - protected function getTypesCollection() - { - if (null === $this->types) { - $this->types = new Collection( - array($this->type), - $this->docblock ? $this->docblock->getContext() : null - ); - } - return $this->types; + return $this->type; } } diff --git a/src/DocBlock/Tags/See.php b/src/DocBlock/Tags/See.php index 159afb2..440baef 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -41,9 +41,9 @@ class See extends Tag /** * {@inheritdoc} */ - public static function create($content, Context $context) + public static function create($body, Context $context) { - $parts = preg_split('/\s+/Su', $content, 2); + $parts = preg_split('/\s+/Su', $body, 2); $resolver = new Resolver(); return new static( diff --git a/src/DocBlock/Tags/Version.php b/src/DocBlock/Tags/Version.php index ef6ccaf..64e1735 100644 --- a/src/DocBlock/Tags/Version.php +++ b/src/DocBlock/Tags/Version.php @@ -47,10 +47,10 @@ class Version extends Tag /** * {@inheritdoc} */ - public static function create($content, Context $context = null) + public static function create($body, Context $context = null) { $matches = []; - if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $content, $matches)) { + if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) { return null; } diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index ad04866..11b331a 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -47,12 +47,18 @@ final class DocBlockFactory implements DocBlockFactoryInterface */ public static function createInstance(array $additionalTags = []) { - $tagFactory = new TagFactory(new FqsenFactory()); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new TagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + + $tagFactory->addService($descriptionFactory); + $tagFactory->addService(new TypeResolver($fqsenResolver)); + foreach ($additionalTags as $tagName => $tagClassName) { $tagFactory->registerTagHandler($tagName, $tagClassName); } - return new self(new DescriptionFactory($tagFactory), $tagFactory); + return new self($descriptionFactory, $tagFactory); } /**