| Total Complexity | 6 |
| Total Lines | 70 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 14 | class FullName extends ValueObject |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var Collection |
||
| 18 | */ |
||
| 19 | protected Collection $split; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Create a new instance of the value object. |
||
| 23 | * |
||
| 24 | * @param string|null $fullName |
||
| 25 | */ |
||
| 26 | 10 | public function __construct(protected ?string $fullName) |
|
| 27 | { |
||
| 28 | 10 | $this->fullName = format(FullNameFormatter::class, $this->fullName); |
|
| 29 | |||
| 30 | 10 | $this->split = str($this->fullName)->split('/\s/'); |
|
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Get the full name. |
||
| 35 | * |
||
| 36 | * @return string |
||
| 37 | */ |
||
| 38 | 6 | public function fullName(): string |
|
| 39 | { |
||
| 40 | 6 | return (string) $this->fullName; |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Get the first name. |
||
| 45 | * |
||
| 46 | * @return string |
||
| 47 | */ |
||
| 48 | 3 | public function firstName(): string |
|
| 49 | { |
||
| 50 | 3 | return $this->split->first(); |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Get the last name. |
||
| 55 | * |
||
| 56 | * @return string |
||
| 57 | */ |
||
| 58 | 2 | public function lastName(): string |
|
| 59 | { |
||
| 60 | 2 | return $this->split->last(); |
|
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Get the object value. |
||
| 65 | * |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | 1 | public function value(): string |
|
| 69 | { |
||
| 70 | 1 | return $this->fullName(); |
|
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Get an array representation of the value object. |
||
| 75 | * |
||
| 76 | * @return array |
||
| 77 | */ |
||
| 78 | 1 | public function toArray(): array |
|
| 84 | ]; |
||
| 85 | } |
||
| 86 | } |
||
| 87 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: