mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Fix tests and linting errors after merging in release 4.x
This commit is contained in:
@@ -21,8 +21,10 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use Webmozart\Assert\Assert;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
use function array_shift;
|
||||
use function array_unshift;
|
||||
use function implode;
|
||||
use function preg_split;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
|
||||
@@ -63,7 +65,8 @@ final class Param extends TagWithType implements Factory\StaticMethod
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
list($firstPart, $body) = self::extractTypeFromBody($body);
|
||||
[$firstPart, $body] = self::extractTypeFromBody($body);
|
||||
|
||||
$type = null;
|
||||
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$variableName = '';
|
||||
|
||||
@@ -21,8 +21,10 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use Webmozart\Assert\Assert;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
use function array_shift;
|
||||
use function array_unshift;
|
||||
use function implode;
|
||||
use function preg_split;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
|
||||
@@ -57,7 +59,7 @@ final class Property extends TagWithType implements Factory\StaticMethod
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
list($firstPart, $body) = self::extractTypeFromBody($body);
|
||||
[$firstPart, $body] = self::extractTypeFromBody($body);
|
||||
$type = null;
|
||||
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$variableName = '';
|
||||
|
||||
@@ -21,8 +21,10 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use Webmozart\Assert\Assert;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
use function array_shift;
|
||||
use function array_unshift;
|
||||
use function implode;
|
||||
use function preg_split;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
|
||||
@@ -57,7 +59,7 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
list($firstPart, $body) = self::extractTypeFromBody($body);
|
||||
[$firstPart, $body] = self::extractTypeFromBody($body);
|
||||
$type = null;
|
||||
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$variableName = '';
|
||||
|
||||
@@ -21,6 +21,7 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use Webmozart\Assert\Assert;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
use function array_shift;
|
||||
use function array_unshift;
|
||||
use function implode;
|
||||
use function preg_split;
|
||||
use function strlen;
|
||||
@@ -58,7 +59,7 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
list($firstPart, $body) = self::extractTypeFromBody($body);
|
||||
[$firstPart, $body] = self::extractTypeFromBody($body);
|
||||
$type = null;
|
||||
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$variableName = '';
|
||||
|
||||
@@ -19,14 +19,13 @@ use phpDocumentor\Reflection\Type;
|
||||
use phpDocumentor\Reflection\TypeResolver;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use Webmozart\Assert\Assert;
|
||||
use function preg_split;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@}return tag in a Docblock.
|
||||
*/
|
||||
final class Return_ extends TagWithType implements Factory\StaticMethod
|
||||
{
|
||||
public function __construct(Type $type, Description $description = null)
|
||||
public function __construct(Type $type, ?Description $description = null)
|
||||
{
|
||||
$this->name = 'return';
|
||||
$this->type = $type;
|
||||
@@ -45,7 +44,7 @@ final class Return_ extends TagWithType implements Factory\StaticMethod
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
list($type, $description) = self::extractTypeFromBody($body);
|
||||
[$type, $description] = self::extractTypeFromBody($body);
|
||||
|
||||
$type = $typeResolver->resolve($type, $context);
|
||||
$description = $descriptionFactory->create($description, $context);
|
||||
@@ -53,8 +52,8 @@ final class Return_ extends TagWithType implements Factory\StaticMethod
|
||||
return new static($type, $description);
|
||||
}
|
||||
|
||||
public function __toString() :string
|
||||
public function __toString() : string
|
||||
{
|
||||
return $this->type . ' ' . (string) $this->description;
|
||||
return ($this->type ?: 'mixed') . ' ' . (string) $this->description;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,30 +8,33 @@ declare(strict_types=1);
|
||||
* 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<[email protected]>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use phpDocumentor\Reflection\Type;
|
||||
use function in_array;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
use function trim;
|
||||
|
||||
abstract class TagWithType extends BaseTag
|
||||
{
|
||||
/** @var Type */
|
||||
/** @var ?Type */
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Returns the type section of the variable.
|
||||
*
|
||||
* @return Type
|
||||
*/
|
||||
public function getType()
|
||||
public function getType() : ?Type
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
protected static function extractTypeFromBody(string $body) : array
|
||||
{
|
||||
$type = '';
|
||||
@@ -46,9 +49,12 @@ abstract class TagWithType extends BaseTag
|
||||
$type .= $character;
|
||||
if (in_array($character, ['<', '(', '[', '{'])) {
|
||||
$nestingLevel++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($character, ['>', ')', ']', '}'])) {
|
||||
$nestingLevel--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,14 +19,13 @@ use phpDocumentor\Reflection\Type;
|
||||
use phpDocumentor\Reflection\TypeResolver;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use Webmozart\Assert\Assert;
|
||||
use function preg_split;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@}throws tag in a Docblock.
|
||||
*/
|
||||
final class Throws extends TagWithType implements Factory\StaticMethod
|
||||
{
|
||||
public function __construct(Type $type, Description $description = null)
|
||||
public function __construct(Type $type, ?Description $description = null)
|
||||
{
|
||||
$this->name = 'throws';
|
||||
$this->type = $type;
|
||||
@@ -45,7 +44,7 @@ final class Throws extends TagWithType implements Factory\StaticMethod
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
list($type, $description) = self::extractTypeFromBody($body);
|
||||
[$type, $description] = self::extractTypeFromBody($body);
|
||||
|
||||
$type = $typeResolver->resolve($type, $context);
|
||||
$description = $descriptionFactory->create($description, $context);
|
||||
|
||||
@@ -21,8 +21,10 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use Webmozart\Assert\Assert;
|
||||
use const PREG_SPLIT_DELIM_CAPTURE;
|
||||
use function array_shift;
|
||||
use function array_unshift;
|
||||
use function implode;
|
||||
use function preg_split;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
|
||||
@@ -57,7 +59,8 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
list($firstPart, $body) = self::extractTypeFromBody($body);
|
||||
[$firstPart, $body] = self::extractTypeFromBody($body);
|
||||
|
||||
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$type = null;
|
||||
$variableName = '';
|
||||
|
||||
@@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Mockery as m;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
@@ -158,19 +159,17 @@ class ReturnTest extends TestCase
|
||||
* This test tests whether an error occurs demonstrating that the braces were taken into account; this test is still
|
||||
* expected to produce an exception because the TypeResolver does not support generics.
|
||||
*
|
||||
* @covers ::create
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_::<public>
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||
* @uses \phpDocumentor\Reflection\TypeResolver
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||
* @uses \phpDocumentor\Reflection\Types\String_
|
||||
* @uses \phpDocumentor\Reflection\Types\Context
|
||||
*
|
||||
* @covers ::create
|
||||
*/
|
||||
public function testFactoryMethodWithGenericWithSpace()
|
||||
public function testFactoryMethodWithGenericWithSpace() : void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('"\array<string, string>" is not a valid Fqsen.');
|
||||
|
||||
$descriptionFactory = m::mock(DescriptionFactory::class);
|
||||
$resolver = new TypeResolver();
|
||||
$context = new Context('');
|
||||
@@ -180,23 +179,28 @@ class ReturnTest extends TestCase
|
||||
->with('My Description', $context)
|
||||
->andReturn($description);
|
||||
|
||||
Return_::create('array<string, string> My Description', $resolver, $descriptionFactory, $context);
|
||||
$fixture = Return_::create('array<string, string> My Description', $resolver, $descriptionFactory, $context);
|
||||
|
||||
$this->assertSame('array<string,string> My Description', (string) $fixture);
|
||||
$this->assertEquals('array<string,string>', $fixture->getType());
|
||||
$this->assertSame($description, $fixture->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see self::testFactoryMethodWithGenericWithSpace()
|
||||
*
|
||||
* @covers ::create
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_::<public>
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||
* @uses \phpDocumentor\Reflection\TypeResolver
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||
* @uses \phpDocumentor\Reflection\Types\String_
|
||||
* @uses \phpDocumentor\Reflection\Types\Context
|
||||
*
|
||||
* @covers ::create
|
||||
*/
|
||||
public function testFactoryMethodWithGenericWithSpaceAndAddedEmojisToVerifyMultiByteBehaviour()
|
||||
public function testFactoryMethodWithGenericWithSpaceAndAddedEmojisToVerifyMultiByteBehaviour() : void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->markTestSkipped('A bug in the TypeResolver breaks this test');
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('"\array😁<string,😁 😁string>" is not a valid Fqsen.');
|
||||
|
||||
$descriptionFactory = m::mock(DescriptionFactory::class);
|
||||
@@ -212,15 +216,16 @@ class ReturnTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::create
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_::<public>
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||
* @uses \phpDocumentor\Reflection\TypeResolver
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||
* @uses \phpDocumentor\Reflection\Types\String_
|
||||
* @uses \phpDocumentor\Reflection\Types\Context
|
||||
*
|
||||
* @covers ::create
|
||||
*/
|
||||
public function testFactoryMethodWithEmojisToVerifyMultiByteBehaviour()
|
||||
public function testFactoryMethodWithEmojisToVerifyMultiByteBehaviour() : void
|
||||
{
|
||||
$descriptionFactory = m::mock(DescriptionFactory::class);
|
||||
$resolver = new TypeResolver();
|
||||
|
||||
@@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Mockery as m;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
@@ -158,19 +159,17 @@ class ThrowsTest extends TestCase
|
||||
* This test tests whether an error occurs demonstrating that the braces were taken into account; this test is still
|
||||
* expected to produce an exception because the TypeResolver does not support generics.
|
||||
*
|
||||
* @covers ::create
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Throws::<public>
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||
* @uses \phpDocumentor\Reflection\TypeResolver
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||
* @uses \phpDocumentor\Reflection\Types\String_
|
||||
* @uses \phpDocumentor\Reflection\Types\Context
|
||||
*
|
||||
* @covers ::create
|
||||
*/
|
||||
public function testFactoryMethodWithGenericWithSpace()
|
||||
public function testFactoryMethodWithGenericWithSpace() : void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('"\array<string, string>" is not a valid Fqsen.');
|
||||
|
||||
$descriptionFactory = m::mock(DescriptionFactory::class);
|
||||
$resolver = new TypeResolver();
|
||||
$context = new Context('');
|
||||
@@ -180,23 +179,28 @@ class ThrowsTest extends TestCase
|
||||
->with('My Description', $context)
|
||||
->andReturn($description);
|
||||
|
||||
Throws::create('array<string, string> My Description', $resolver, $descriptionFactory, $context);
|
||||
$fixture = Throws::create('array<string, string> My Description', $resolver, $descriptionFactory, $context);
|
||||
|
||||
$this->assertSame('array<string,string> My Description', (string) $fixture);
|
||||
$this->assertEquals('array<string,string>', $fixture->getType());
|
||||
$this->assertSame($description, $fixture->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see self::testFactoryMethodWithGenericWithSpace()
|
||||
*
|
||||
* @covers ::create
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Throws::<public>
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||
* @uses \phpDocumentor\Reflection\TypeResolver
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||
* @uses \phpDocumentor\Reflection\Types\String_
|
||||
* @uses \phpDocumentor\Reflection\Types\Context
|
||||
*
|
||||
* @covers ::create
|
||||
*/
|
||||
public function testFactoryMethodWithGenericWithSpaceAndAddedEmojisToVerifyMultiByteBehaviour()
|
||||
public function testFactoryMethodWithGenericWithSpaceAndAddedEmojisToVerifyMultiByteBehaviour() : void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->markTestSkipped('A bug in the TypeResolver breaks this test');
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('"\array😁<string,😁 😁string>" is not a valid Fqsen.');
|
||||
|
||||
$descriptionFactory = m::mock(DescriptionFactory::class);
|
||||
@@ -212,15 +216,16 @@ class ThrowsTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::create
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Throws::<public>
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||
* @uses \phpDocumentor\Reflection\TypeResolver
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||
* @uses \phpDocumentor\Reflection\Types\String_
|
||||
* @uses \phpDocumentor\Reflection\Types\Context
|
||||
*
|
||||
* @covers ::create
|
||||
*/
|
||||
public function testFactoryMethodWithEmojisToVerifyMultiByteBehaviour()
|
||||
public function testFactoryMethodWithEmojisToVerifyMultiByteBehaviour() : void
|
||||
{
|
||||
$descriptionFactory = m::mock(DescriptionFactory::class);
|
||||
$resolver = new TypeResolver();
|
||||
|
||||
Reference in New Issue
Block a user