| Total Complexity | 11 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | final class Argument |
||
| 13 | { |
||
| 14 | private $name; |
||
| 15 | private $type; |
||
| 16 | private $optional = false; |
||
| 17 | private $default; |
||
| 18 | |||
| 19 | 71 | public function __construct(Name $name, Type $type) |
|
| 20 | { |
||
| 21 | 71 | $this->name = $name; |
|
| 22 | 71 | $this->type = $type; |
|
| 23 | 71 | } |
|
| 24 | |||
| 25 | 69 | public function name(): Name |
|
| 26 | { |
||
| 27 | 69 | return $this->name; |
|
| 28 | } |
||
| 29 | |||
| 30 | 15 | public function type(): Type |
|
| 31 | { |
||
| 32 | 15 | return $this->type; |
|
| 33 | } |
||
| 34 | |||
| 35 | 15 | public function makeOptional(): self |
|
| 36 | { |
||
| 37 | 15 | $self = clone $this; |
|
| 38 | 15 | $self->optional = true; |
|
| 39 | |||
| 40 | 15 | return $self; |
|
| 41 | } |
||
| 42 | |||
| 43 | 15 | public function defaultsTo(Name $name): self |
|
| 44 | { |
||
| 45 | 15 | $self = clone $this; |
|
| 46 | 15 | $self->default = $name; |
|
| 47 | |||
| 48 | 15 | return $self; |
|
| 49 | } |
||
| 50 | |||
| 51 | 53 | public function optional(): bool |
|
| 54 | } |
||
| 55 | |||
| 56 | 53 | public function hasDefault(): bool |
|
| 59 | } |
||
| 60 | |||
| 61 | 13 | public function default(): Name |
|
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param mixed $value |
||
| 68 | * |
||
| 69 | * @throws InvalidArgument |
||
| 70 | */ |
||
| 71 | 36 | public function validate($value): void |
|
| 72 | { |
||
| 73 | 36 | if (!$this->type->accepts($value)) { |
|
| 74 | 2 | throw new InvalidArgument((string) $this->name); |
|
| 75 | } |
||
| 76 | 35 | } |
|
| 77 | |||
| 78 | 6 | public function compile(): CompiledArgument |
|
| 81 | } |
||
| 82 | } |
||
| 83 |