Add braces support to Property, Property-Read, Property-Write and Var

This commit is contained in:
Mike van Riel
2019-12-27 21:07:05 +01:00
parent bb19583948
commit 1a5d9a2dbc
4 changed files with 50 additions and 87 deletions
+11 -20
View File
@@ -29,19 +29,16 @@ use function substr;
/** /**
* Reflection class for a {@}property tag in a Docblock. * Reflection class for a {@}property tag in a Docblock.
*/ */
final class Property extends BaseTag implements Factory\StaticMethod final class Property extends TagWithType implements Factory\StaticMethod
{ {
/** @var string */
protected $name = 'property';
/** @var Type|null */
private $type;
/** @var string|null */ /** @var string|null */
protected $variableName = ''; protected $variableName = '';
public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null)
{ {
Assert::string($variableName);
$this->name = 'property';
$this->variableName = $variableName; $this->variableName = $variableName;
$this->type = $type; $this->type = $type;
$this->description = $description; $this->description = $description;
@@ -60,15 +57,17 @@ final class Property extends BaseTag implements Factory\StaticMethod
Assert::notNull($typeResolver); Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory); Assert::notNull($descriptionFactory);
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); list($firstPart, $body) = self::extractTypeFromBody($body);
Assert::isArray($parts);
$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 (isset($parts[0]) && ($parts[0] !== '') && ($parts[0][0] !== '$')) { if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
$type = $typeResolver->resolve(array_shift($parts), $context); $type = $typeResolver->resolve($firstPart, $context);
array_shift($parts); } else {
// 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
@@ -94,14 +93,6 @@ final class Property extends BaseTag implements Factory\StaticMethod
return $this->variableName; return $this->variableName;
} }
/**
* Returns the variable's type or null if unknown.
*/
public function getType() : ?Type
{
return $this->type;
}
/** /**
* Returns a string representation for this tag. * Returns a string representation for this tag.
*/ */
+11 -20
View File
@@ -29,19 +29,16 @@ use function substr;
/** /**
* Reflection class for a {@}property-read tag in a Docblock. * Reflection class for a {@}property-read tag in a Docblock.
*/ */
final class PropertyRead extends BaseTag implements Factory\StaticMethod final class PropertyRead extends TagWithType implements Factory\StaticMethod
{ {
/** @var string */
protected $name = 'property-read';
/** @var Type|null */
private $type;
/** @var string|null */ /** @var string|null */
protected $variableName = ''; protected $variableName = '';
public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null)
{ {
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;
@@ -60,15 +57,17 @@ final class PropertyRead extends BaseTag implements Factory\StaticMethod
Assert::notNull($typeResolver); Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory); Assert::notNull($descriptionFactory);
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); list($firstPart, $body) = self::extractTypeFromBody($body);
Assert::isArray($parts);
$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 (isset($parts[0]) && ($parts[0] !== '') && ($parts[0][0] !== '$')) { if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
$type = $typeResolver->resolve(array_shift($parts), $context); $type = $typeResolver->resolve($firstPart, $context);
array_shift($parts); } else {
// 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
@@ -94,14 +93,6 @@ final class PropertyRead extends BaseTag implements Factory\StaticMethod
return $this->variableName; return $this->variableName;
} }
/**
* Returns the variable's type or null if unknown.
*/
public function getType() : ?Type
{
return $this->type;
}
/** /**
* Returns a string representation for this tag. * Returns a string representation for this tag.
*/ */
+11 -20
View File
@@ -30,19 +30,16 @@ use function substr;
/** /**
* Reflection class for a {@}property-write tag in a Docblock. * Reflection class for a {@}property-write tag in a Docblock.
*/ */
final class PropertyWrite extends BaseTag implements Factory\StaticMethod final class PropertyWrite extends TagWithType implements Factory\StaticMethod
{ {
/** @var string */ /** @var string */
protected $name = 'property-write';
/** @var Type|null */
private $type;
/** @var string|null */
protected $variableName = ''; protected $variableName = '';
public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null)
{ {
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;
@@ -61,15 +58,17 @@ final class PropertyWrite extends BaseTag implements Factory\StaticMethod
Assert::notNull($typeResolver); Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory); Assert::notNull($descriptionFactory);
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); list($firstPart, $body) = self::extractTypeFromBody($body);
Assert::isArray($parts);
$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 (isset($parts[0]) && ($parts[0] !== '') && ($parts[0][0] !== '$')) { if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
$type = $typeResolver->resolve(array_shift($parts), $context); $type = $typeResolver->resolve($firstPart, $context);
array_shift($parts); } else {
// 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
@@ -95,14 +94,6 @@ final class PropertyWrite extends BaseTag implements Factory\StaticMethod
return $this->variableName; return $this->variableName;
} }
/**
* Returns the variable's type or null if unknown.
*/
public function getType() : ?Type
{
return $this->type;
}
/** /**
* Returns a string representation for this tag. * Returns a string representation for this tag.
*/ */
+11 -21
View File
@@ -29,19 +29,16 @@ use function substr;
/** /**
* Reflection class for a {@}var tag in a Docblock. * Reflection class for a {@}var tag in a Docblock.
*/ */
final class Var_ extends BaseTag implements Factory\StaticMethod final class Var_ extends TagWithType implements Factory\StaticMethod
{ {
/** @var string */
protected $name = 'var';
/** @var Type|null */
private $type;
/** @var string|null */ /** @var string|null */
protected $variableName = ''; protected $variableName = '';
public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null) public function __construct(?string $variableName, ?Type $type = null, ?Description $description = null)
{ {
Assert::string($variableName);
$this->name = 'var';
$this->variableName = $variableName; $this->variableName = $variableName;
$this->type = $type; $this->type = $type;
$this->description = $description; $this->description = $description;
@@ -60,16 +57,17 @@ final class Var_ extends BaseTag implements Factory\StaticMethod
Assert::notNull($typeResolver); Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory); Assert::notNull($descriptionFactory);
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE); list($firstPart, $body) = self::extractTypeFromBody($body);
Assert::isArray($parts); $parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
Assert::allString($parts);
$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 (isset($parts[0]) && ($parts[0] !== '') && ($parts[0][0] !== '$')) { if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
$type = $typeResolver->resolve(array_shift($parts), $context); $type = $typeResolver->resolve($firstPart, $context);
array_shift($parts); } else {
// 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
@@ -95,14 +93,6 @@ final class Var_ extends BaseTag implements Factory\StaticMethod
return $this->variableName; return $this->variableName;
} }
/**
* Returns the variable's type or null if unknown.
*/
public function getType() : ?Type
{
return $this->type;
}
/** /**
* Returns a string representation for this tag. * Returns a string representation for this tag.
*/ */