Commit 263640a8 by 杨树贤

降级包

parent 28a77aa4
Showing with 1741 additions and 1146 deletions
...@@ -12,7 +12,10 @@ ...@@ -12,7 +12,10 @@
"predis/predis": "^1.1", "predis/predis": "^1.1",
"vladimir-yuldashev/laravel-queue-rabbitmq": "5.2", "vladimir-yuldashev/laravel-queue-rabbitmq": "5.2",
"maatwebsite/excel": "2.1.0", "maatwebsite/excel": "2.1.0",
"guzzlehttp/guzzle": "6.3" "guzzlehttp/guzzle": "6.3",
"doctrine/inflector": "1.1.0",
"doctrine/instantiator": "1.0.2",
"phpdocumentor/reflection-docblock": "3.2.2"
}, },
"require-dev": { "require-dev": {
"fzaninotto/faker": "~1.4", "fzaninotto/faker": "~1.4",
...@@ -55,6 +58,9 @@ ...@@ -55,6 +58,9 @@
}, },
"config": { "config": {
"preferred-install": "dist", "preferred-install": "dist",
"platform-check": false "platform-check": false,
"allow-plugins": {
"kylekatarnls/update-helper": true
}
} }
} }
...@@ -149,7 +149,7 @@ class ClassLoader ...@@ -149,7 +149,7 @@ class ClassLoader
/** /**
* @return string[] Array of classname => path * @return string[] Array of classname => path
* @psalm-var array<string, string> * @psalm-return array<string, string>
*/ */
public function getClassMap() public function getClassMap()
{ {
......
...@@ -326,7 +326,9 @@ class InstalledVersions ...@@ -326,7 +326,9 @@ class InstalledVersions
if (isset(self::$installedByVendor[$vendorDir])) { if (isset(self::$installedByVendor[$vendorDir])) {
$installed[] = self::$installedByVendor[$vendorDir]; $installed[] = self::$installedByVendor[$vendorDir];
} elseif (is_file($vendorDir.'/composer/installed.php')) { } elseif (is_file($vendorDir.'/composer/installed.php')) {
$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php'; /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require $vendorDir.'/composer/installed.php';
$installed[] = self::$installedByVendor[$vendorDir] = $required;
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
self::$installed = $installed[count($installed) - 1]; self::$installed = $installed[count($installed) - 1];
} }
...@@ -338,12 +340,17 @@ class InstalledVersions ...@@ -338,12 +340,17 @@ class InstalledVersions
// only require the installed.php file if this file is loaded from its dumped location, // only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') { if (substr(__DIR__, -8, 1) !== 'C') {
self::$installed = require __DIR__ . '/installed.php'; /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require __DIR__ . '/installed.php';
self::$installed = $required;
} else { } else {
self::$installed = array(); self::$installed = array();
} }
} }
$installed[] = self::$installed;
if (self::$installed !== array()) {
$installed[] = self::$installed;
}
return $installed; return $installed;
} }
......
...@@ -7,16 +7,16 @@ $baseDir = dirname($vendorDir); ...@@ -7,16 +7,16 @@ $baseDir = dirname($vendorDir);
return array( return array(
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'1d1b89d124cc9cb8219922c9d5569199' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest.php',
'667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php', '320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
'2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
'bd9634f2d41831496de0d3dfe4c94881' => $vendorDir . '/symfony/polyfill-php56/bootstrap.php', 'bd9634f2d41831496de0d3dfe4c94881' => $vendorDir . '/symfony/polyfill-php56/bootstrap.php',
'667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php',
'7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php', '7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php',
'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php', 'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php', 'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php',
'1d1b89d124cc9cb8219922c9d5569199' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest.php',
'5255c38a0faeba867671b61dfda6d864' => $vendorDir . '/paragonie/random_compat/lib/random.php', '5255c38a0faeba867671b61dfda6d864' => $vendorDir . '/paragonie/random_compat/lib/random.php',
'e7223560d890eab89cda23685e711e2c' => $vendorDir . '/psy/psysh/src/Psy/functions.php', 'e7223560d890eab89cda23685e711e2c' => $vendorDir . '/psy/psysh/src/Psy/functions.php',
'2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php', '37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
'f0906e6318348a765ffb6eb24e0d0938' => $vendorDir . '/laravel/framework/src/Illuminate/Foundation/helpers.php', 'f0906e6318348a765ffb6eb24e0d0938' => $vendorDir . '/laravel/framework/src/Illuminate/Foundation/helpers.php',
'58571171fd5812e6e447dce228f52f4d' => $vendorDir . '/laravel/framework/src/Illuminate/Support/helpers.php', '58571171fd5812e6e447dce228f52f4d' => $vendorDir . '/laravel/framework/src/Illuminate/Support/helpers.php',
......
...@@ -12,4 +12,6 @@ return array( ...@@ -12,4 +12,6 @@ return array(
'Mockery' => array($vendorDir . '/mockery/mockery/library'), 'Mockery' => array($vendorDir . '/mockery/mockery/library'),
'Maatwebsite\\Excel\\' => array($vendorDir . '/maatwebsite/excel/src'), 'Maatwebsite\\Excel\\' => array($vendorDir . '/maatwebsite/excel/src'),
'JakubOnderka\\PhpConsoleHighlighter' => array($vendorDir . '/jakub-onderka/php-console-highlighter/src'), 'JakubOnderka\\PhpConsoleHighlighter' => array($vendorDir . '/jakub-onderka/php-console-highlighter/src'),
'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src'),
'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib'),
); );
...@@ -44,8 +44,6 @@ return array( ...@@ -44,8 +44,6 @@ return array(
'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'), 'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
'Faker\\' => array($vendorDir . '/fzaninotto/faker/src/Faker'), 'Faker\\' => array($vendorDir . '/fzaninotto/faker/src/Faker'),
'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'), 'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'),
'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'),
'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib/Doctrine/Common/Inflector'),
'Cron\\' => array($vendorDir . '/mtdowling/cron-expression/src/Cron'), 'Cron\\' => array($vendorDir . '/mtdowling/cron-expression/src/Cron'),
'ClassPreloader\\' => array($vendorDir . '/classpreloader/classpreloader/src'), 'ClassPreloader\\' => array($vendorDir . '/classpreloader/classpreloader/src'),
'App\\' => array($baseDir . '/app'), 'App\\' => array($baseDir . '/app'),
......
...@@ -63,11 +63,16 @@ class ComposerAutoloaderInit2a46e5674e69fd121680370ab820bf2e ...@@ -63,11 +63,16 @@ class ComposerAutoloaderInit2a46e5674e69fd121680370ab820bf2e
} }
} }
/**
* @param string $fileIdentifier
* @param string $file
* @return void
*/
function composerRequire2a46e5674e69fd121680370ab820bf2e($fileIdentifier, $file) function composerRequire2a46e5674e69fd121680370ab820bf2e($fileIdentifier, $file)
{ {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
require $file;
} }
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
'reference' => '6a65bded842127cb11c4764e987e1d101a8b986c', 'reference' => '28a77aa4f4c9c4ee2d223a5fcd2492be745919f7',
'name' => 'laravel/laravel', 'name' => 'laravel/laravel',
'dev' => true, 'dev' => true,
), ),
...@@ -41,22 +41,22 @@ ...@@ -41,22 +41,22 @@
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'doctrine/inflector' => array( 'doctrine/inflector' => array(
'pretty_version' => '1.3.1', 'pretty_version' => 'v1.1.0',
'version' => '1.3.1.0', 'version' => '1.1.0.0',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../doctrine/inflector', 'install_path' => __DIR__ . '/../doctrine/inflector',
'aliases' => array(), 'aliases' => array(),
'reference' => 'ec3a55242203ffa6a4b27c58176da97ff0a7aec1', 'reference' => '90b2128806bfde671b6952ab8bea493942c1fdae',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'doctrine/instantiator' => array( 'doctrine/instantiator' => array(
'pretty_version' => '1.3.0', 'pretty_version' => '1.0.2',
'version' => '1.3.0.0', 'version' => '1.0.2.0',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../doctrine/instantiator', 'install_path' => __DIR__ . '/../doctrine/instantiator',
'aliases' => array(), 'aliases' => array(),
'reference' => 'ae466f726242e637cebdd526a7d991b9433bacf1', 'reference' => '26404e0c90565b614ee76b988b9bc8790d77f590',
'dev_requirement' => true, 'dev_requirement' => false,
), ),
'fzaninotto/faker' => array( 'fzaninotto/faker' => array(
'pretty_version' => 'v1.9.1', 'pretty_version' => 'v1.9.1',
...@@ -328,7 +328,7 @@ ...@@ -328,7 +328,7 @@
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
'reference' => '6a65bded842127cb11c4764e987e1d101a8b986c', 'reference' => '28a77aa4f4c9c4ee2d223a5fcd2492be745919f7',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'league/flysystem' => array( 'league/flysystem' => array(
...@@ -413,31 +413,31 @@ ...@@ -413,31 +413,31 @@
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'phpdocumentor/reflection-common' => array( 'phpdocumentor/reflection-common' => array(
'pretty_version' => '2.0.0', 'pretty_version' => '1.0.1',
'version' => '2.0.0.0', 'version' => '1.0.1.0',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../phpdocumentor/reflection-common', 'install_path' => __DIR__ . '/../phpdocumentor/reflection-common',
'aliases' => array(), 'aliases' => array(),
'reference' => '63a995caa1ca9e5590304cd845c15ad6d482a62a', 'reference' => '21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6',
'dev_requirement' => true, 'dev_requirement' => false,
), ),
'phpdocumentor/reflection-docblock' => array( 'phpdocumentor/reflection-docblock' => array(
'pretty_version' => '4.3.4', 'pretty_version' => '3.2.2',
'version' => '4.3.4.0', 'version' => '3.2.2.0',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../phpdocumentor/reflection-docblock', 'install_path' => __DIR__ . '/../phpdocumentor/reflection-docblock',
'aliases' => array(), 'aliases' => array(),
'reference' => 'da3fd972d6bafd628114f7e7e036f45944b62e9c', 'reference' => '4aada1f93c72c35e22fb1383b47fee43b8f1d157',
'dev_requirement' => true, 'dev_requirement' => false,
), ),
'phpdocumentor/type-resolver' => array( 'phpdocumentor/type-resolver' => array(
'pretty_version' => '1.0.1', 'pretty_version' => '0.3.0',
'version' => '1.0.1.0', 'version' => '0.3.0.0',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../phpdocumentor/type-resolver', 'install_path' => __DIR__ . '/../phpdocumentor/type-resolver',
'aliases' => array(), 'aliases' => array(),
'reference' => '2e32a6d48972b2c1976ed5d8967145b6cec4a4a9', 'reference' => 'fb3933512008d8162b3cdf9e18dba9309b7c3773',
'dev_requirement' => true, 'dev_requirement' => false,
), ),
'phpoffice/phpexcel' => array( 'phpoffice/phpexcel' => array(
'pretty_version' => '1.8.2', 'pretty_version' => '1.8.2',
...@@ -722,12 +722,12 @@ ...@@ -722,12 +722,12 @@
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'symfony/polyfill-ctype' => array( 'symfony/polyfill-ctype' => array(
'pretty_version' => 'v1.15.0', 'pretty_version' => 'v1.19.0',
'version' => '1.15.0.0', 'version' => '1.19.0.0',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-ctype', 'install_path' => __DIR__ . '/../symfony/polyfill-ctype',
'aliases' => array(), 'aliases' => array(),
'reference' => '4719fa9c18b0464d399f1a63bf624b42b6fa8d14', 'reference' => 'aed596913b70fae57be53d86faa2e9ef85a2297b',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'symfony/polyfill-mbstring' => array( 'symfony/polyfill-mbstring' => array(
...@@ -842,13 +842,13 @@ ...@@ -842,13 +842,13 @@
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'webmozart/assert' => array( 'webmozart/assert' => array(
'pretty_version' => '1.7.0', 'pretty_version' => '1.9.1',
'version' => '1.7.0.0', 'version' => '1.9.1.0',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../webmozart/assert', 'install_path' => __DIR__ . '/../webmozart/assert',
'aliases' => array(), 'aliases' => array(),
'reference' => 'aed98a490f9a8f78468232db345ab9cf606cf598', 'reference' => 'bafc69caeb4d49c39fd0779086c03a3738cbb389',
'dev_requirement' => true, 'dev_requirement' => false,
), ),
), ),
); );
vendor/
composer.lock
composer.phar
phpunit.xml
language: php
sudo: false
cache:
directory:
- $HOME/.composer/cache
php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
install:
- composer install -n
script:
- phpunit
...@@ -13,20 +13,17 @@ ...@@ -13,20 +13,17 @@
{"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"} {"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"}
], ],
"require": { "require": {
"php": "^7.1" "php": ">=5.3.2"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^6.2" "phpunit/phpunit": "4.*"
}, },
"autoload": { "autoload": {
"psr-4": { "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector" } "psr-0": { "Doctrine\\Common\\Inflector\\": "lib/" }
},
"autoload-dev": {
"psr-4": { "Doctrine\\Tests\\Common\\Inflector\\": "tests/Doctrine/Tests/Common/Inflector" }
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.3.x-dev" "dev-master": "1.1.x-dev"
} }
} }
} }
Introduction
============
The Doctrine Inflector has static methods for inflecting text.
The features include pluralization, singularization,
converting between camelCase and under_score and capitalizing
words.
All you need to use the Inflector is the ``Doctrine\Common\Inflector\Inflector``
class.
Installation
============
You can install the Inflector with composer:
.. code-block::
$ composer require doctrine/inflector
Here are the available methods that you can use:
Tableize
========
Converts ``ModelName`` to ``model_name``:
.. code-block:: php
echo Inflector::tableize('ModelName'); // model_name
Classify
========
Converts ``model_name`` to ``ModelName``:
.. code-block:: php
echo Inflector::classify('model_name'); // ModelName
Camelize
========
This method uses `Classify`_ and then converts the first character to lowercase:
.. code-block:: php
echo Inflector::camelize('model_name'); // modelName
ucwords
=======
Takes a string and capitalizes all of the words, like PHP's built-in
ucwords function. This extends that behavior, however, by allowing the
word delimiters to be configured, rather than only separating on
whitespace.
Here is an example:
.. code-block:: php
$string = 'top-o-the-morning to all_of_you!';
echo Inflector::ucwords($string); // Top-O-The-Morning To All_of_you!
echo Inflector::ucwords($string, '-_ '); // Top-O-The-Morning To All_Of_You!
Pluralize
=========
Returns a word in plural form.
.. code-block:: php
echo Inflector::pluralize('browser'); // browsers
Singularize
===========
.. code-block:: php
echo Inflector::singularize('browsers'); // browser
Rules
=====
Customize the rules for pluralization and singularization:
.. code-block:: php
Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
Inflector::rules('plural', [
'rules' => ['/^(inflect)ors$/i' => '\1ables'],
'uninflected' => ['dontinflectme'],
'irregular' => ['red' => 'redlings']
]);
The arguments for the ``rules`` method are:
- ``$type`` - The type of inflection, either ``plural`` or ``singular``
- ``$rules`` - An array of rules to be added.
- ``$reset`` - If true, will unset default inflections for all new rules that are being defined in $rules.
Reset
=====
Clears Inflectors inflected value caches, and resets the inflection
rules to the initial values.
.. code-block:: php
Inflector::reset();
Slugify
=======
You can easily use the Inflector to create a slug from a string of text
by using the `tableize`_ method and replacing underscores with hyphens:
.. code-block:: php
public static function slugify(string $text) : string
{
return str_replace('_', '-', Inflector::tableize($text));
}
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/Doctrine/Tests/TestInit.php"
>
<testsuites>
<testsuite name="Doctrine Inflector Test Suite">
<directory>./tests/Doctrine/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./lib/Doctrine/</directory>
</whitelist>
</filter>
<groups>
<exclude>
<group>performance</group>
</exclude>
</groups>
</phpunit>
<?php
namespace Doctrine\Tests;
/**
* Base testcase class for all Doctrine testcases.
*/
abstract class DoctrineTestCase extends \PHPUnit_Framework_TestCase
{
}
\ No newline at end of file
<?php
/*
* This file bootstraps the test environment.
*/
namespace Doctrine\Tests;
error_reporting(E_ALL | E_STRICT);
// register silently failing autoloader
spl_autoload_register(function($class)
{
if (0 === strpos($class, 'Doctrine\Tests\\')) {
$path = __DIR__.'/../../'.strtr($class, '\\', '/').'.php';
if (is_file($path) && is_readable($path)) {
require_once $path;
return true;
}
} else if (0 === strpos($class, 'Doctrine\Common\\')) {
$path = __DIR__.'/../../../lib/'.($class = strtr($class, '\\', '/')).'.php';
if (is_file($path) && is_readable($path)) {
require_once $path;
return true;
}
}
});
{
"active": true,
"name": "Instantiator",
"slug": "instantiator",
"docsSlug": "doctrine-instantiator",
"codePath": "/src",
"versions": [
{
"name": "1.1",
"branchName": "master",
"slug": "latest",
"aliases": [
"current",
"stable"
],
"maintained": true,
"current": true
},
{
"name": "1.0",
"branchName": "1.0.x",
"slug": "1.0"
}
]
}
patreon: phpdoctrine
tidelift: packagist/doctrine%2Finstantiator
custom: https://www.doctrine-project.org/sponsorship.html
phpunit.xml
composer.lock
build
vendor
coverage.clover
\ No newline at end of file
before_commands: before_commands:
- "composer install --no-dev --prefer-source" - "composer install --prefer-source"
checks:
php:
excluded_dependencies:
- phpstan/phpstan
tools: tools:
external_code_coverage: external_code_coverage:
timeout: 600
php_code_coverage:
enabled: true enabled: true
timeout: 300 test_command: ./vendor/bin/phpunit
filter:
excluded_paths: ["tests", "vendor"]
php_code_sniffer: php_code_sniffer:
enabled: true enabled: true
config: config:
standard: PSR2 standard: PSR2
filter: filter:
paths: ["src/*", "tests/*"] paths: ["src/*", "tests/*"]
excluded_paths: []
php_cpd: php_cpd:
enabled: true enabled: true
excluded_dirs: ["tests", "vendor"] excluded_dirs: ["build/*", "tests", "vendor"]
php_cs_fixer: php_cs_fixer:
enabled: true enabled: true
config: config:
...@@ -30,7 +24,7 @@ tools: ...@@ -30,7 +24,7 @@ tools:
paths: ["src/*", "tests/*"] paths: ["src/*", "tests/*"]
php_loc: php_loc:
enabled: true enabled: true
excluded_dirs: ["tests", "vendor"] excluded_dirs: ["build", "tests", "vendor"]
php_mess_detector: php_mess_detector:
enabled: true enabled: true
config: config:
...@@ -40,9 +34,13 @@ tools: ...@@ -40,9 +34,13 @@ tools:
paths: ["src/*"] paths: ["src/*"]
php_pdepend: php_pdepend:
enabled: true enabled: true
excluded_dirs: ["tests", "vendor"] excluded_dirs: ["build", "tests", "vendor"]
php_analyzer: php_analyzer:
enabled: true enabled: true
filter: filter:
paths: ["src/*", "tests/*"] paths: ["src/*", "tests/*"]
php_hhvm:
enabled: true
filter:
paths: ["src/*", "tests/*"]
sensiolabs_security_checker: true sensiolabs_security_checker: true
set -x
if [ "$TRAVIS_PHP_VERSION" = 'hhvm' ] || [ "$TRAVIS_PHP_VERSION" = 'hhvm-nightly' ] ; then
curl -sS https://getcomposer.org/installer > composer-installer.php
hhvm composer-installer.php
hhvm -v ResourceLimit.SocketDefaultTimeout=30 -v Http.SlowQueryThreshold=30000 composer.phar update --prefer-source
elif [ "$TRAVIS_PHP_VERSION" = '5.3.3' ] ; then
composer self-update
composer update --prefer-source --no-dev
composer dump-autoload
else
composer self-update
composer update --prefer-source
fi
language: php
php:
- 5.3.3
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
- hhvm-nightly
before_script:
- ./.travis.install.sh
script:
- sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.3.3' ]; then phpunit; fi"
- sh -c "if [ '$TRAVIS_PHP_VERSION' != '5.3.3' ]; then ./vendor/bin/phpunit; fi"
- sh -c "if [ '$TRAVIS_PHP_VERSION' != '5.3.3' ]; then ./vendor/bin/phpcs --standard=PSR2 ./src/ ./tests/; fi"
- sh -c "if [[ '$TRAVIS_PHP_VERSION' != '5.3.3' && '$TRAVIS_PHP_VERSION' != '5.4.29' && '$TRAVIS_PHP_VERSION' != '5.5.13' ]]; then php -n ./vendor/bin/athletic -p ./tests/DoctrineTest/InstantiatorPerformance/ -f GroupedFormatter; fi"
after_script:
- sh -c "if [ '$TRAVIS_PHP_VERSION' != '5.3.3' ]; then wget https://scrutinizer-ci.com/ocular.phar; php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi"
matrix:
allow_failures:
- php: 5.6 # Depends on https://github.com/php/php-src/pull/733
- php: hhvm-nightly
# Contributing # Contributing
* Follow the [Doctrine Coding Standard](https://github.com/doctrine/coding-standard) * Coding standard for the project is [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)
* The project will follow strict [object calisthenics](http://www.slideshare.net/guilhermeblanco/object-calisthenics-applied-to-php) * The project will follow strict [object calisthenics](http://www.slideshare.net/guilhermeblanco/object-calisthenics-applied-to-php)
* Any contribution must provide tests for additional introduced conditions * Any contribution must provide tests for additional introduced conditions
* Any un-confirmed issue needs a failing test case before being accepted * Any un-confirmed issue needs a failing test case before being accepted
......
...@@ -6,6 +6,7 @@ This library provides a way of avoiding usage of constructors when instantiating ...@@ -6,6 +6,7 @@ This library provides a way of avoiding usage of constructors when instantiating
[![Code Coverage](https://scrutinizer-ci.com/g/doctrine/instantiator/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/doctrine/instantiator/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/doctrine/instantiator/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/doctrine/instantiator/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/doctrine/instantiator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/doctrine/instantiator/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/doctrine/instantiator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/doctrine/instantiator/?branch=master)
[![Dependency Status](https://www.versioneye.com/package/php--doctrine--instantiator/badge.svg)](https://www.versioneye.com/package/php--doctrine--instantiator) [![Dependency Status](https://www.versioneye.com/package/php--doctrine--instantiator/badge.svg)](https://www.versioneye.com/package/php--doctrine--instantiator)
[![HHVM Status](http://hhvm.h4cc.de/badge/doctrine/instantiator.png)](http://hhvm.h4cc.de/package/doctrine/instantiator)
[![Latest Stable Version](https://poser.pugx.org/doctrine/instantiator/v/stable.png)](https://packagist.org/packages/doctrine/instantiator) [![Latest Stable Version](https://poser.pugx.org/doctrine/instantiator/v/stable.png)](https://packagist.org/packages/doctrine/instantiator)
[![Latest Unstable Version](https://poser.pugx.org/doctrine/instantiator/v/unstable.png)](https://packagist.org/packages/doctrine/instantiator) [![Latest Unstable Version](https://poser.pugx.org/doctrine/instantiator/v/unstable.png)](https://packagist.org/packages/doctrine/instantiator)
...@@ -15,18 +16,18 @@ This library provides a way of avoiding usage of constructors when instantiating ...@@ -15,18 +16,18 @@ This library provides a way of avoiding usage of constructors when instantiating
The suggested installation method is via [composer](https://getcomposer.org/): The suggested installation method is via [composer](https://getcomposer.org/):
```sh ```sh
php composer.phar require "doctrine/instantiator:~1.0.3" php composer.phar require "doctrine/instantiator:~1.0,>=1.0.2"
``` ```
## Usage ## Usage
The instantiator is able to create new instances of any class without using the constructor or any API of the class The instantiator is able to create new instances of any class without using the constructor of the class
itself: itself:
```php ```php
$instantiator = new \Doctrine\Instantiator\Instantiator(); $instantiator = new \Doctrine\Instantiator\Instantiator();
$instance = $instantiator->instantiate(\My\ClassName\Here::class); $instance = $instantiator->instantiate('My\\ClassName\\Here');
``` ```
## Contributing ## Contributing
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
"type": "library", "type": "library",
"license": "MIT", "license": "MIT",
"homepage": "https://www.doctrine-project.org/projects/instantiator.html", "homepage": "https://github.com/doctrine/instantiator",
"keywords": [ "keywords": [
"instantiate", "instantiate",
"constructor" "constructor"
...@@ -16,20 +16,18 @@ ...@@ -16,20 +16,18 @@
} }
], ],
"require": { "require": {
"php": "^7.1" "php": "~5.3"
}, },
"require-dev": { "require-dev": {
"ext-phar": "*", "ext-phar": "*",
"ext-pdo": "*", "ext-pdo": "*",
"doctrine/coding-standard": "^6.0", "phpunit/phpunit": "~4.0",
"phpbench/phpbench": "^0.13", "squizlabs/php_codesniffer": "2.0.*@ALPHA",
"phpstan/phpstan-phpunit": "^0.11", "athletic/athletic": "~0.1.8"
"phpstan/phpstan-shim": "^0.11",
"phpunit/phpunit": "^7.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-0": {
"Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" "Doctrine\\Instantiator\\": "src"
} }
}, },
"autoload-dev": { "autoload-dev": {
...@@ -41,7 +39,7 @@ ...@@ -41,7 +39,7 @@
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.2.x-dev" "dev-master": "1.0.x-dev"
} }
} }
} }
Introduction
============
This library provides a way of avoiding usage of constructors when instantiating PHP classes.
Installation
============
The suggested installation method is via `composer`_:
.. code-block:: console
$ composer require doctrine/instantiator
Usage
=====
The instantiator is able to create new instances of any class without
using the constructor or any API of the class itself:
.. code-block:: php
<?php
use Doctrine\Instantiator\Instantiator;
use App\Entities\User;
$instantiator = new Instantiator();
$user = $instantiator->instantiate(User::class);
Contributing
============
- Follow the `Doctrine Coding Standard`_
- The project will follow strict `object calisthenics`_
- Any contribution must provide tests for additional introduced
conditions
- Any un-confirmed issue needs a failing test case before being
accepted
- Pull requests must be sent from a new hotfix/feature branch, not from
``master``.
Testing
=======
The PHPUnit version to be used is the one installed as a dev- dependency
via composer:
.. code-block:: console
$ ./vendor/bin/phpunit
Accepted coverage for new contributions is 80%. Any contribution not
satisfying this requirement won’t be merged.
Credits
=======
This library was migrated from `ocramius/instantiator`_, which has been
donated to the doctrine organization, and which is now deprecated in
favour of this package.
.. _composer: https://getcomposer.org/
.. _CONTRIBUTING.md: CONTRIBUTING.md
.. _ocramius/instantiator: https://github.com/Ocramius/Instantiator
.. _Doctrine Coding Standard: https://github.com/doctrine/coding-standard
.. _object calisthenics: http://www.slideshare.net/guilhermeblanco/object-calisthenics-applied-to-php
{
"bootstrap": "vendor/autoload.php",
"path": "tests/DoctrineTest/InstantiatorPerformance"
}
<?xml version="1.0"?>
<ruleset>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>
<file>src</file>
<file>tests</file>
<rule ref="Doctrine">
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint"/>
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException"/>
</rule>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming">
<exclude-pattern>tests/DoctrineTest/InstantiatorTestAsset/AbstractClassAsset.php</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming">
<exclude-pattern>src/Doctrine/Instantiator/Exception/UnexpectedValueException.php</exclude-pattern>
<exclude-pattern>src/Doctrine/Instantiator/Exception/InvalidArgumentException.php</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming">
<exclude-pattern>src/Doctrine/Instantiator/Exception/ExceptionInterface.php</exclude-pattern>
<exclude-pattern>src/Doctrine/Instantiator/InstantiatorInterface.php</exclude-pattern>
</rule>
</ruleset>
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<ruleset <ruleset
name="ProxyManager rules" name="Instantiator rules"
xmlns="http://pmd.sf.net/ruleset/1.0.0" xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
> >
<rule ref="rulesets/cleancode.xml">
<!-- static access is used for caching purposes -->
<exclude name="StaticAccess"/>
</rule>
<rule ref="rulesets/codesize.xml"/> <rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/controversial.xml"/>
<rule ref="rulesets/design.xml"/>
<rule ref="rulesets/naming.xml"/>
<rule ref="rulesets/unusedcode.xml"/> <rule ref="rulesets/unusedcode.xml"/>
<rule ref="rulesets/design.xml"> <rule
<!-- eval is needed to generate runtime classes --> name="NPathComplexity"
<exclude name="EvalExpression"/> message="The {0} {1}() has an NPath complexity of {2}. The configured NPath complexity threshold is {3}."
</rule> class="PHP_PMD_Rule_Design_NpathComplexity"
<rule ref="rulesets/naming.xml"> >
<exclude name="LongVariable"/>
</rule>
<rule ref="rulesets/naming.xml/LongVariable">
<properties> <properties>
<property name="minimum">40</property> <property name="minimum" description="The npath reporting threshold" value="10"/>
</properties> </properties>
</rule> </rule>
</ruleset> </ruleset>
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
parameters:
level: max
paths:
- src
- tests
ignoreErrors:
-
message: '#::__construct\(\) does not call parent constructor from#'
path: '*/tests/DoctrineTest/InstantiatorTestAsset/*.php'
# dynamic properties confuse static analysis
-
message: '#Access to an undefined property object::\$foo\.#'
path: '*/tests/DoctrineTest/InstantiatorTest/InstantiatorTest.php'
<?xml version="1.0"?>
<phpunit
bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
stopOnFailure="false"
processIsolation="false"
backupGlobals="false"
syntaxCheck="true"
>
<testsuite name="Doctrine\Instantiator tests">
<directory>./tests/DoctrineTest/InstantiatorTest</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="./coverage.clover"/>
</logging>
</phpunit>
<?php <?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Instantiator\Exception; namespace Doctrine\Instantiator\Exception;
use Throwable;
/** /**
* Base exception marker interface for the instantiator component * Base exception marker interface for the instantiator component
*
* @author Marco Pivetta <ocramius@gmail.com>
*/ */
interface ExceptionInterface extends Throwable interface ExceptionInterface
{ {
} }
<?php <?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Instantiator\Exception; namespace Doctrine\Instantiator\Exception;
use InvalidArgumentException as BaseInvalidArgumentException; use InvalidArgumentException as BaseInvalidArgumentException;
use ReflectionClass; use ReflectionClass;
use const PHP_VERSION_ID;
use function interface_exists;
use function sprintf;
use function trait_exists;
/** /**
* Exception for invalid arguments provided to the instantiator * Exception for invalid arguments provided to the instantiator
*
* @author Marco Pivetta <ocramius@gmail.com>
*/ */
class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionInterface class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionInterface
{ {
public static function fromNonExistingClass(string $className) : self /**
* @param string $className
*
* @return self
*/
public static function fromNonExistingClass($className)
{ {
if (interface_exists($className)) { if (interface_exists($className)) {
return new self(sprintf('The provided type "%s" is an interface, and can not be instantiated', $className)); return new self(sprintf('The provided type "%s" is an interface, and can not be instantiated', $className));
...@@ -27,7 +47,12 @@ class InvalidArgumentException extends BaseInvalidArgumentException implements E ...@@ -27,7 +47,12 @@ class InvalidArgumentException extends BaseInvalidArgumentException implements E
return new self(sprintf('The provided class "%s" does not exist', $className)); return new self(sprintf('The provided class "%s" does not exist', $className));
} }
public static function fromAbstractClass(ReflectionClass $reflectionClass) : self /**
* @param ReflectionClass $reflectionClass
*
* @return self
*/
public static function fromAbstractClass(ReflectionClass $reflectionClass)
{ {
return new self(sprintf( return new self(sprintf(
'The provided class "%s" is abstract, and can not be instantiated', 'The provided class "%s" is abstract, and can not be instantiated',
......
<?php <?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Instantiator\Exception; namespace Doctrine\Instantiator\Exception;
use Exception; use Exception;
use ReflectionClass; use ReflectionClass;
use UnexpectedValueException as BaseUnexpectedValueException; use UnexpectedValueException as BaseUnexpectedValueException;
use function sprintf;
/** /**
* Exception for given parameters causing invalid/unexpected state on instantiation * Exception for given parameters causing invalid/unexpected state on instantiation
*
* @author Marco Pivetta <ocramius@gmail.com>
*/ */
class UnexpectedValueException extends BaseUnexpectedValueException implements ExceptionInterface class UnexpectedValueException extends BaseUnexpectedValueException implements ExceptionInterface
{ {
public static function fromSerializationTriggeredException( /**
ReflectionClass $reflectionClass, * @param ReflectionClass $reflectionClass
Exception $exception * @param Exception $exception
) : self { *
* @return self
*/
public static function fromSerializationTriggeredException(ReflectionClass $reflectionClass, Exception $exception)
{
return new self( return new self(
sprintf( sprintf(
'An exception was raised while trying to instantiate an instance of "%s" via un-serialization', 'An exception was raised while trying to instantiate an instance of "%s" via un-serialization',
...@@ -26,13 +48,22 @@ class UnexpectedValueException extends BaseUnexpectedValueException implements E ...@@ -26,13 +48,22 @@ class UnexpectedValueException extends BaseUnexpectedValueException implements E
); );
} }
/**
* @param ReflectionClass $reflectionClass
* @param string $errorString
* @param int $errorCode
* @param string $errorFile
* @param int $errorLine
*
* @return UnexpectedValueException
*/
public static function fromUncleanUnSerialization( public static function fromUncleanUnSerialization(
ReflectionClass $reflectionClass, ReflectionClass $reflectionClass,
string $errorString, $errorString,
int $errorCode, $errorCode,
string $errorFile, $errorFile,
int $errorLine $errorLine
) : self { ) {
return new self( return new self(
sprintf( sprintf(
'Could not produce an instance of "%s" via un-serialization, since an error was triggered ' 'Could not produce an instance of "%s" via un-serialization, since an error was triggered '
......
<?php <?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Instantiator; namespace Doctrine\Instantiator;
use Doctrine\Instantiator\Exception\ExceptionInterface;
/** /**
* Instantiator provides utility methods to build objects without invoking their constructors * Instantiator provides utility methods to build objects without invoking their constructors
*
* @author Marco Pivetta <ocramius@gmail.com>
*/ */
interface InstantiatorInterface interface InstantiatorInterface
{ {
...@@ -14,7 +31,7 @@ interface InstantiatorInterface ...@@ -14,7 +31,7 @@ interface InstantiatorInterface
* *
* @return object * @return object
* *
* @throws ExceptionInterface * @throws \Doctrine\Instantiator\Exception\ExceptionInterface
*/ */
public function instantiate($className); public function instantiate($className);
} }
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorPerformance;
use Athletic\AthleticEvent;
use Doctrine\Instantiator\Instantiator;
/**
* Performance tests for {@see \Doctrine\Instantiator\Instantiator}
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class InstantiatorPerformanceEvent extends AthleticEvent
{
/**
* @var \Doctrine\Instantiator\Instantiator
*/
private $instantiator;
/**
* {@inheritDoc}
*/
protected function setUp()
{
$this->instantiator = new Instantiator();
$this->instantiator->instantiate(__CLASS__);
$this->instantiator->instantiate('ArrayObject');
$this->instantiator->instantiate('DoctrineTest\\InstantiatorTestAsset\\SimpleSerializableAsset');
$this->instantiator->instantiate('DoctrineTest\\InstantiatorTestAsset\\SerializableArrayObjectAsset');
$this->instantiator->instantiate('DoctrineTest\\InstantiatorTestAsset\\UnCloneableAsset');
}
/**
* @iterations 20000
* @baseline
* @group instantiation
*/
public function testInstantiateSelf()
{
$this->instantiator->instantiate(__CLASS__);
}
/**
* @iterations 20000
* @group instantiation
*/
public function testInstantiateInternalClass()
{
$this->instantiator->instantiate('ArrayObject');
}
/**
* @iterations 20000
* @group instantiation
*/
public function testInstantiateSimpleSerializableAssetClass()
{
$this->instantiator->instantiate('DoctrineTest\\InstantiatorTestAsset\\SimpleSerializableAsset');
}
/**
* @iterations 20000
* @group instantiation
*/
public function testInstantiateSerializableArrayObjectAsset()
{
$this->instantiator->instantiate('DoctrineTest\\InstantiatorTestAsset\\SerializableArrayObjectAsset');
}
/**
* @iterations 20000
* @group instantiation
*/
public function testInstantiateUnCloneableAsset()
{
$this->instantiator->instantiate('DoctrineTest\\InstantiatorTestAsset\\UnCloneableAsset');
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTest\Exception;
use Doctrine\Instantiator\Exception\InvalidArgumentException;
use PHPUnit_Framework_TestCase;
use ReflectionClass;
/**
* Tests for {@see \Doctrine\Instantiator\Exception\InvalidArgumentException}
*
* @author Marco Pivetta <ocramius@gmail.com>
*
* @covers \Doctrine\Instantiator\Exception\InvalidArgumentException
*/
class InvalidArgumentExceptionTest extends PHPUnit_Framework_TestCase
{
public function testFromNonExistingTypeWithNonExistingClass()
{
$className = __CLASS__ . uniqid();
$exception = InvalidArgumentException::fromNonExistingClass($className);
$this->assertInstanceOf('Doctrine\\Instantiator\\Exception\\InvalidArgumentException', $exception);
$this->assertSame('The provided class "' . $className . '" does not exist', $exception->getMessage());
}
public function testFromNonExistingTypeWithTrait()
{
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Need at least PHP 5.4.0, as this test requires traits support to run');
}
$exception = InvalidArgumentException::fromNonExistingClass(
'DoctrineTest\\InstantiatorTestAsset\\SimpleTraitAsset'
);
$this->assertSame(
'The provided type "DoctrineTest\\InstantiatorTestAsset\\SimpleTraitAsset" is a trait, '
. 'and can not be instantiated',
$exception->getMessage()
);
}
public function testFromNonExistingTypeWithInterface()
{
$exception = InvalidArgumentException::fromNonExistingClass('Doctrine\\Instantiator\\InstantiatorInterface');
$this->assertSame(
'The provided type "Doctrine\\Instantiator\\InstantiatorInterface" is an interface, '
. 'and can not be instantiated',
$exception->getMessage()
);
}
public function testFromAbstractClass()
{
$reflection = new ReflectionClass('DoctrineTest\\InstantiatorTestAsset\\AbstractClassAsset');
$exception = InvalidArgumentException::fromAbstractClass($reflection);
$this->assertSame(
'The provided class "DoctrineTest\\InstantiatorTestAsset\\AbstractClassAsset" is abstract, '
. 'and can not be instantiated',
$exception->getMessage()
);
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTest\Exception;
use Doctrine\Instantiator\Exception\UnexpectedValueException;
use Exception;
use PHPUnit_Framework_TestCase;
use ReflectionClass;
/**
* Tests for {@see \Doctrine\Instantiator\Exception\UnexpectedValueException}
*
* @author Marco Pivetta <ocramius@gmail.com>
*
* @covers \Doctrine\Instantiator\Exception\UnexpectedValueException
*/
class UnexpectedValueExceptionTest extends PHPUnit_Framework_TestCase
{
public function testFromSerializationTriggeredException()
{
$reflectionClass = new ReflectionClass($this);
$previous = new Exception();
$exception = UnexpectedValueException::fromSerializationTriggeredException($reflectionClass, $previous);
$this->assertInstanceOf('Doctrine\\Instantiator\\Exception\\UnexpectedValueException', $exception);
$this->assertSame($previous, $exception->getPrevious());
$this->assertSame(
'An exception was raised while trying to instantiate an instance of "'
. __CLASS__ . '" via un-serialization',
$exception->getMessage()
);
}
public function testFromUncleanUnSerialization()
{
$reflection = new ReflectionClass('DoctrineTest\\InstantiatorTestAsset\\AbstractClassAsset');
$exception = UnexpectedValueException::fromUncleanUnSerialization($reflection, 'foo', 123, 'bar', 456);
$this->assertInstanceOf('Doctrine\\Instantiator\\Exception\\UnexpectedValueException', $exception);
$this->assertSame(
'Could not produce an instance of "DoctrineTest\\InstantiatorTestAsset\\AbstractClassAsset" '
. 'via un-serialization, since an error was triggered in file "bar" at line "456"',
$exception->getMessage()
);
$previous = $exception->getPrevious();
$this->assertInstanceOf('Exception', $previous);
$this->assertSame('foo', $previous->getMessage());
$this->assertSame(123, $previous->getCode());
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTest;
use Doctrine\Instantiator\Exception\UnexpectedValueException;
use Doctrine\Instantiator\Instantiator;
use PHPUnit_Framework_TestCase;
use ReflectionClass;
/**
* Tests for {@see \Doctrine\Instantiator\Instantiator}
*
* @author Marco Pivetta <ocramius@gmail.com>
*
* @covers \Doctrine\Instantiator\Instantiator
*/
class InstantiatorTest extends PHPUnit_Framework_TestCase
{
/**
* @var Instantiator
*/
private $instantiator;
/**
* {@inheritDoc}
*/
protected function setUp()
{
$this->instantiator = new Instantiator();
}
/**
* @param string $className
*
* @dataProvider getInstantiableClasses
*/
public function testCanInstantiate($className)
{
$this->assertInstanceOf($className, $this->instantiator->instantiate($className));
}
/**
* @param string $className
*
* @dataProvider getInstantiableClasses
*/
public function testInstantiatesSeparateInstances($className)
{
$instance1 = $this->instantiator->instantiate($className);
$instance2 = $this->instantiator->instantiate($className);
$this->assertEquals($instance1, $instance2);
$this->assertNotSame($instance1, $instance2);
}
public function testExceptionOnUnSerializationException()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped(
'As of facebook/hhvm#3432, HHVM has no PDORow, and therefore '
. ' no internal final classes that cannot be instantiated'
);
}
$className = 'DoctrineTest\\InstantiatorTestAsset\\UnserializeExceptionArrayObjectAsset';
if (\PHP_VERSION_ID >= 50600) {
$className = 'PDORow';
}
if (\PHP_VERSION_ID === 50429 || \PHP_VERSION_ID === 50513) {
$className = 'DoctrineTest\\InstantiatorTestAsset\\SerializableArrayObjectAsset';
}
$this->setExpectedException('Doctrine\\Instantiator\\Exception\\UnexpectedValueException');
$this->instantiator->instantiate($className);
}
public function testNoticeOnUnSerializationException()
{
if (\PHP_VERSION_ID >= 50600) {
$this->markTestSkipped(
'PHP 5.6 supports `ReflectionClass#newInstanceWithoutConstructor()` for some internal classes'
);
}
try {
$this->instantiator->instantiate('DoctrineTest\\InstantiatorTestAsset\\WakeUpNoticesAsset');
$this->fail('No exception was raised');
} catch (UnexpectedValueException $exception) {
$wakeUpNoticesReflection = new ReflectionClass('DoctrineTest\\InstantiatorTestAsset\\WakeUpNoticesAsset');
$previous = $exception->getPrevious();
$this->assertInstanceOf('Exception', $previous);
// in PHP 5.4.29 and PHP 5.5.13, this case is not a notice, but an exception being thrown
if (! (\PHP_VERSION_ID === 50429 || \PHP_VERSION_ID === 50513)) {
$this->assertSame(
'Could not produce an instance of "DoctrineTest\\InstantiatorTestAsset\WakeUpNoticesAsset" '
. 'via un-serialization, since an error was triggered in file "'
. $wakeUpNoticesReflection->getFileName() . '" at line "36"',
$exception->getMessage()
);
$this->assertSame('Something went bananas while un-serializing this instance', $previous->getMessage());
$this->assertSame(\E_USER_NOTICE, $previous->getCode());
}
}
}
/**
* @param string $invalidClassName
*
* @dataProvider getInvalidClassNames
*/
public function testInstantiationFromNonExistingClass($invalidClassName)
{
$this->setExpectedException('Doctrine\\Instantiator\\Exception\\InvalidArgumentException');
$this->instantiator->instantiate($invalidClassName);
}
public function testInstancesAreNotCloned()
{
$className = 'TemporaryClass' . uniqid();
eval('namespace ' . __NAMESPACE__ . '; class ' . $className . '{}');
$instance = $this->instantiator->instantiate(__NAMESPACE__ . '\\' . $className);
$instance->foo = 'bar';
$instance2 = $this->instantiator->instantiate(__NAMESPACE__ . '\\' . $className);
$this->assertObjectNotHasAttribute('foo', $instance2);
}
/**
* Provides a list of instantiable classes (existing)
*
* @return string[][]
*/
public function getInstantiableClasses()
{
$classes = array(
array('stdClass'),
array(__CLASS__),
array('Doctrine\\Instantiator\\Instantiator'),
array('PharException'),
array('DoctrineTest\\InstantiatorTestAsset\\SimpleSerializableAsset'),
array('DoctrineTest\\InstantiatorTestAsset\\PharExceptionAsset'),
array('DoctrineTest\\InstantiatorTestAsset\\UnCloneableAsset'),
);
if (\PHP_VERSION_ID === 50429 || \PHP_VERSION_ID === 50513) {
return $classes;
}
$classes = array_merge(
$classes,
array(
array('PharException'),
array('ArrayObject'),
array('DoctrineTest\\InstantiatorTestAsset\\ArrayObjectAsset'),
array('DoctrineTest\\InstantiatorTestAsset\\SerializableArrayObjectAsset'),
)
);
if (\PHP_VERSION_ID >= 50600) {
$classes[] = array('DoctrineTest\\InstantiatorTestAsset\\WakeUpNoticesAsset');
$classes[] = array('DoctrineTest\\InstantiatorTestAsset\\UnserializeExceptionArrayObjectAsset');
}
return $classes;
}
/**
* Provides a list of instantiable classes (existing)
*
* @return string[][]
*/
public function getInvalidClassNames()
{
$classNames = array(
array(__CLASS__ . uniqid()),
array('Doctrine\\Instantiator\\InstantiatorInterface'),
array('DoctrineTest\\InstantiatorTestAsset\\AbstractClassAsset'),
);
if (\PHP_VERSION_ID >= 50400) {
$classNames[] = array('DoctrineTest\\InstantiatorTestAsset\\SimpleTraitAsset');
}
return $classNames;
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTestAsset;
/**
* A simple asset for an abstract class
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
abstract class AbstractClassAsset
{
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTestAsset;
use ArrayObject;
use BadMethodCallException;
/**
* Test asset that extends an internal PHP class
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class ArrayObjectAsset extends ArrayObject
{
/**
* Constructor - should not be called
*
* @throws BadMethodCallException
*/
public function __construct()
{
throw new BadMethodCallException('Not supposed to be called!');
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTestAsset;
use BadMethodCallException;
use Phar;
/**
* Test asset that extends an internal PHP class
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class PharAsset extends Phar
{
/**
* Constructor - should not be called
*
* @throws BadMethodCallException
*/
public function __construct()
{
throw new BadMethodCallException('Not supposed to be called!');
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTestAsset;
use BadMethodCallException;
use PharException;
/**
* Test asset that extends an internal PHP class
* This class should be serializable without problems
* and without getting the "Erroneous data format for unserializing"
* error
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class PharExceptionAsset extends PharException
{
/**
* Constructor - should not be called
*
* @throws BadMethodCallException
*/
public function __construct()
{
throw new BadMethodCallException('Not supposed to be called!');
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTestAsset;
use ArrayObject;
use BadMethodCallException;
use Serializable;
/**
* Serializable test asset that also extends an internal class
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class SerializableArrayObjectAsset extends ArrayObject implements Serializable
{
/**
* Constructor - should not be called
*
* @throws BadMethodCallException
*/
public function __construct()
{
throw new BadMethodCallException('Not supposed to be called!');
}
/**
* {@inheritDoc}
*/
public function serialize()
{
return '';
}
/**
* {@inheritDoc}
*
* Should not be called
*
* @throws BadMethodCallException
*/
public function unserialize($serialized)
{
throw new BadMethodCallException('Not supposed to be called!');
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTestAsset;
use BadMethodCallException;
use Serializable;
/**
* Base serializable test asset
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class SimpleSerializableAsset implements Serializable
{
/**
* Constructor - should not be called
*
* @throws BadMethodCallException
*/
public function __construct()
{
throw new BadMethodCallException('Not supposed to be called!');
}
/**
* {@inheritDoc}
*/
public function serialize()
{
return '';
}
/**
* {@inheritDoc}
*
* Should not be called
*
* @throws BadMethodCallException
*/
public function unserialize($serialized)
{
throw new BadMethodCallException('Not supposed to be called!');
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTestAsset;
/**
* A simple trait with no attached logic
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
trait SimpleTraitAsset
{
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTestAsset;
use BadMethodCallException;
/**
* Base un-cloneable asset
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class UnCloneableAsset
{
/**
* Constructor - should not be called
*
* @throws BadMethodCallException
*/
public function __construct()
{
throw new BadMethodCallException('Not supposed to be called!');
}
/**
* Magic `__clone` - should not be invoked
*
* @throws BadMethodCallException
*/
public function __clone()
{
throw new BadMethodCallException('Not supposed to be called!');
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTestAsset;
use ArrayObject;
use BadMethodCallException;
/**
* A simple asset for an abstract class
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class UnserializeExceptionArrayObjectAsset extends ArrayObject
{
/**
* {@inheritDoc}
*/
public function __wakeup()
{
throw new BadMethodCallException();
}
}
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace DoctrineTest\InstantiatorTestAsset;
use ArrayObject;
/**
* A simple asset for an abstract class
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class WakeUpNoticesAsset extends ArrayObject
{
/**
* Wakeup method called after un-serialization
*/
public function __wakeup()
{
trigger_error('Something went bananas while un-serializing this instance');
}
}
language: php language: php
php: [ 7.1, 7.2, nightly ] php:
sudo: false - 5.5
- 5.6
env: - 7.0
- 7.1
- hhvm
- nightly
matrix: matrix:
fast_finish: true
allow_failures: allow_failures:
- php: nightly - php:
- hhvm
- nightly
install: cache:
- travis_retry composer install --no-interaction --prefer-dist --optimize-autoloader directories:
- $HOME/.composer/cache
script: script:
- ./vendor/bin/phpunit --no-coverage - vendor/bin/phpunit --coverage-clover=coverage.clover -v
- composer update --no-interaction --prefer-source
jobs: - vendor/bin/phpunit -v
include:
- stage: analysis
php: 7.1
script:
- ./vendor/bin/phpunit
after_script:
- travis_retry wget --no-verbose https://phar.io/releases/phive.phar
- travis_retry php phive.phar --no-progress install --trust-gpg-keys E82B2FB314E9906E php-coveralls/php-coveralls && ./tools/php-coveralls --verbose
- travis_retry wget --no-verbose https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
- stage: analysis before_script:
php: 7.1 - composer install --no-interaction
before_script:
- travis_retry wget --no-verbose https://phar.io/releases/phive.phar
- travis_retry php phive.phar --no-progress install --trust-gpg-keys 8E730BA25823D8B5 phpstan
script:
- ./tools/phpstan analyse src --level max --configuration phpstan.neon
- stage: analysis after_script:
php: 7.1 - if [ $TRAVIS_PHP_VERSION = '5.6' ]; then wget https://scrutinizer-ci.com/ocular.phar; php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
script:
- composer create-project symplify/easy-coding-standard temp/ecs ^3 && temp/ecs/bin/ecs check src tests
cache:
directories:
- $HOME/.composer
- $HOME/.phive
notifications: notifications:
irc: "irc.freenode.org#phpdocumentor" irc: "irc.freenode.org#phpdocumentor"
slack:
secure: "fjumM0h+4w3EYM4dpgqvpiCug7m4sSIC5+HATgwga/Nrc6IjlbWvGOv3JPgD3kQUhi18VmZfUYPmCv916SIbMnv8JWcrSaJXnPCgmxidvYkuzQDIw1HDJbVppGnkmwQA/qjIrM3sIEMfnu/arLRJQLI363aStZzGPxwIa4PDKcg="
email: email:
- me@mikevanriel.com - me@mikevanriel.com
- ashnazg@php.net - ashnazg@php.net
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) # ReflectionCommon
[![Travis Status](https://img.shields.io/travis/phpDocumentor/ReflectionCommon.svg?label=Linux)](https://travis-ci.org/phpDocumentor/ReflectionCommon) [![Build Status](https://travis-ci.org/phpDocumentor/ReflectionCommon.svg?branch=master)](https://travis-ci.org/phpDocumentor/ReflectionCommon)
[![Appveyor Status](https://img.shields.io/appveyor/ci/phpDocumentor/ReflectionCommon.svg?label=Windows)](https://ci.appveyor.com/project/phpDocumentor/ReflectionCommon/branch/master)
[![Coveralls Coverage](https://img.shields.io/coveralls/github/phpDocumentor/ReflectionCommon.svg)](https://coveralls.io/github/phpDocumentor/ReflectionCommon?branch=master)
[![Scrutinizer Code Coverage](https://img.shields.io/scrutinizer/coverage/g/phpDocumentor/ReflectionCommon.svg)](https://scrutinizer-ci.com/g/phpDocumentor/ReflectionCommon/?branch=master)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/phpDocumentor/ReflectionCommon.svg)](https://scrutinizer-ci.com/g/phpDocumentor/ReflectionCommon/?branch=master)
[![Stable Version](https://img.shields.io/packagist/v/phpDocumentor/Reflection-Common.svg)](https://packagist.org/packages/phpDocumentor/Reflection-Common)
[![Unstable Version](https://img.shields.io/packagist/vpre/phpDocumentor/Reflection-Common.svg)](https://packagist.org/packages/phpDocumentor/Reflection-Common)
ReflectionCommon
================
build: false
clone_folder: c:\reflectioncommon
max_jobs: 3
platform: x86
pull_requests:
do_not_increment_build_number: true
version: '{build}.{branch}'
skip_tags: true
branches:
only:
- master
environment:
matrix:
- php_ver_target: 7.1
- php_ver_target: 7.2
matrix:
fast_finish: false
cache:
- c:\php -> appveyor.yml
- '%LOCALAPPDATA%\Composer\files'
init:
- SET PATH=C:\Program Files\OpenSSL;c:\tools\php;%PATH%
- SET COMPOSER_NO_INTERACTION=1
- SET PHP=1
- SET ANSICON=121x90 (121x90)
install:
- IF EXIST c:\tools\php (SET PHP=0)
- ps: appveyor-retry cinst --params '""/InstallDir:C:\tools\php""' --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php_ver_target | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','')
- cd c:\tools\php
- IF %PHP%==1 copy /Y php.ini-development php.ini
- IF %PHP%==1 echo max_execution_time=1200 >> php.ini
- IF %PHP%==1 echo date.timezone="UTC" >> php.ini
- IF %PHP%==1 echo extension_dir=ext >> php.ini
- IF %PHP%==1 echo extension=php_curl.dll >> php.ini
- IF %PHP%==1 echo extension=php_openssl.dll >> php.ini
- IF %PHP%==1 echo extension=php_mbstring.dll >> php.ini
- IF %PHP%==1 echo extension=php_fileinfo.dll >> php.ini
- IF %PHP%==1 echo zend.assertions=1 >> php.ini
- IF %PHP%==1 echo assert.exception=On >> php.ini
- IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
- appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar
- cd c:\reflectioncommon
- composer install --no-interaction --prefer-dist --no-progress
test_script:
- cd c:\reflectioncommon
- vendor\bin\phpunit --no-coverage
...@@ -11,19 +11,19 @@ ...@@ -11,19 +11,19 @@
} }
], ],
"require": { "require": {
"php": ">=7.1" "php": ">=5.5"
}, },
"autoload" : { "autoload" : {
"psr-4" : { "psr-4" : {
"phpDocumentor\\Reflection\\": "src/" "phpDocumentor\\Reflection\\": ["src"]
} }
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~6" "phpunit/phpunit": "^4.6"
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "2.x-dev" "dev-master": "1.0.x-dev"
} }
} }
} }
includes:
- temp/ecs/config/clean-code.neon
- temp/ecs/config/psr2.neon
- temp/ecs/config/common.neon
parameters:
exclude_checkers:
# from temp/ecs/config/common.neon
- PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer
- PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer
- PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer
# from temp/ecs/config/spaces.neon
- PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer
skip:
PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff:
- */tests/**
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpunit" version="^6.5.5" installed="6.5.5" location="./tools/phpunit"/>
<phar name="phpstan" version="^0.9.1" installed="0.9.1" location="./tools/phpstan"/>
</phive>
<?php <?php
declare(strict_types=1);
/** /**
* phpDocumentor * phpDocumentor
* *
* For the full copyright and license information, please view the LICENSE * PHP Version 5.5
* file that was distributed with this source code.
* *
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) * @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT * @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org * @link http://phpdoc.org
*/ */
...@@ -21,11 +18,15 @@ interface Element ...@@ -21,11 +18,15 @@ interface Element
{ {
/** /**
* Returns the Fqsen of the element. * Returns the Fqsen of the element.
*
* @return Fqsen
*/ */
public function getFqsen(): Fqsen; public function getFqsen();
/** /**
* Returns the name of the element. * Returns the name of the element.
*
* @return string
*/ */
public function getName(): string; public function getName();
} }
\ No newline at end of file
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
* *
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org> * @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
* @license http://www.opensource.org/licenses/mit-license.php MIT * @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org * @link http://phpdoc.org
*/ */
...@@ -21,16 +19,22 @@ interface File ...@@ -21,16 +19,22 @@ interface File
{ {
/** /**
* Returns the content of the file as a string. * Returns the content of the file as a string.
*
* @return string
*/ */
public function getContents(): string; public function getContents();
/** /**
* Returns md5 hash of the file. * Returns md5 hash of the file.
*
* @return string
*/ */
public function md5(): string; public function md5();
/** /**
* Returns an relative path to the file. * Returns an relative path to the file.
*
* @return string
*/ */
public function path(): string; public function path();
} }
<?php <?php
declare(strict_types=1);
/** /**
* phpDocumentor * phpDocumentor
* *
* For the full copyright and license information, please view the LICENSE * PHP Version 5.5
* file that was distributed with this source code.
* *
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) * @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT * @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org * @link http://phpdoc.org
*/ */
namespace phpDocumentor\Reflection; namespace phpDocumentor\Reflection;
use InvalidArgumentException;
/** /**
* Value Object for Fqsen. * Value Object for Fqsen.
* *
...@@ -36,19 +31,21 @@ final class Fqsen ...@@ -36,19 +31,21 @@ final class Fqsen
/** /**
* Initializes the object. * Initializes the object.
* *
* @throws InvalidArgumentException when $fqsen is not matching the format. * @param string $fqsen
*
* @throws \InvalidArgumentException when $fqsen is not matching the format.
*/ */
public function __construct(string $fqsen) public function __construct($fqsen)
{ {
$matches = []; $matches = array();
$result = preg_match( $result = preg_match(
'/^\\\\([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\\\]*)?(?:[:]{2}\\$?([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*))?(?:\\(\\))?$/', '/^\\\\([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\\\]*)?(?:[:]{2}\\$?([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*))?(?:\\(\\))?$/',
$fqsen, $fqsen,
$matches $matches
); );
if ($result === 0) { if ($result === 0) {
throw new InvalidArgumentException( throw new \InvalidArgumentException(
sprintf('"%s" is not a valid Fqsen.', $fqsen) sprintf('"%s" is not a valid Fqsen.', $fqsen)
); );
} }
...@@ -65,16 +62,20 @@ final class Fqsen ...@@ -65,16 +62,20 @@ final class Fqsen
/** /**
* converts this class to string. * converts this class to string.
*
* @return string
*/ */
public function __toString(): string public function __toString()
{ {
return $this->fqsen; return $this->fqsen;
} }
/** /**
* Returns the name of the element without path. * Returns the name of the element without path.
*
* @return string
*/ */
public function getName(): string public function getName()
{ {
return $this->name; return $this->name;
} }
......
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
* *
* @copyright 2010-2018 Mike van Riel<mike@phpdoc.org> * @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
* @license http://www.opensource.org/licenses/mit-license.php MIT * @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org * @link http://phpdoc.org
*/ */
...@@ -19,7 +17,7 @@ namespace phpDocumentor\Reflection; ...@@ -19,7 +17,7 @@ namespace phpDocumentor\Reflection;
*/ */
final class Location final class Location
{ {
/** @var int */ /** @var int */
private $lineNumber = 0; private $lineNumber = 0;
/** @var int */ /** @var int */
...@@ -27,25 +25,32 @@ final class Location ...@@ -27,25 +25,32 @@ final class Location
/** /**
* Initializes the location for an element using its line number in the file and optionally the column number. * Initializes the location for an element using its line number in the file and optionally the column number.
*
* @param int $lineNumber
* @param int $columnNumber
*/ */
public function __construct(int $lineNumber, int $columnNumber = 0) public function __construct($lineNumber, $columnNumber = 0)
{ {
$this->lineNumber = $lineNumber; $this->lineNumber = $lineNumber;
$this->columnNumber = $columnNumber; $this->columnNumber = $columnNumber;
} }
/** /**
* Returns the line number that is covered by this location. * Returns the line number that is covered by this location.
*
* @return integer
*/ */
public function getLineNumber(): int public function getLineNumber()
{ {
return $this->lineNumber; return $this->lineNumber;
} }
/** /**
* Returns the column number (character position on a line) for this location object. * Returns the column number (character position on a line) for this location object.
*
* @return integer
*/ */
public function getColumnNumber(): int public function getColumnNumber()
{ {
return $this->columnNumber; return $this->columnNumber;
} }
......
<?php <?php
declare(strict_types=1);
/** /**
* phpDocumentor * phpDocumentor
* *
* For the full copyright and license information, please view the LICENSE * PHP Version 5.5
* file that was distributed with this source code.
* *
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) * @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT * @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org * @link http://phpdoc.org
*/ */
...@@ -21,6 +18,8 @@ interface Project ...@@ -21,6 +18,8 @@ interface Project
{ {
/** /**
* Returns the name of the project. * Returns the name of the project.
*
* @return string
*/ */
public function getName(): string; public function getName();
} }
<?php <?php
declare(strict_types=1);
/** /**
* phpDocumentor * phpDocumentor
* *
* For the full copyright and license information, please view the LICENSE * PHP Version 5.5
* file that was distributed with this source code.
* *
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) * @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT * @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org * @link http://phpdoc.org
*/ */
namespace phpDocumentor\Reflection; namespace phpDocumentor\Reflection;
/** /**
...@@ -27,5 +23,5 @@ interface ProjectFactory ...@@ -27,5 +23,5 @@ interface ProjectFactory
* @param File[] $files * @param File[] $files
* @return Project * @return Project
*/ */
public function create($name, array $files): Project; public function create($name, array $files);
} }
service_name: travis-ci
coverage_clover: coverage.xml
json_path: coverage.json
...@@ -10,12 +10,16 @@ that is 100% compatible with the [PHPDoc standard](http://phpdoc.org/docs/latest ...@@ -10,12 +10,16 @@ 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 With this component, a library can provide support for annotations via DocBlocks
or otherwise retrieve information that is embedded in a DocBlock. or otherwise retrieve information that is embedded in a DocBlock.
> **Note**: *this is a core component of phpDocumentor and is constantly being
> optimized for performance.*
Installation Installation
------------ ------------
```bash You can install the component in the following ways:
composer require phpdocumentor/reflection-docblock
``` * Use the official Github repository (https://github.com/phpDocumentor/ReflectionDocBlock)
* Via Composer (http://packagist.org/packages/phpdocumentor/reflection-docblock)
Usage Usage
----- -----
...@@ -48,20 +52,18 @@ $docblock = $factory->create($docComment); ...@@ -48,20 +52,18 @@ $docblock = $factory->create($docComment);
``` ```
The `create` method will yield an object of type `\phpDocumentor\Reflection\DocBlock` The `create` method will yield an object of type `\phpDocumentor\Reflection\DocBlock`
whose methods can be queried: whose methods can be queried as shown in the following example.
```php ```php
// Contains the summary for this DocBlock // Should contain the summary for this DocBlock
$summary = $docblock->getSummary(); $summary = $docblock->getSummary();
// Contains \phpDocumentor\Reflection\DocBlock\Description object // Contains an object of type \phpDocumentor\Reflection\DocBlock\Description;
// you can either cast it to string or use the render method to get a string
// representation of the Description.
$description = $docblock->getDescription(); $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 [`/examples` folder](/examples). > For more examples it would be best to review the scripts in the `/examples`
> folder.
build: false
clone_folder: c:\reflectiondocblock
max_jobs: 3
platform: x86
pull_requests:
do_not_increment_build_number: true
version: '{build}.{branch}'
skip_tags: true
branches:
only:
- master
environment:
matrix:
- php_ver_target: 7.1
- php_ver_target: 7.2
matrix:
fast_finish: false
cache:
- c:\php -> appveyor.yml
- '%LOCALAPPDATA%\Composer\files'
init:
- SET PATH=C:\Program Files\OpenSSL;c:\tools\php;%PATH%
- SET COMPOSER_NO_INTERACTION=1
- SET PHP=1
- SET ANSICON=121x90 (121x90)
install:
- IF EXIST c:\tools\php (SET PHP=0)
- ps: appveyor-retry cinst --params '""/InstallDir:C:\tools\php""' --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php_ver_target | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','')
- cd c:\tools\php
- IF %PHP%==1 copy /Y php.ini-development php.ini
- IF %PHP%==1 echo max_execution_time=1200 >> php.ini
- IF %PHP%==1 echo date.timezone="UTC" >> php.ini
- IF %PHP%==1 echo extension_dir=ext >> php.ini
- IF %PHP%==1 echo extension=php_curl.dll >> php.ini
- IF %PHP%==1 echo extension=php_openssl.dll >> php.ini
- IF %PHP%==1 echo extension=php_mbstring.dll >> php.ini
- IF %PHP%==1 echo extension=php_fileinfo.dll >> php.ini
- IF %PHP%==1 echo zend.assertions=1 >> php.ini
- IF %PHP%==1 echo assert.exception=On >> php.ini
- IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
- appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar
- cd c:\reflectiondocblock
- composer install --no-interaction --prefer-dist --no-progress
- composer global require phpunit/phpunit ^6
- composer global config bin-dir --absolute
test_script:
- cd c:\reflectiondocblock
- c:\Users\appveyor\AppData\Roaming\Composer\vendor\bin\phpunit --no-coverage
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
} }
], ],
"require": { "require": {
"php": "^7.0", "php": ">=5.5",
"phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", "phpdocumentor/reflection-common": "^1.0@dev",
"phpdocumentor/type-resolver": "~0.4 || ^1.0.0", "phpdocumentor/type-resolver": "^0.3.0",
"webmozart/assert": "^1.0" "webmozart/assert": "^1.0"
}, },
"autoload": { "autoload": {
...@@ -22,14 +22,7 @@ ...@@ -22,14 +22,7 @@
"psr-4": {"phpDocumentor\\Reflection\\": ["tests/unit"]} "psr-4": {"phpDocumentor\\Reflection\\": ["tests/unit"]}
}, },
"require-dev": { "require-dev": {
"mockery/mockery": "^1.0", "mockery/mockery": "^0.9.4",
"phpdocumentor/type-resolver": "0.4.*", "phpunit/phpunit": "^4.4"
"phpunit/phpunit": "^6.4",
"doctrine/instantiator": "^1.0.5"
},
"extra": {
"branch-alias": {
"dev-master": "4.x-dev"
}
} }
} }
includes:
- temp/ecs/config/clean-code.neon
- temp/ecs/config/psr2-checkers.neon
- temp/ecs/config/spaces.neon
- temp/ecs/config/common.neon
checkers:
PhpCsFixer\Fixer\Operator\ConcatSpaceFixer:
spacing: one
parameters:
exclude_checkers:
# from temp/ecs/config/common.neon
- PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer
- PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer
- PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer
# from temp/ecs/config/spaces.neon
- PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer
skip:
SlevomatCodingStandard\Sniffs\Classes\UnusedPrivateElementsSniff:
# WIP code
- src/DocBlock/StandardTagFactory.php
PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\EmptyStatementSniff:
# WIP code
- src/DocBlock/StandardTagFactory.php
PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes\ValidClassNameSniff:
- src/DocBlock/Tags/Return_.php
- src/DocBlock/Tags/Var_.php
PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\CamelCapsFunctionNameSniff:
- */tests/**
...@@ -24,7 +24,7 @@ final class DocBlock ...@@ -24,7 +24,7 @@ final class DocBlock
private $description = null; private $description = null;
/** @var Tag[] An array containing all the tags in this docblock; except inline. */ /** @var Tag[] An array containing all the tags in this docblock; except inline. */
private $tags = []; private $tags = array();
/** @var Types\Context Information about the context of this DocBlock. */ /** @var Types\Context Information about the context of this DocBlock. */
private $context = null; private $context = null;
...@@ -55,7 +55,8 @@ final class DocBlock ...@@ -55,7 +55,8 @@ final class DocBlock
Location $location = null, Location $location = null,
$isTemplateStart = false, $isTemplateStart = false,
$isTemplateEnd = false $isTemplateEnd = false
) { )
{
Assert::string($summary); Assert::string($summary);
Assert::boolean($isTemplateStart); Assert::boolean($isTemplateStart);
Assert::boolean($isTemplateEnd); Assert::boolean($isTemplateEnd);
...@@ -170,11 +171,11 @@ final class DocBlock ...@@ -170,11 +171,11 @@ final class DocBlock
{ {
Assert::string($name); Assert::string($name);
$result = []; $result = array();
/** @var Tag $tag */ /** @var Tag $tag */
foreach ($this->getTags() as $tag) { foreach ($this->getTags() as $tag) {
if ($tag->getName() !== $name) { if ($tag->getName() != $name) {
continue; continue;
} }
...@@ -197,7 +198,7 @@ final class DocBlock ...@@ -197,7 +198,7 @@ final class DocBlock
/** @var Tag $tag */ /** @var Tag $tag */
foreach ($this->getTags() as $tag) { foreach ($this->getTags() as $tag) {
if ($tag->getName() === $name) { if ($tag->getName() == $name) {
return true; return true;
} }
} }
...@@ -206,23 +207,6 @@ final class DocBlock ...@@ -206,23 +207,6 @@ final class DocBlock
} }
/** /**
* Remove a tag from this DocBlock.
*
* @param Tag $tag The tag to remove.
*
* @return void
*/
public function removeTag(Tag $tagToRemove)
{
foreach ($this->tags as $key => $tag) {
if ($tag === $tagToRemove) {
unset($this->tags[$key]);
break;
}
}
}
/**
* Adds a tag to this DocBlock. * Adds a tag to this DocBlock.
* *
* @param Tag $tag The tag to add. * @param Tag $tag The tag to add.
......
...@@ -71,16 +71,6 @@ class Description ...@@ -71,16 +71,6 @@ class Description
} }
/** /**
* Returns the tags for this DocBlock.
*
* @return Tag[]
*/
public function getTags()
{
return $this->tags;
}
/**
* Renders this description as a string where the provided formatter will format the tags in the expected string * Renders this description as a string where the provided formatter will format the tags in the expected string
* format. * format.
* *
...@@ -98,7 +88,6 @@ class Description ...@@ -98,7 +88,6 @@ class Description
foreach ($this->tags as $tag) { foreach ($this->tags as $tag) {
$tags[] = '{' . $formatter->format($tag) . '}'; $tags[] = '{' . $formatter->format($tag) . '}';
} }
return vsprintf($this->bodyTemplate, $tags); return vsprintf($this->bodyTemplate, $tags);
} }
......
...@@ -188,4 +188,5 @@ class DescriptionFactory ...@@ -188,4 +188,5 @@ class DescriptionFactory
return implode("\n", $lines); return implode("\n", $lines);
} }
} }
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* @link http://phpdoc.org * @link http://phpdoc.org
*/ */
namespace phpDocumentor\Reflection\DocBlock; namespace phpDocumentor\Reflection;
use phpDocumentor\Reflection\DocBlock\Tags\Example; use phpDocumentor\Reflection\DocBlock\Tags\Example;
...@@ -23,7 +23,7 @@ class ExampleFinder ...@@ -23,7 +23,7 @@ class ExampleFinder
private $sourceDirectory = ''; private $sourceDirectory = '';
/** @var string[] */ /** @var string[] */
private $exampleDirectories = []; private $exampleDirectories = array();
/** /**
* Attempts to find the example contents for the given descriptor. * Attempts to find the example contents for the given descriptor.
......
...@@ -81,12 +81,7 @@ class Serializer ...@@ -81,12 +81,7 @@ class Serializer
) )
); );
$comment = "{$firstIndent}/**\n"; $comment = "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n";
if ($text) {
$comment .= "{$indent} * {$text}\n";
$comment .= "{$indent} *\n";
}
$comment = $this->addTagBlock($docblock, $wrapLength, $indent, $comment); $comment = $this->addTagBlock($docblock, $wrapLength, $indent, $comment);
$comment .= $indent . ' */'; $comment .= $indent . ' */';
...@@ -126,7 +121,6 @@ class Serializer ...@@ -126,7 +121,6 @@ class Serializer
$text = wordwrap($text, $wrapLength); $text = wordwrap($text, $wrapLength);
return $text; return $text;
} }
return $text; return $text;
} }
...@@ -144,7 +138,6 @@ class Serializer ...@@ -144,7 +138,6 @@ class Serializer
if ($wrapLength !== null) { if ($wrapLength !== null) {
$tagText = wordwrap($tagText, $wrapLength); $tagText = wordwrap($tagText, $wrapLength);
} }
$tagText = str_replace("\n", "\n{$indent} * ", $tagText); $tagText = str_replace("\n", "\n{$indent} * ", $tagText);
$comment .= "{$indent} * {$tagText}\n"; $comment .= "{$indent} * {$tagText}\n";
......
...@@ -166,7 +166,7 @@ final class StandardTagFactory implements TagFactory ...@@ -166,7 +166,7 @@ final class StandardTagFactory implements TagFactory
*/ */
private function extractTagParts($tagLine) private function extractTagParts($tagLine)
{ {
$matches = []; $matches = array();
if (! preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)/us', $tagLine, $matches)) { if (! preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)/us', $tagLine, $matches)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors' 'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors'
...@@ -196,7 +196,8 @@ final class StandardTagFactory implements TagFactory ...@@ -196,7 +196,8 @@ final class StandardTagFactory implements TagFactory
$arguments = $this->getArgumentsForParametersFromWiring( $arguments = $this->getArgumentsForParametersFromWiring(
$this->fetchParametersForHandlerFactoryMethod($handlerClassName), $this->fetchParametersForHandlerFactoryMethod($handlerClassName),
$this->getServiceLocatorWithDynamicParameters($context, $name, $body) $this->getServiceLocatorWithDynamicParameters($context, $name, $body)
); )
;
return call_user_func_array([$handlerClassName, 'create'], $arguments); return call_user_func_array([$handlerClassName, 'create'], $arguments);
} }
......
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of phpDocumentor. * This file is part of phpDocumentor.
* *
......
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
namespace phpDocumentor\Reflection\DocBlock\Tags; namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\Types\Context as TypeContext; use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\FqsenResolver;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
/** /**
...@@ -49,7 +49,8 @@ final class Covers extends BaseTag implements Factory\StaticMethod ...@@ -49,7 +49,8 @@ final class Covers extends BaseTag implements Factory\StaticMethod
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
FqsenResolver $resolver = null, FqsenResolver $resolver = null,
TypeContext $context = null TypeContext $context = null
) { )
{
Assert::string($body); Assert::string($body);
Assert::notEmpty($body); Assert::notEmpty($body);
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
namespace phpDocumentor\Reflection\DocBlock\Tags; namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
/** /**
......
...@@ -12,19 +12,17 @@ ...@@ -12,19 +12,17 @@
namespace phpDocumentor\Reflection\DocBlock\Tags; namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\Tag;
use Webmozart\Assert\Assert;
/** /**
* Reflection class for a {@}example tag in a Docblock. * Reflection class for a {@}example tag in a Docblock.
*/ */
final class Example extends BaseTag implements Factory\StaticMethod final class Example extends BaseTag
{ {
/** /**
* @var string Path to a file to use as an example. May also be an absolute URI. * @var string Path to a file to use as an example. May also be an absolute URI.
*/ */
private $filePath; private $filePath = '';
/** /**
* @var bool Whether the file path component represents an URI. This determines how the file portion * @var bool Whether the file path component represents an URI. This determines how the file portion
...@@ -33,33 +31,6 @@ final class Example extends BaseTag implements Factory\StaticMethod ...@@ -33,33 +31,6 @@ final class Example extends BaseTag implements Factory\StaticMethod
private $isURI = false; private $isURI = false;
/** /**
* @var int
*/
private $startingLine;
/**
* @var int
*/
private $lineCount;
public function __construct($filePath, $isURI, $startingLine, $lineCount, $description)
{
Assert::notEmpty($filePath);
Assert::integer($startingLine);
Assert::greaterThanEq($startingLine, 0);
$this->filePath = $filePath;
$this->startingLine = $startingLine;
$this->lineCount = $lineCount;
$this->name = 'example';
if ($description !== null) {
$this->description = trim($description);
}
$this->isURI = $isURI;
}
/**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getContent() public function getContent()
...@@ -72,7 +43,7 @@ final class Example extends BaseTag implements Factory\StaticMethod ...@@ -72,7 +43,7 @@ final class Example extends BaseTag implements Factory\StaticMethod
:$this->filePath; :$this->filePath;
} }
return trim($filePath . ' ' . parent::getDescription()); $this->description = $filePath . ' ' . parent::getContent();
} }
return $this->description; return $this->description;
...@@ -100,29 +71,16 @@ final class Example extends BaseTag implements Factory\StaticMethod ...@@ -100,29 +71,16 @@ final class Example extends BaseTag implements Factory\StaticMethod
$lineCount = null; $lineCount = null;
$description = null; $description = null;
if (array_key_exists(3, $matches)) { // Starting line / Number of lines / Description
$description = $matches[3]; if (preg_match('/^([1-9]\d*)\s*(?:((?1))\s+)?(.*)$/sux', $matches[3], $matches)) {
$startingLine = (int)$matches[1];
// Starting line / Number of lines / Description if (isset($matches[2]) && $matches[2] !== '') {
if (preg_match('/^([1-9]\d*)(?:\s+((?1))\s*)?(.*)$/sux', $matches[3], $contentMatches)) { $lineCount = (int)$matches[2];
$startingLine = (int)$contentMatches[1];
if (isset($contentMatches[2]) && $contentMatches[2] !== '') {
$lineCount = (int)$contentMatches[2];
}
if (array_key_exists(3, $contentMatches)) {
$description = $contentMatches[3];
}
} }
$description = $matches[3];
} }
return new static( return new static($filePath, $fileUri, $startingLine, $lineCount, $description);
$filePath !== null?$filePath:$fileUri,
$fileUri !== null,
$startingLine,
$lineCount,
$description
);
} }
/** /**
...@@ -137,40 +95,64 @@ final class Example extends BaseTag implements Factory\StaticMethod ...@@ -137,40 +95,64 @@ final class Example extends BaseTag implements Factory\StaticMethod
} }
/** /**
* Returns a string representation for this tag. * Sets the file path.
* *
* @return string * @param string $filePath The new file path to use for the example.
*
* @return $this
*/ */
public function __toString() public function setFilePath($filePath)
{ {
return $this->filePath . ($this->description ? ' ' . $this->description : ''); $this->isURI = false;
$this->filePath = trim($filePath);
$this->description = null;
return $this;
} }
/** /**
* Returns true if the provided URI is relative or contains a complete scheme (and thus is absolute). * Sets the file path as an URI.
* *
* @param string $uri * This function is equivalent to {@link setFilePath()}, except that it
* converts an URI to a file path before that.
* *
* @return bool * There is no getFileURI(), as {@link getFilePath()} is compatible.
*
* @param string $uri The new file URI to use as an example.
*
* @return $this
*/ */
private function isUriRelative($uri) public function setFileURI($uri)
{ {
return false === strpos($uri, ':'); $this->isURI = true;
$this->description = null;
$this->filePath = $this->isUriRelative($uri)
? rawurldecode(str_replace(array('/', '\\'), '%2F', $uri))
: $this->filePath = $uri;
return $this;
} }
/** /**
* @return int * Returns a string representation for this tag.
*
* @return string
*/ */
public function getStartingLine() public function __toString()
{ {
return $this->startingLine; return $this->filePath . ($this->description ? ' ' . $this->description->render() : '');
} }
/** /**
* @return int * Returns true if the provided URI is relative or contains a complete scheme (and thus is absolute).
*
* @param string $uri
*
* @return bool
*/ */
public function getLineCount() private function isUriRelative($uri)
{ {
return $this->lineCount; return false === strpos($uri, ':');
} }
} }
...@@ -57,7 +57,7 @@ class Generic extends BaseTag implements Factory\StaticMethod ...@@ -57,7 +57,7 @@ class Generic extends BaseTag implements Factory\StaticMethod
Assert::stringNotEmpty($name); Assert::stringNotEmpty($name);
Assert::notNull($descriptionFactory); Assert::notNull($descriptionFactory);
$description = $descriptionFactory && $body !== "" ? $descriptionFactory->create($body, $context) : null; $description = $descriptionFactory && $body ? $descriptionFactory->create($body, $context) : null;
return new static($name, $description); return new static($name, $description);
} }
......
...@@ -102,8 +102,12 @@ final class Method extends BaseTag implements Factory\StaticMethod ...@@ -102,8 +102,12 @@ final class Method extends BaseTag implements Factory\StaticMethod
) )
\s+ \s+
)? )?
# Legacy method name (not captured)
(?:
[\w_]+\(\)\s+
)?
# Method name # Method name
([\w_]+) ([\w\|_\\\\]+)
# Arguments # Arguments
(?: (?:
\(([^\)]*)\) \(([^\)]*)\)
...@@ -131,7 +135,7 @@ final class Method extends BaseTag implements Factory\StaticMethod ...@@ -131,7 +135,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
if (is_string($arguments) && strlen($arguments) > 0) { if (is_string($arguments) && strlen($arguments) > 0) {
$arguments = explode(',', $arguments); $arguments = explode(',', $arguments);
foreach ($arguments as &$argument) { foreach($arguments as &$argument) {
$argument = explode(' ', self::stripRestArg(trim($argument)), 2); $argument = explode(' ', self::stripRestArg(trim($argument)), 2);
if ($argument[0][0] === '$') { if ($argument[0][0] === '$') {
$argumentName = substr($argument[0], 1); $argumentName = substr($argument[0], 1);
...@@ -210,13 +214,10 @@ final class Method extends BaseTag implements Factory\StaticMethod ...@@ -210,13 +214,10 @@ final class Method extends BaseTag implements Factory\StaticMethod
if (is_string($argument)) { if (is_string($argument)) {
$argument = [ 'name' => $argument ]; $argument = [ 'name' => $argument ];
} }
if (! isset($argument['type'])) { if (! isset($argument['type'])) {
$argument['type'] = new Void_(); $argument['type'] = new Void_();
} }
$keys = array_keys($argument); $keys = array_keys($argument);
sort($keys);
if ($keys !== [ 'name', 'type' ]) { if ($keys !== [ 'name', 'type' ]) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
'Arguments can only have the "name" and "type" fields, found: ' . var_export($keys, true) 'Arguments can only have the "name" and "type" fields, found: ' . var_export($keys, true)
......
...@@ -22,9 +22,15 @@ use Webmozart\Assert\Assert; ...@@ -22,9 +22,15 @@ use Webmozart\Assert\Assert;
/** /**
* Reflection class for the {@}param tag in a Docblock. * Reflection class for the {@}param tag in a Docblock.
*/ */
final class Param extends TagWithType implements Factory\StaticMethod final class Param extends BaseTag implements Factory\StaticMethod
{ {
/** @var string */ /** @var string */
protected $name = 'param';
/** @var Type */
private $type;
/** @var string */
private $variableName = ''; private $variableName = '';
/** @var bool determines whether this is a variadic argument */ /** @var bool determines whether this is a variadic argument */
...@@ -41,7 +47,6 @@ final class Param extends TagWithType implements Factory\StaticMethod ...@@ -41,7 +47,6 @@ final class Param extends TagWithType implements Factory\StaticMethod
Assert::string($variableName); Assert::string($variableName);
Assert::boolean($isVariadic); Assert::boolean($isVariadic);
$this->name = 'param';
$this->variableName = $variableName; $this->variableName = $variableName;
$this->type = $type; $this->type = $type;
$this->isVariadic = $isVariadic; $this->isVariadic = $isVariadic;
...@@ -60,25 +65,19 @@ final class Param extends TagWithType implements Factory\StaticMethod ...@@ -60,25 +65,19 @@ final class Param extends TagWithType implements Factory\StaticMethod
Assert::stringNotEmpty($body); Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]); Assert::allNotNull([$typeResolver, $descriptionFactory]);
list($firstPart, $body) = self::extractTypeFromBody($body); $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
$type = null; $type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = ''; $variableName = '';
$isVariadic = false; $isVariadic = false;
// if the first item that is encountered is not a variable; it is a type // if the first item that is encountered is not a variable; it is a type
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) { if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) {
$type = $typeResolver->resolve($firstPart, $context); $type = $typeResolver->resolve(array_shift($parts), $context);
} else { array_shift($parts);
// first part is not a type; we should prepend it to the parts array for further processing
array_unshift($parts, $firstPart);
} }
// if the next item starts with a $ or ...$ it must be the variable name // if the next item starts with a $ or ...$ it must be the variable name
if (isset($parts[0]) if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$')) {
&& (strlen($parts[0]) > 0)
&& ($parts[0][0] === '$' || substr($parts[0], 0, 4) === '...$')
) {
$variableName = array_shift($parts); $variableName = array_shift($parts);
array_shift($parts); array_shift($parts);
...@@ -108,6 +107,16 @@ final class Param extends TagWithType implements Factory\StaticMethod ...@@ -108,6 +107,16 @@ final class Param extends TagWithType implements Factory\StaticMethod
} }
/** /**
* Returns the variable's type or null if unknown.
*
* @return Type|null
*/
public function getType()
{
return $this->type;
}
/**
* Returns whether this tag is variadic. * Returns whether this tag is variadic.
* *
* @return boolean * @return boolean
...@@ -125,8 +134,8 @@ final class Param extends TagWithType implements Factory\StaticMethod ...@@ -125,8 +134,8 @@ final class Param extends TagWithType implements Factory\StaticMethod
public function __toString() public function __toString()
{ {
return ($this->type ? $this->type . ' ' : '') return ($this->type ? $this->type . ' ' : '')
. ($this->isVariadic() ? '...' : '') . ($this->isVariadic() ? '...' : '')
. '$' . $this->variableName . '$' . $this->variableName
. ($this->description ? ' ' . $this->description : ''); . ($this->description ? ' ' . $this->description : '');
} }
} }
...@@ -22,21 +22,26 @@ use Webmozart\Assert\Assert; ...@@ -22,21 +22,26 @@ use Webmozart\Assert\Assert;
/** /**
* Reflection class for a {@}property tag in a Docblock. * Reflection class for a {@}property tag in a Docblock.
*/ */
class Property extends TagWithType implements Factory\StaticMethod class Property extends BaseTag implements Factory\StaticMethod
{ {
/** @var string */ /** @var string */
protected $name = 'property';
/** @var Type */
private $type;
/** @var string */
protected $variableName = ''; protected $variableName = '';
/** /**
* @param string $variableName * @param string $variableName
* @param Type $type * @param Type $type
* @param Description $description * @param Description $description
*/ */
public function __construct($variableName, Type $type = null, Description $description = null) public function __construct($variableName, Type $type = null, Description $description = null)
{ {
Assert::string($variableName); Assert::string($variableName);
$this->name = 'property';
$this->variableName = $variableName; $this->variableName = $variableName;
$this->type = $type; $this->type = $type;
$this->description = $description; $this->description = $description;
...@@ -54,21 +59,18 @@ class Property extends TagWithType implements Factory\StaticMethod ...@@ -54,21 +59,18 @@ class Property extends TagWithType implements Factory\StaticMethod
Assert::stringNotEmpty($body); Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]); Assert::allNotNull([$typeResolver, $descriptionFactory]);
list($firstPart, $body) = self::extractTypeFromBody($body); $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
$type = null; $type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = ''; $variableName = '';
// if the first item that is encountered is not a variable; it is a type // if the first item that is encountered is not a variable; it is a type
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) { if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) {
$type = $typeResolver->resolve($firstPart, $context); $type = $typeResolver->resolve(array_shift($parts), $context);
} else { array_shift($parts);
// first part is not a type; we should prepend it to the parts array for further processing
array_unshift($parts, $firstPart);
} }
// if the next item starts with a $ or ...$ it must be the variable name // 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] === '$')) { if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] == '$')) {
$variableName = array_shift($parts); $variableName = array_shift($parts);
array_shift($parts); array_shift($parts);
...@@ -93,6 +95,16 @@ class Property extends TagWithType implements Factory\StaticMethod ...@@ -93,6 +95,16 @@ class Property extends TagWithType implements Factory\StaticMethod
} }
/** /**
* Returns the variable's type or null if unknown.
*
* @return Type|null
*/
public function getType()
{
return $this->type;
}
/**
* Returns a string representation for this tag. * Returns a string representation for this tag.
* *
* @return string * @return string
...@@ -100,7 +112,7 @@ class Property extends TagWithType implements Factory\StaticMethod ...@@ -100,7 +112,7 @@ class Property extends TagWithType implements Factory\StaticMethod
public function __toString() public function __toString()
{ {
return ($this->type ? $this->type . ' ' : '') return ($this->type ? $this->type . ' ' : '')
. '$' . $this->variableName . '$' . $this->variableName
. ($this->description ? ' ' . $this->description : ''); . ($this->description ? ' ' . $this->description : '');
} }
} }
...@@ -22,21 +22,26 @@ use Webmozart\Assert\Assert; ...@@ -22,21 +22,26 @@ use Webmozart\Assert\Assert;
/** /**
* Reflection class for a {@}property-read tag in a Docblock. * Reflection class for a {@}property-read tag in a Docblock.
*/ */
class PropertyRead extends TagWithType implements Factory\StaticMethod class PropertyRead extends BaseTag implements Factory\StaticMethod
{ {
/** @var string */ /** @var string */
protected $name = 'property-read';
/** @var Type */
private $type;
/** @var string */
protected $variableName = ''; protected $variableName = '';
/** /**
* @param string $variableName * @param string $variableName
* @param Type $type * @param Type $type
* @param Description $description * @param Description $description
*/ */
public function __construct($variableName, Type $type = null, Description $description = null) public function __construct($variableName, Type $type = null, Description $description = null)
{ {
Assert::string($variableName); Assert::string($variableName);
$this->name = 'property-read';
$this->variableName = $variableName; $this->variableName = $variableName;
$this->type = $type; $this->type = $type;
$this->description = $description; $this->description = $description;
...@@ -54,21 +59,18 @@ class PropertyRead extends TagWithType implements Factory\StaticMethod ...@@ -54,21 +59,18 @@ class PropertyRead extends TagWithType implements Factory\StaticMethod
Assert::stringNotEmpty($body); Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]); Assert::allNotNull([$typeResolver, $descriptionFactory]);
list($firstPart, $body) = self::extractTypeFromBody($body); $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
$type = null; $type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = ''; $variableName = '';
// if the first item that is encountered is not a variable; it is a type // if the first item that is encountered is not a variable; it is a type
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) { if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) {
$type = $typeResolver->resolve($firstPart, $context); $type = $typeResolver->resolve(array_shift($parts), $context);
} else { array_shift($parts);
// first part is not a type; we should prepend it to the parts array for further processing
array_unshift($parts, $firstPart);
} }
// if the next item starts with a $ or ...$ it must be the variable name // 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] === '$')) { if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] == '$')) {
$variableName = array_shift($parts); $variableName = array_shift($parts);
array_shift($parts); array_shift($parts);
...@@ -93,6 +95,16 @@ class PropertyRead extends TagWithType implements Factory\StaticMethod ...@@ -93,6 +95,16 @@ class PropertyRead extends TagWithType implements Factory\StaticMethod
} }
/** /**
* Returns the variable's type or null if unknown.
*
* @return Type|null
*/
public function getType()
{
return $this->type;
}
/**
* Returns a string representation for this tag. * Returns a string representation for this tag.
* *
* @return string * @return string
...@@ -100,7 +112,7 @@ class PropertyRead extends TagWithType implements Factory\StaticMethod ...@@ -100,7 +112,7 @@ class PropertyRead extends TagWithType implements Factory\StaticMethod
public function __toString() public function __toString()
{ {
return ($this->type ? $this->type . ' ' : '') return ($this->type ? $this->type . ' ' : '')
. '$' . $this->variableName . '$' . $this->variableName
. ($this->description ? ' ' . $this->description : ''); . ($this->description ? ' ' . $this->description : '');
} }
} }
...@@ -22,21 +22,26 @@ use Webmozart\Assert\Assert; ...@@ -22,21 +22,26 @@ use Webmozart\Assert\Assert;
/** /**
* Reflection class for a {@}property-write tag in a Docblock. * Reflection class for a {@}property-write tag in a Docblock.
*/ */
class PropertyWrite extends TagWithType implements Factory\StaticMethod class PropertyWrite extends BaseTag implements Factory\StaticMethod
{ {
/** @var string */ /** @var string */
protected $name = 'property-write';
/** @var Type */
private $type;
/** @var string */
protected $variableName = ''; protected $variableName = '';
/** /**
* @param string $variableName * @param string $variableName
* @param Type $type * @param Type $type
* @param Description $description * @param Description $description
*/ */
public function __construct($variableName, Type $type = null, Description $description = null) public function __construct($variableName, Type $type = null, Description $description = null)
{ {
Assert::string($variableName); Assert::string($variableName);
$this->name = 'property-write';
$this->variableName = $variableName; $this->variableName = $variableName;
$this->type = $type; $this->type = $type;
$this->description = $description; $this->description = $description;
...@@ -54,21 +59,18 @@ class PropertyWrite extends TagWithType implements Factory\StaticMethod ...@@ -54,21 +59,18 @@ class PropertyWrite extends TagWithType implements Factory\StaticMethod
Assert::stringNotEmpty($body); Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]); Assert::allNotNull([$typeResolver, $descriptionFactory]);
list($firstPart, $body) = self::extractTypeFromBody($body); $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
$type = null; $type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = ''; $variableName = '';
// if the first item that is encountered is not a variable; it is a type // if the first item that is encountered is not a variable; it is a type
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) { if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) {
$type = $typeResolver->resolve($firstPart, $context); $type = $typeResolver->resolve(array_shift($parts), $context);
} else { array_shift($parts);
// first part is not a type; we should prepend it to the parts array for further processing
array_unshift($parts, $firstPart);
} }
// if the next item starts with a $ or ...$ it must be the variable name // 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] === '$')) { if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] == '$')) {
$variableName = array_shift($parts); $variableName = array_shift($parts);
array_shift($parts); array_shift($parts);
...@@ -93,6 +95,16 @@ class PropertyWrite extends TagWithType implements Factory\StaticMethod ...@@ -93,6 +95,16 @@ class PropertyWrite extends TagWithType implements Factory\StaticMethod
} }
/** /**
* Returns the variable's type or null if unknown.
*
* @return Type|null
*/
public function getType()
{
return $this->type;
}
/**
* Returns a string representation for this tag. * Returns a string representation for this tag.
* *
* @return string * @return string
...@@ -100,7 +112,7 @@ class PropertyWrite extends TagWithType implements Factory\StaticMethod ...@@ -100,7 +112,7 @@ class PropertyWrite extends TagWithType implements Factory\StaticMethod
public function __toString() public function __toString()
{ {
return ($this->type ? $this->type . ' ' : '') return ($this->type ? $this->type . ' ' : '')
. '$' . $this->variableName . '$' . $this->variableName
. ($this->description ? ' ' . $this->description : ''); . ($this->description ? ' ' . $this->description : '');
} }
} }
<?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.
*
* @copyright 2010-2017 Mike van Riel<mike@phpdoc.org>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @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
{
/**
* @var RealFqsen
*/
private $fqsen;
/**
* Fqsen constructor.
*/
public function __construct(RealFqsen $fqsen)
{
$this->fqsen = $fqsen;
}
/**
* @return string string representation of the referenced fqsen
*/
public function __toString()
{
return (string)$this->fqsen;
}
}
<?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.
*
* @copyright 2010-2017 Mike van Riel<mike@phpdoc.org>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @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();
}
<?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.
*
* @copyright 2010-2017 Mike van Riel<mike@phpdoc.org>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @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
{
/**
* @var string
*/
private $uri;
/**
* Url constructor.
*/
public function __construct($uri)
{
Assert::stringNotEmpty($uri);
$this->uri = $uri;
}
public function __toString()
{
return $this->uri;
}
}
...@@ -22,11 +22,15 @@ use Webmozart\Assert\Assert; ...@@ -22,11 +22,15 @@ use Webmozart\Assert\Assert;
/** /**
* Reflection class for a {@}return tag in a Docblock. * Reflection class for a {@}return tag in a Docblock.
*/ */
final class Return_ extends TagWithType implements Factory\StaticMethod final class Return_ extends BaseTag implements Factory\StaticMethod
{ {
protected $name = 'return';
/** @var Type */
private $type;
public function __construct(Type $type, Description $description = null) public function __construct(Type $type, Description $description = null)
{ {
$this->name = 'return';
$this->type = $type; $this->type = $type;
$this->description = $description; $this->description = $description;
} }
...@@ -39,18 +43,29 @@ final class Return_ extends TagWithType implements Factory\StaticMethod ...@@ -39,18 +43,29 @@ final class Return_ extends TagWithType implements Factory\StaticMethod
TypeResolver $typeResolver = null, TypeResolver $typeResolver = null,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
) { )
{
Assert::string($body); Assert::string($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]); Assert::allNotNull([$typeResolver, $descriptionFactory]);
list($type, $description) = self::extractTypeFromBody($body); $parts = preg_split('/\s+/Su', $body, 2);
$type = $typeResolver->resolve($type, $context); $type = $typeResolver->resolve(isset($parts[0]) ? $parts[0] : '', $context);
$description = $descriptionFactory->create($description, $context); $description = $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context);
return new static($type, $description); return new static($type, $description);
} }
/**
* Returns the type section of the variable.
*
* @return Type
*/
public function getType()
{
return $this->type;
}
public function __toString() public function __toString()
{ {
return $this->type . ' ' . $this->description; return $this->type . ' ' . $this->description;
......
...@@ -12,13 +12,11 @@ ...@@ -12,13 +12,11 @@
namespace phpDocumentor\Reflection\DocBlock\Tags; namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as FqsenRef; use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Reference;
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url;
use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\FqsenResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext; use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\DocBlock\Description;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
/** /**
...@@ -28,16 +26,16 @@ class See extends BaseTag implements Factory\StaticMethod ...@@ -28,16 +26,16 @@ class See extends BaseTag implements Factory\StaticMethod
{ {
protected $name = 'see'; protected $name = 'see';
/** @var Reference */ /** @var Fqsen */
protected $refers = null; protected $refers = null;
/** /**
* Initializes this tag. * Initializes this tag.
* *
* @param Reference $refers * @param Fqsen $refers
* @param Description $description * @param Description $description
*/ */
public function __construct(Reference $refers, Description $description = null) public function __construct(Fqsen $refers, Description $description = null)
{ {
$this->refers = $refers; $this->refers = $refers;
$this->description = $description; $this->description = $description;
...@@ -58,18 +56,13 @@ class See extends BaseTag implements Factory\StaticMethod ...@@ -58,18 +56,13 @@ class See extends BaseTag implements Factory\StaticMethod
$parts = preg_split('/\s+/Su', $body, 2); $parts = preg_split('/\s+/Su', $body, 2);
$description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null;
// https://tools.ietf.org/html/rfc2396#section-3 return new static($resolver->resolve($parts[0], $context), $description);
if (preg_match('/\w:\/\/\w/i', $parts[0])) {
return new static(new Url($parts[0]), $description);
}
return new static(new FqsenRef($resolver->resolve($parts[0], $context)), $description);
} }
/** /**
* Returns the ref of this tag. * Returns the structural element this tag refers to.
* *
* @return Reference * @return Fqsen
*/ */
public function getReference() public function getReference()
{ {
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
namespace phpDocumentor\Reflection\DocBlock\Tags; namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
/** /**
......
...@@ -59,7 +59,6 @@ final class Source extends BaseTag implements Factory\StaticMethod ...@@ -59,7 +59,6 @@ final class Source extends BaseTag implements Factory\StaticMethod
if (isset($matches[2]) && $matches[2] !== '') { if (isset($matches[2]) && $matches[2] !== '') {
$lineCount = (int)$matches[2]; $lineCount = (int)$matches[2];
} }
$description = $matches[3]; $description = $matches[3];
} }
......
<?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.
*
* @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\Type;
abstract class TagWithType extends BaseTag
{
/** @var Type */
protected $type;
/**
* Returns the type section of the variable.
*
* @return Type
*/
public function getType()
{
return $this->type;
}
protected static function extractTypeFromBody(string $body) : array
{
$type = '';
$nestingLevel = 0;
for ($i = 0; $i < strlen($body); $i++) {
$character = $body[$i];
if (trim($character) === '' && $nestingLevel === 0) {
break;
}
$type .= $character;
if (in_array($character, ['<', '(', '[', '{'])) {
$nestingLevel++;
}
if (in_array($character, ['>', ')', ']', '}'])) {
$nestingLevel--;
}
}
$description = trim(substr($body, strlen($type)));
return [$type, $description];
}
}
...@@ -22,12 +22,16 @@ use Webmozart\Assert\Assert; ...@@ -22,12 +22,16 @@ use Webmozart\Assert\Assert;
/** /**
* Reflection class for a {@}throws tag in a Docblock. * Reflection class for a {@}throws tag in a Docblock.
*/ */
final class Throws extends TagWithType implements Factory\StaticMethod final class Throws extends BaseTag implements Factory\StaticMethod
{ {
protected $name = 'throws';
/** @var Type */
private $type;
public function __construct(Type $type, Description $description = null) public function __construct(Type $type, Description $description = null)
{ {
$this->name = 'throws'; $this->type = $type;
$this->type = $type;
$this->description = $description; $this->description = $description;
} }
...@@ -43,14 +47,24 @@ final class Throws extends TagWithType implements Factory\StaticMethod ...@@ -43,14 +47,24 @@ final class Throws extends TagWithType implements Factory\StaticMethod
Assert::string($body); Assert::string($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]); Assert::allNotNull([$typeResolver, $descriptionFactory]);
list($type, $description) = self::extractTypeFromBody($body); $parts = preg_split('/\s+/Su', $body, 2);
$type = $typeResolver->resolve($type, $context); $type = $typeResolver->resolve(isset($parts[0]) ? $parts[0] : '', $context);
$description = $descriptionFactory->create($description, $context); $description = $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context);
return new static($type, $description); return new static($type, $description);
} }
/**
* Returns the type section of the variable.
*
* @return Type
*/
public function getType()
{
return $this->type;
}
public function __toString() public function __toString()
{ {
return $this->type . ' ' . $this->description; return $this->type . ' ' . $this->description;
......
...@@ -22,24 +22,29 @@ use Webmozart\Assert\Assert; ...@@ -22,24 +22,29 @@ use Webmozart\Assert\Assert;
/** /**
* Reflection class for a {@}var tag in a Docblock. * Reflection class for a {@}var tag in a Docblock.
*/ */
class Var_ extends TagWithType implements Factory\StaticMethod class Var_ extends BaseTag implements Factory\StaticMethod
{ {
/** @var string */ /** @var string */
protected $name = 'var';
/** @var Type */
private $type;
/** @var string */
protected $variableName = ''; protected $variableName = '';
/** /**
* @param string $variableName * @param string $variableName
* @param Type $type * @param Type $type
* @param Description $description * @param Description $description
*/ */
public function __construct($variableName, Type $type = null, Description $description = null) public function __construct($variableName, Type $type = null, Description $description = null)
{ {
Assert::string($variableName); Assert::string($variableName);
$this->name = 'var';
$this->variableName = $variableName; $this->variableName = $variableName;
$this->type = $type; $this->type = $type;
$this->description = $description; $this->description = $description;
} }
/** /**
...@@ -54,21 +59,18 @@ class Var_ extends TagWithType implements Factory\StaticMethod ...@@ -54,21 +59,18 @@ class Var_ extends TagWithType implements Factory\StaticMethod
Assert::stringNotEmpty($body); Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]); Assert::allNotNull([$typeResolver, $descriptionFactory]);
list($firstPart, $body) = self::extractTypeFromBody($body); $parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE); $type = null;
$type = null;
$variableName = ''; $variableName = '';
// if the first item that is encountered is not a variable; it is a type // if the first item that is encountered is not a variable; it is a type
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) { if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) {
$type = $typeResolver->resolve($firstPart, $context); $type = $typeResolver->resolve(array_shift($parts), $context);
} else { array_shift($parts);
// first part is not a type; we should prepend it to the parts array for further processing
array_unshift($parts, $firstPart);
} }
// if the next item starts with a $ or ...$ it must be the variable name // 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] === '$')) { if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] == '$')) {
$variableName = array_shift($parts); $variableName = array_shift($parts);
array_shift($parts); array_shift($parts);
...@@ -93,6 +95,16 @@ class Var_ extends TagWithType implements Factory\StaticMethod ...@@ -93,6 +95,16 @@ class Var_ extends TagWithType implements Factory\StaticMethod
} }
/** /**
* Returns the variable's type or null if unknown.
*
* @return Type|null
*/
public function getType()
{
return $this->type;
}
/**
* Returns a string representation for this tag. * Returns a string representation for this tag.
* *
* @return string * @return string
...@@ -100,7 +112,7 @@ class Var_ extends TagWithType implements Factory\StaticMethod ...@@ -100,7 +112,7 @@ class Var_ extends TagWithType implements Factory\StaticMethod
public function __toString() public function __toString()
{ {
return ($this->type ? $this->type . ' ' : '') return ($this->type ? $this->type . ' ' : '')
. (empty($this->variableName) ? null : ('$' . $this->variableName)) . '$' . $this->variableName
. ($this->description ? ' ' . $this->description : ''); . ($this->description ? ' ' . $this->description : '');
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment