| Total Complexity | 11 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class Preset |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var array |
||
| 11 | */ |
||
| 12 | protected array $usedLayouts = []; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var array[string]string |
||
|
|
|||
| 16 | */ |
||
| 17 | protected array $layouts = []; |
||
| 18 | |||
| 19 | 11 | public function __construct() |
|
| 20 | { |
||
| 21 | 11 | $this->setLayouts($this->usedLayouts); |
|
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Initialise new instance using layouts set. |
||
| 26 | */ |
||
| 27 | 11 | public static function withLayouts(array $usedLayouts = []): static |
|
| 28 | { |
||
| 29 | 11 | return (new static())->setLayouts($usedLayouts); |
|
| 30 | } |
||
| 31 | |||
| 32 | 11 | public function setLayouts(array $usedLayouts = []): static |
|
| 33 | { |
||
| 34 | 11 | $this->layouts = []; |
|
| 35 | |||
| 36 | 11 | foreach ($usedLayouts as $key => $layout) { |
|
| 37 | 11 | if (is_a($layout, Layout::class, true)) { |
|
| 38 | 11 | if (is_string($layout)) { |
|
| 39 | 11 | $layout = new $layout; |
|
| 40 | } |
||
| 41 | 11 | $this->layouts[(is_numeric($key) || !$key) ? $layout->name() : $key] = $layout::class; |
|
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | 11 | return $this; |
|
| 46 | } |
||
| 47 | |||
| 48 | 11 | public function layouts(): array |
|
| 51 | } |
||
| 52 | |||
| 53 | 9 | public function handle(Flexible $field): static |
|
| 60 | } |
||
| 61 | } |
||
| 62 |