| 1 | <?php |
||
| 7 | class ValidationViolation |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | protected $message; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var null|string |
||
| 16 | */ |
||
| 17 | protected $property; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param string $message |
||
| 21 | * @param null|string $property |
||
| 22 | */ |
||
| 23 | 3 | protected function __construct(string $message, ?string $property = null) |
|
| 28 | |||
| 29 | /** |
||
| 30 | * @return string |
||
| 31 | */ |
||
| 32 | 2 | public function __toString(): string |
|
| 33 | { |
||
| 34 | 2 | return sprintf('%s %s', ($property = $this->getProperty()) ? ($property.':') : '', $this->getMessage()); |
|
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param string $message |
||
| 39 | * @param null|string $property |
||
| 40 | * |
||
| 41 | * @return ValidationViolation |
||
| 42 | */ |
||
| 43 | 3 | public static function create(string $message, ?string $property = null): self |
|
| 47 | |||
| 48 | /** |
||
| 49 | * @return string |
||
| 50 | */ |
||
| 51 | 2 | public function getMessage(): string |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @return null|string |
||
| 58 | */ |
||
| 59 | 2 | public function getProperty(): ?string |
|
| 63 | } |
||
| 64 |