| 1 |
<?php declare(strict_types = 1); |
| 2 |
|
| 3 |
namespace PHPStan\PhpDocParser\Ast\PhpDoc\Doctrine; |
| 4 |
|
| 5 |
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprNode; |
| 6 |
use PHPStan\PhpDocParser\Ast\Node; |
| 7 |
use PHPStan\PhpDocParser\Ast\NodeAttributes; |
| 8 |
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; |
| 9 |
|
| 10 |
/** |
| 11 |
* @phpstan-type ValueType = DoctrineAnnotation|IdentifierTypeNode|DoctrineArray|ConstExprNode |
| 12 |
*/ |
| 13 |
class DoctrineArgument implements Node |
| 14 |
{ |
| 15 |
|
| 16 |
use NodeAttributes; |
| 17 |
|
| 18 |
public ?IdentifierTypeNode $key = null; |
| 19 |
|
| 20 |
/** @var ValueType */ |
| 21 |
public $value; |
| 22 |
|
| 23 |
/** |
| 24 |
* @param ValueType $value |
| 25 |
*/ |
| 26 |
public function __construct(?IdentifierTypeNode $key, $value) |
| 27 |
{ |
| 28 |
$this->key = $key; |
| 29 |
$this->value = $value; |
| 30 |
} |
| 31 |
|
| 32 |
public function __toString(): string |
| 33 |
{ |
| 34 |
if ($this->key === null) { |
| 35 |
return (string) $this->value; |
| 36 |
} |
| 37 |
|
| 38 |
return $this->key . '=' . $this->value; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* @param array<string, mixed> $properties |
| 43 |
*/ |
| 44 |
public static function __set_state(array $properties): self |
| 45 |
{ |
| 46 |
$instance = new self($properties['key'], $properties['value']); |
| 47 |
if (isset($properties['attributes'])) { |
| 48 |
foreach ($properties['attributes'] as $key => $value) { |
| 49 |
$instance->setAttribute($key, $value); |
| 50 |
} |
| 51 |
} |
| 52 |
return $instance; |
| 53 |
} |
| 54 |
|
| 55 |
} |