| Total Complexity | 10 |
| Total Lines | 88 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | abstract class Rule |
||
| 6 | { |
||
| 7 | |||
| 8 | use Attachable; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @var null|string |
||
| 12 | */ |
||
| 13 | protected $type; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var null|Path |
||
| 17 | */ |
||
| 18 | protected $path; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var array |
||
| 22 | */ |
||
| 23 | protected $methods; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | protected $defaults; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Rule constructor. |
||
| 32 | * |
||
| 33 | * @param string $key |
||
| 34 | * @param array $storage |
||
| 35 | * @param null|self $parent |
||
| 36 | */ |
||
| 37 | public function __construct(string $key, array $storage, ?self $parent = null) |
||
| 38 | { |
||
| 39 | $this->prepare(); |
||
| 40 | $this->initializer($key, $storage); |
||
| 41 | $this->pathInit(); |
||
| 42 | if ($parent) { |
||
| 43 | $this->afterPrepare($parent); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param Path|null $path |
||
| 49 | */ |
||
| 50 | protected function hinge(?Path $path): void |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param self $parent |
||
| 62 | * @return void |
||
| 63 | */ |
||
| 64 | protected function afterPrepare(self $parent): void |
||
| 65 | { |
||
| 66 | $this->hinge($parent->path); |
||
| 67 | $this->_key = $parent->_key . '.' . $this->_key; |
||
| 68 | $this->methods = $this->methods ?? $parent->methods; |
||
| 69 | $this->defaults = \array_merge( |
||
| 70 | (array)$parent->defaults, |
||
| 71 | (array)$this->defaults |
||
| 72 | ); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * if this.path === string then new Path(string, []) |
||
| 77 | * else this.path === array then new Path(...this.path) |
||
| 78 | */ |
||
| 79 | protected function pathInit(): void |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @return void |
||
| 90 | */ |
||
| 91 | protected function prepare(): void |
||
| 97 |