composer-update-patch
This commit is contained in:
@@ -129,9 +129,10 @@ class DescriptionFactory
|
||||
|
||||
//In order to allow "literal" inline tags, the otherwise invalid
|
||||
//sequence "{@}" is changed to "@", and "{}" is changed to "}".
|
||||
//"%" is escaped to "%%" because of vsprintf.
|
||||
//See unit tests for examples.
|
||||
for ($i = 0; $i < $count; $i += 2) {
|
||||
$tokens[$i] = str_replace(['{@}', '{}'], ['@', '}'], $tokens[$i]);
|
||||
$tokens[$i] = str_replace(['{@}', '{}', '%'], ['@', '}', '%%'], $tokens[$i]);
|
||||
}
|
||||
|
||||
return [implode('', $tokens), $tags];
|
||||
|
@@ -63,7 +63,10 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod
|
||||
|
||||
$matches = [];
|
||||
if (!preg_match('/^(' . self::REGEX_VECTOR . ')\s*(.+)?$/sux', $body, $matches)) {
|
||||
return null;
|
||||
return new static(
|
||||
null,
|
||||
null !== $descriptionFactory ? $descriptionFactory->create($body, $context) : null
|
||||
);
|
||||
}
|
||||
|
||||
return new static(
|
||||
|
@@ -127,7 +127,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
|
||||
if ('' !== $arguments) {
|
||||
$arguments = explode(',', $arguments);
|
||||
foreach($arguments as &$argument) {
|
||||
$argument = explode(' ', trim($argument));
|
||||
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
|
||||
if ($argument[0][0] === '$') {
|
||||
$argumentName = substr($argument[0], 1);
|
||||
$argumentType = new Void_();
|
||||
@@ -135,6 +135,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
|
||||
$argumentType = $typeResolver->resolve($argument[0], $context);
|
||||
$argumentName = '';
|
||||
if (isset($argument[1])) {
|
||||
$argument[1] = self::stripRestArg($argument[1]);
|
||||
$argumentName = substr($argument[1], 1);
|
||||
}
|
||||
}
|
||||
@@ -217,4 +218,13 @@ final class Method extends BaseTag implements Factory\StaticMethod
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
private static function stripRestArg($argument)
|
||||
{
|
||||
if (strpos($argument, '...') === 0) {
|
||||
$argument = trim(substr($argument, 3));
|
||||
}
|
||||
|
||||
return $argument;
|
||||
}
|
||||
}
|
||||
|
@@ -161,6 +161,6 @@ class DeprecatedTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testFactoryMethodReturnsNullIfBodyDoesNotMatchRegex()
|
||||
{
|
||||
$this->assertNull(Deprecated::create('dkhf<'));
|
||||
$this->assertEquals(new Deprecated(), Deprecated::create('dkhf<'));
|
||||
}
|
||||
}
|
||||
|
@@ -139,6 +139,33 @@ class MethodTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($expected, $fixture->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::create
|
||||
*/
|
||||
public function testRestArgumentIsParsedAsRegularArg()
|
||||
{
|
||||
$expected = [
|
||||
[ 'name' => 'arg1', 'type' => new Void_() ],
|
||||
[ 'name' => 'rest', 'type' => new Void_() ],
|
||||
[ 'name' => 'rest2', 'type' => new Array_() ],
|
||||
];
|
||||
|
||||
$descriptionFactory = m::mock(DescriptionFactory::class);
|
||||
$resolver = new TypeResolver();
|
||||
$context = new Context('');
|
||||
$description = new Description('');
|
||||
$descriptionFactory->shouldReceive('create')->with('', $context)->andReturn($description);
|
||||
|
||||
$fixture = Method::create(
|
||||
'void myMethod($arg1, ...$rest, array ... $rest2)',
|
||||
$resolver,
|
||||
$descriptionFactory,
|
||||
$context
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $fixture->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::getReturnType
|
||||
|
Reference in New Issue
Block a user