You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if ($type['type'] === 'array') {
// handle the case of a single value
if ( ! is_array($values[$property])) {
$values[$property] = array($values[$property]);
}
// checks if the attribute has array type declaration, such as "array<string>"
if (isset($type['array_type'])) {
foreach ($values[$property] as $item) {
if (gettype($item) !== $type['array_type'] && !$item instanceof $type['array_type']) {
throw AnnotationException::attributeTypeError($property, $originalName, $this->context, 'either a(n) '.$type['array_type'].', or an array of '.$type['array_type'].'s', $item);
}
}
}
} elseif (gettype($values[$property]) !== $type['type'] && !$values[$property] instanceof $type['type']) {
throw AnnotationException::attributeTypeError($property, $originalName, $this->context, 'a(n) '.$type['value'], $values[$property]);
}
Assumes type annotation of value to be done like so:
@var string
However, you could do something like
@var null|string
Because the elseif() only does string comparisons, using the latter notation will always fail.
Here the @Encrypted is custom Annotation. I'll leave all options out of the scope but it's defined like so:
/**
* @Annotation
* @Target("PROPERTY")
*/
class Encrypted
{
/**
* @var string
*/
public $spices;
// getters/setters + other options
}
However, I would like to define the property like so:
/**
* @var null|string
*/
public $spices;
The first passes, the second fails because an assumption is done that the @var declaration always contains just one type.
P.s. - I've seen comments before about creating a test case, PR and PhpUnit tested code and such. If you have any docs on "how-to" all that, I'll give creating that a shot.
The text was updated successfully, but these errors were encountered:
annotations/lib/Doctrine/Common/Annotations/DocParser.php
Line 810 in 9419fd5
Line #810 is the
elseif (...)
lineAssumes type annotation of value to be done like so:
However, you could do something like
Because the
elseif()
only does string comparisons, using the latter notation will always fail.Small use case
Here the
@Encrypted
is custom Annotation. I'll leave all options out of the scope but it's defined like so:However, I would like to define the property like so:
The first passes, the second fails because an assumption is done that the
@var
declaration always contains just one type.P.s. - I've seen comments before about creating a test case, PR and PhpUnit tested code and such. If you have any docs on "how-to" all that, I'll give creating that a shot.
The text was updated successfully, but these errors were encountered: