Lines
100.00%
8 / 8
Functions and Methods
100.00%
4 / 4
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Name | 100.00% | 8 / 8 | 100.00% | 4 / 4 | 6 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | |||||
| __toString | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| equals | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| validate | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Districts\Core\Domain; | |
| 6 | ||
| 7 | use Districts\Core\Domain\Exception\InvalidNameException; | |
| 8 | use Doctrine\ORM\Mapping as ORM; | |
| 9 | ||
| 10 | #[ORM\Embeddable] | |
| 11 | readonly class Name | |
| 12 | { | |
| 13 | #[ORM\Column(type: "string", options: ["collation" => "utf8_polish_ci"])] | |
| 14 | private string $name; | |
| 15 | ||
| 16 | public function __construct(string $name) | |
| 17 | { | |
| 18 | if (!self::validate($name)) { | |
| 19 | throw new InvalidNameException(); | |
| 20 | } | |
| 21 | $this->name = $name; | |
| 22 | } | |
| 23 | ||
| 24 | public function __toString(): string | |
| 25 | { | |
| 26 | return $this->name; | |
| 27 | } | |
| 28 | ||
| 29 | public function equals(self $other): bool | |
| 30 | { | |
| 31 | return $this->name === $other->name; | |
| 32 | } | |
| 33 | ||
| 34 | private static function validate(string $name): bool | |
| 35 | { | |
| 36 | if ($name === "") { | |
| 37 | return false; | |
| 38 | } | |
| 39 | return true; | |
| 40 | } | |
| 41 | } |