| Total Complexity | 10 |
| Total Lines | 126 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class Field implements FieldInterface |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | private $fieldName; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | private $validators = []; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var array |
||
| 21 | */ |
||
| 22 | private $filters = []; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var bool |
||
| 26 | */ |
||
| 27 | private $required; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var callable|null |
||
| 31 | */ |
||
| 32 | private $condition; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var bool |
||
| 36 | */ |
||
| 37 | private $isArray = false; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Field constructor. |
||
| 41 | * @param string $fieldName |
||
| 42 | * @param bool $required |
||
| 43 | * @param callable|null $condition |
||
| 44 | */ |
||
| 45 | public function __construct( |
||
| 46 | string $fieldName, |
||
| 47 | bool $required, |
||
| 48 | ?callable $condition |
||
| 49 | ) { |
||
| 50 | $this->fieldName = $fieldName; |
||
| 51 | $this->required = $required; |
||
| 52 | $this->condition = $condition; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $name |
||
| 57 | * @param array|null $options |
||
| 58 | * @return Field |
||
| 59 | */ |
||
| 60 | public function registerValidator(string $name, ?array $options): self |
||
| 61 | { |
||
| 62 | $this->validators[$name] = $options; |
||
| 63 | return $this; |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param bool $isArray |
||
| 68 | * @return Field |
||
| 69 | */ |
||
| 70 | public function setIsArray(bool $isArray): self |
||
| 71 | { |
||
| 72 | $this->isArray = $isArray; |
||
| 73 | return $this; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | public function fieldName(): string |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @return bool |
||
| 86 | */ |
||
| 87 | public function required(): bool |
||
| 88 | { |
||
| 89 | return $this->required; |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @return array |
||
| 94 | */ |
||
| 95 | public function validators(): array |
||
| 96 | { |
||
| 97 | return $this->validators; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @return callable|null |
||
| 102 | */ |
||
| 103 | public function condition(): ?callable |
||
| 104 | { |
||
| 105 | return $this->condition; |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param string $name |
||
| 110 | * @param array|null $options |
||
| 111 | * @return Field |
||
| 112 | */ |
||
| 113 | public function registerFilter(string $name, ?array $options): self |
||
| 114 | { |
||
| 115 | $this->filters[$name] = $options; |
||
| 116 | return $this; |
||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @return array |
||
| 121 | */ |
||
| 122 | public function filters(): array |
||
| 123 | { |
||
| 124 | return $this->filters; |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @return bool |
||
| 129 | */ |
||
| 130 | public function isArray(): bool |
||
| 133 | } |
||
| 134 | } |
||
| 135 |