mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 18:13:13 +00:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bba116ba9d | ||
|
|
23fa082874 | ||
|
|
e6811e927f | ||
|
|
05596d7626 | ||
|
|
e5e172728c | ||
|
|
9a2f0eb8ba | ||
|
|
bf44b757fe | ||
|
|
e6526132ee |
+6
-7
@@ -1,14 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<phpunit colors="true" strict="true" bootstrap="vendor/autoload.php">
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<coverage>
|
||||
<include>
|
||||
<directory suffix=".php">./src/</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="phpDocumentor\Reflection\DocBlock">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">./src/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
||||
@@ -109,7 +109,7 @@ class Description implements \Reflector
|
||||
)
|
||||
\}/Sux',
|
||||
$this->contents,
|
||||
null,
|
||||
-1,
|
||||
PREG_SPLIT_DELIM_CAPTURE
|
||||
);
|
||||
|
||||
|
||||
@@ -95,7 +95,9 @@ class Tag implements \Reflector
|
||||
'var'
|
||||
=> '\Barryvdh\Reflection\DocBlock\Tag\VarTag',
|
||||
'version'
|
||||
=> '\Barryvdh\Reflection\DocBlock\Tag\VersionTag'
|
||||
=> '\Barryvdh\Reflection\DocBlock\Tag\VersionTag',
|
||||
'SuppressWarnings'
|
||||
=> '\Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag'
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,12 +46,37 @@ class ParamTag extends ReturnTag
|
||||
public function setContent($content)
|
||||
{
|
||||
Tag::setContent($content);
|
||||
$parts = preg_split(
|
||||
'/(\s+)/Su',
|
||||
$this->description,
|
||||
3,
|
||||
PREG_SPLIT_DELIM_CAPTURE
|
||||
);
|
||||
|
||||
$parts = [];
|
||||
$rest = $this->description;
|
||||
|
||||
// parsing generics and closures to detect types
|
||||
for($pos = 0, $stacks = []; $pos < strlen($rest); $pos++) {
|
||||
$char = $rest[$pos];
|
||||
|
||||
if($char === '<') {
|
||||
array_unshift($stacks, $char);
|
||||
}
|
||||
if($char === '(') {
|
||||
array_unshift($stacks, $char);
|
||||
}
|
||||
if($char === '>' && isset($stacks[0]) && $stacks[0] === '<') {
|
||||
array_shift($stacks);
|
||||
}
|
||||
if($char === ')' && isset($stacks[0]) && $stacks[0] === '(') {
|
||||
array_shift($stacks);
|
||||
}
|
||||
|
||||
if(!$stacks && preg_match('/\A(\s+)(.*)/su', substr($rest, $pos), $matches)) {
|
||||
$parts[0] = substr($rest, 0, $pos);
|
||||
$parts[1] = $matches[1];
|
||||
$rest = $matches[2];
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
array_push($parts, ...preg_split('/(\s+)/u', $rest, 2, PREG_SPLIT_DELIM_CAPTURE));
|
||||
|
||||
// if the first item that is encountered is not a variable; it is a type
|
||||
if (isset($parts[0])
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5.3
|
||||
*
|
||||
* @author Andrew Smith <[email protected]>
|
||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||
|
||||
use Barryvdh\Reflection\DocBlock\Tag;
|
||||
|
||||
/**
|
||||
* Reflection class for a @SuppressWarnings tag in a Docblock.
|
||||
*
|
||||
* @author Andrew Smith <[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class SuppressWarningsTag extends Tag
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return "@{$this->getName()}{$this->getContent()}";
|
||||
}
|
||||
}
|
||||
@@ -145,9 +145,9 @@ class Collection extends \ArrayObject
|
||||
$type_parts[] = $curr_type;
|
||||
$curr_type = '';
|
||||
} else {
|
||||
if ($char === '<') {
|
||||
if ($char === '<' || $char === '(') {
|
||||
$nest_level++;
|
||||
} else if ($char === '>') {
|
||||
} else if ($char === '>' || $char === ')') {
|
||||
$nest_level--;
|
||||
}
|
||||
|
||||
@@ -189,6 +189,10 @@ class Collection extends \ArrayObject
|
||||
return $type;
|
||||
}
|
||||
|
||||
if($type[0] === '(') {
|
||||
return $type;
|
||||
}
|
||||
|
||||
if ($this->isTypeAnArray($type)) {
|
||||
return $this->expand(substr($type, 0, -2)) . self::OPERATOR_ARRAY;
|
||||
}
|
||||
@@ -210,11 +214,7 @@ class Collection extends \ArrayObject
|
||||
if ('' !== $namespace) {
|
||||
$namespace .= self::OPERATOR_NAMESPACE;
|
||||
}
|
||||
$with_name_space = self::OPERATOR_NAMESPACE . $namespace . $type;
|
||||
if($this->shouldBeAbsolute($with_name_space)){
|
||||
return $with_name_space;
|
||||
}
|
||||
return $type;
|
||||
return self::OPERATOR_NAMESPACE . $namespace . $type;
|
||||
}
|
||||
|
||||
if (strpos($type_parts[0], '::')) {
|
||||
|
||||
@@ -114,7 +114,75 @@ class ParamTagTest extends TestCase
|
||||
array('int'),
|
||||
'$bob',
|
||||
"Type on a new line"
|
||||
)
|
||||
),
|
||||
|
||||
// generic array
|
||||
array(
|
||||
'param',
|
||||
'array<int, string> $names',
|
||||
'array<int, string>',
|
||||
array('array<int, string>'),
|
||||
'$names',
|
||||
''
|
||||
),
|
||||
|
||||
// nested generics
|
||||
array(
|
||||
'param',
|
||||
'array<int, array<string, mixed>> $arrays',
|
||||
'array<int, array<string, mixed>>',
|
||||
array('array<int, array<string, mixed>>'),
|
||||
'$arrays',
|
||||
''
|
||||
),
|
||||
|
||||
// closure
|
||||
array(
|
||||
'param',
|
||||
'(\Closure(int, string): bool) $callback',
|
||||
'(\Closure(int, string): bool)',
|
||||
array('(\Closure(int, string): bool)'),
|
||||
'$callback',
|
||||
''
|
||||
),
|
||||
|
||||
// generic array in closure
|
||||
array(
|
||||
'param',
|
||||
'(\Closure(array<int, string>): bool) $callback',
|
||||
'(\Closure(array<int, string>): bool)',
|
||||
array('(\Closure(array<int, string>): bool)'),
|
||||
'$callback',
|
||||
''
|
||||
),
|
||||
|
||||
// union types in closure
|
||||
array(
|
||||
'param',
|
||||
'(\Closure(int|string): bool)|bool $callback',
|
||||
'(\Closure(int|string): bool)|bool',
|
||||
array('(\Closure(int|string): bool)', 'bool'),
|
||||
'$callback',
|
||||
''
|
||||
),
|
||||
|
||||
// example from Laravel Framework - Eloquent Builder)
|
||||
array(
|
||||
'param',
|
||||
'array<array-key, array|(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string>|string $relations',
|
||||
'array<array-key, array|(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string>|string',
|
||||
array('array<array-key, array|(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string>', 'string'),
|
||||
'$relations',
|
||||
''
|
||||
),
|
||||
array(
|
||||
'param',
|
||||
'(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string|null $callback',
|
||||
'(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string|null',
|
||||
array('(\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)', 'string', 'null'),
|
||||
'$callback',
|
||||
''
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor SuppressWarnings Tag Test
|
||||
*
|
||||
* PHP version 5.3
|
||||
*
|
||||
* @author Andrew Smith <[email protected]>
|
||||
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace Barryvdh\Reflection\DocBlock\Tag;
|
||||
|
||||
use PHPUnit\Framework\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for \Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag
|
||||
*
|
||||
* @author Andrew Smith <[email protected]>
|
||||
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class SuppressWarningsTagTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test that the \Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag can
|
||||
* understand the @SuppressWarnings doc block.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $content
|
||||
* @param string $exType
|
||||
* @param string $exVariable
|
||||
* @param string $exDescription
|
||||
*
|
||||
* @covers \Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag
|
||||
* @dataProvider provideDataForConstuctor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructorParesInputsIntoCorrectFields(
|
||||
$type,
|
||||
$content,
|
||||
$description
|
||||
) {
|
||||
$tag = new SuppressWarningsTag($type, $content);
|
||||
|
||||
$this->assertEquals($type, $tag->getName());
|
||||
$this->assertEquals($description, $tag->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testConstructorParesInputsIntoCorrectFields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provideDataForConstuctor()
|
||||
{
|
||||
// $type, $content, $description
|
||||
return array(
|
||||
array(
|
||||
'SuppressWarnings',
|
||||
'SuppressWarnings(PHPMD)',
|
||||
'SuppressWarnings(PHPMD)',
|
||||
),
|
||||
array(
|
||||
'SuppressWarnings',
|
||||
'SuppressWarnings(PHPMD.TooManyMethods)',
|
||||
'SuppressWarnings(PHPMD.TooManyMethods)',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user