diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 281756f..650506f 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -85,7 +85,9 @@ final class Param extends TagWithType implements Factory\StaticMethod // if the next item starts with a $ or ...$ or &$ or &...$ it must be the variable name if (isset($parts[0]) && self::strStartsWithVariable($parts[0])) { $variableName = array_shift($parts); - array_shift($parts); + if ($type) { + array_shift($parts); + } Assert::notNull($variableName); @@ -141,8 +143,8 @@ final class Param extends TagWithType implements Factory\StaticMethod return ($this->type ? $this->type . ' ' : '') . ($this->isReference() ? '&' : '') . ($this->isVariadic() ? '...' : '') - . ($this->variableName !== null ? '$' . $this->variableName : '') - . ($this->description ? ' ' . $this->description : ''); + . ($this->variableName ? '$' . $this->variableName : '') + . ($this->description ? ($this->variableName ? ' ' : '') . $this->description : ''); } private static function strStartsWithVariable(string $str) : bool diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php index d8b83b6..e358d98 100644 --- a/src/DocBlock/Tags/Property.php +++ b/src/DocBlock/Tags/Property.php @@ -68,10 +68,12 @@ final class Property extends TagWithType implements Factory\StaticMethod 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 $ it must be the variable name if (isset($parts[0]) && strpos($parts[0], '$') === 0) { $variableName = array_shift($parts); - array_shift($parts); + if ($type) { + array_shift($parts); + } Assert::notNull($variableName); @@ -98,6 +100,6 @@ final class Property extends TagWithType implements Factory\StaticMethod { return ($this->type ? $this->type . ' ' : '') . ($this->variableName ? '$' . $this->variableName : '') - . ($this->description ? ' ' . $this->description : ''); + . ($this->description ? ($this->variableName ? ' ' : '') . $this->description : ''); } } diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php index 087803c..6118d32 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -71,7 +71,9 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod // if the next item starts with a $ or ...$ it must be the variable name if (isset($parts[0]) && strpos($parts[0], '$') === 0) { $variableName = array_shift($parts); - array_shift($parts); + if ($type) { + array_shift($parts); + } Assert::notNull($variableName); @@ -98,6 +100,6 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod { return ($this->type ? $this->type . ' ' : '') . ($this->variableName ? '$' . $this->variableName : '') - . ($this->description ? ' ' . $this->description : ''); + . ($this->description ? ($this->variableName ? ' ' : '') . $this->description : ''); } } diff --git a/src/DocBlock/Tags/PropertyWrite.php b/src/DocBlock/Tags/PropertyWrite.php index 176b63d..d1b5a4e 100644 --- a/src/DocBlock/Tags/PropertyWrite.php +++ b/src/DocBlock/Tags/PropertyWrite.php @@ -71,7 +71,9 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod // if the next item starts with a $ or ...$ it must be the variable name if (isset($parts[0]) && strpos($parts[0], '$') === 0) { $variableName = array_shift($parts); - array_shift($parts); + if ($type) { + array_shift($parts); + } Assert::notNull($variableName); @@ -98,6 +100,6 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod { return ($this->type ? $this->type . ' ' : '') . ($this->variableName ? '$' . $this->variableName : '') - . ($this->description ? ' ' . $this->description : ''); + . ($this->description ? ($this->variableName ? ' ' : '') . $this->description : ''); } } diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php index ac1c438..f939a25 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -72,7 +72,9 @@ final class Var_ extends TagWithType implements Factory\StaticMethod // if the next item starts with a $ or ...$ it must be the variable name if (isset($parts[0]) && strpos($parts[0], '$') === 0) { $variableName = array_shift($parts); - array_shift($parts); + if ($type) { + array_shift($parts); + } Assert::notNull($variableName); @@ -98,7 +100,7 @@ final class Var_ extends TagWithType implements Factory\StaticMethod public function __toString() : string { return ($this->type ? $this->type . ' ' : '') - . (empty($this->variableName) ? '' : '$' . $this->variableName) - . ($this->description ? ' ' . $this->description : ''); + . ($this->variableName ? '$' . $this->variableName : '') + . ($this->description ? ($this->variableName ? ' ' : '') . $this->description : ''); } } diff --git a/tests/unit/DocBlock/Tags/ParamTest.php b/tests/unit/DocBlock/Tags/ParamTest.php index 246b57e..99a84da 100644 --- a/tests/unit/DocBlock/Tags/ParamTest.php +++ b/tests/unit/DocBlock/Tags/ParamTest.php @@ -16,8 +16,11 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; +use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -270,6 +273,128 @@ class ParamTest extends TestCase $this->assertSame($description, $fixture->getDescription()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithReferenceWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Param::create( + '&$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('&$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertFalse($fixture->isVariadic()); + $this->assertTrue($fixture->isReference()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithVariadicReferenceWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Param::create( + '&...$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('&...$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertTrue($fixture->isVariadic()); + $this->assertTrue($fixture->isReference()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Param::create( + '$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertFalse($fixture->isVariadic()); + $this->assertFalse($fixture->isReference()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Param::create( + 'int My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('int My Description', (string) $fixture); + $this->assertSame('', $fixture->getVariableName()); + $this->assertInstanceOf(Integer::class, $fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: * @uses \phpDocumentor\Reflection\TypeResolver diff --git a/tests/unit/DocBlock/Tags/PropertyReadTest.php b/tests/unit/DocBlock/Tags/PropertyReadTest.php index 901b090..d2b2ee8 100644 --- a/tests/unit/DocBlock/Tags/PropertyReadTest.php +++ b/tests/unit/DocBlock/Tags/PropertyReadTest.php @@ -16,8 +16,11 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; +use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -169,6 +172,64 @@ class PropertyReadTest extends TestCase $this->assertSame($description, $fixture->getDescription()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = PropertyRead::create( + '$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = PropertyRead::create( + 'int My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('int My Description', (string) $fixture); + $this->assertSame('', $fixture->getVariableName()); + $this->assertInstanceOf(Integer::class, $fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyRead:: * @uses \phpDocumentor\Reflection\TypeResolver diff --git a/tests/unit/DocBlock/Tags/PropertyTest.php b/tests/unit/DocBlock/Tags/PropertyTest.php index ec0e7fc..bf5258b 100644 --- a/tests/unit/DocBlock/Tags/PropertyTest.php +++ b/tests/unit/DocBlock/Tags/PropertyTest.php @@ -16,8 +16,11 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; +use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -164,6 +167,64 @@ class PropertyTest extends TestCase $this->assertSame($description, $fixture->getDescription()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Property::create( + '$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Property::create( + 'int My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('int My Description', (string) $fixture); + $this->assertSame('', $fixture->getVariableName()); + $this->assertInstanceOf(Integer::class, $fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Property:: * @uses \phpDocumentor\Reflection\TypeResolver diff --git a/tests/unit/DocBlock/Tags/PropertyWriteTest.php b/tests/unit/DocBlock/Tags/PropertyWriteTest.php index 1c6124c..e25b360 100644 --- a/tests/unit/DocBlock/Tags/PropertyWriteTest.php +++ b/tests/unit/DocBlock/Tags/PropertyWriteTest.php @@ -16,8 +16,11 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; +use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -169,6 +172,64 @@ class PropertyWriteTest extends TestCase $this->assertSame($description, $fixture->getDescription()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = PropertyWrite::create( + '$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = PropertyWrite::create( + 'int My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('int My Description', (string) $fixture); + $this->assertSame('', $fixture->getVariableName()); + $this->assertInstanceOf(Integer::class, $fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite:: * @uses \phpDocumentor\Reflection\TypeResolver diff --git a/tests/unit/DocBlock/Tags/VarTest.php b/tests/unit/DocBlock/Tags/VarTest.php index 409263e..4a8235a 100644 --- a/tests/unit/DocBlock/Tags/VarTest.php +++ b/tests/unit/DocBlock/Tags/VarTest.php @@ -16,8 +16,11 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; +use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -176,6 +179,64 @@ class VarTest extends TestCase $this->assertSame($description, $fixture->getDescription()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Var_::create( + '$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Var_::create( + 'int My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('int My Description', (string) $fixture); + $this->assertSame('', $fixture->getVariableName()); + $this->assertInstanceOf(Integer::class, $fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_:: * @uses \phpDocumentor\Reflection\TypeResolver