| Total Complexity | 7 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | final class ValidationContext |
||
| 10 | { |
||
| 11 | private ?DataSetInterface $dataSet; |
||
| 12 | private ?string $attribute = null; |
||
| 13 | private array $params = []; |
||
| 14 | |||
| 15 | public function __construct( |
||
| 16 | ?DataSetInterface $dataSet = null, |
||
| 17 | ?string $attribute = null, |
||
| 18 | array $params = [] |
||
| 19 | ) { |
||
| 20 | $this->dataSet = $dataSet; |
||
| 21 | $this->attribute = $attribute; |
||
| 22 | $this->params = $params; |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @return DataSetInterface|null Optional data set. |
||
| 27 | */ |
||
| 28 | public function getDataSet(): ?DataSetInterface |
||
| 29 | { |
||
| 30 | return $this->dataSet; |
||
| 31 | } |
||
| 32 | |||
| 33 | public function getAttribute(): ?string |
||
| 34 | { |
||
| 35 | return $this->attribute; |
||
| 36 | } |
||
| 37 | |||
| 38 | public function withAttribute(?string $attribute): self |
||
| 39 | { |
||
| 40 | $new = clone $this; |
||
| 41 | $new->attribute = $attribute; |
||
| 42 | return $new; |
||
| 43 | } |
||
| 44 | |||
| 45 | public function getParams(): array |
||
| 46 | { |
||
| 47 | return $this->params; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param string $key |
||
| 52 | * @param mixed $default |
||
| 53 | * |
||
| 54 | * @return mixed |
||
| 55 | */ |
||
| 56 | public function getParam(string $key, $default = null) |
||
| 57 | { |
||
| 58 | return ArrayHelper::getValue($this->params, $key, $default); |
||
| 59 | } |
||
| 60 | |||
| 61 | public function setParam(string $key, $value): void |
||
| 64 | } |
||
| 65 | } |
||
| 66 |