| Total Complexity | 11 |
| Total Lines | 76 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class Enum extends Generic |
||
| 8 | { |
||
| 9 | protected $options = []; |
||
| 10 | |||
| 11 | protected $colors = ['#777777', '#2574ab', '#259dab', '#5bc0de', '#e6ad5c', '#d9534f']; |
||
| 12 | |||
| 13 | protected $palette = []; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @param array $options |
||
| 17 | * @return self |
||
| 18 | */ |
||
| 19 | public function setOptions(array $options): self |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Set colors palette. |
||
| 35 | * |
||
| 36 | * @param string|array $colors |
||
| 37 | * @param string|null $value |
||
| 38 | */ |
||
| 39 | public function palette($color, string $value = null) |
||
| 40 | { |
||
| 41 | if (is_array($color)) { |
||
| 42 | foreach ($color as $name => $code) { |
||
| 43 | $this->palette($name, $code); |
||
| 44 | } |
||
| 45 | |||
| 46 | return $this; |
||
| 47 | } |
||
| 48 | |||
| 49 | if (!array_key_exists($color, $this->options)) { |
||
| 50 | throw new Exception("Unknown option {$color}"); |
||
| 51 | } |
||
| 52 | |||
| 53 | $this->palette[$color] = $value; |
||
| 54 | |||
| 55 | return $this; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return array |
||
| 60 | */ |
||
| 61 | protected function onEdit() |
||
| 62 | { |
||
| 63 | return [ |
||
| 64 | 'options' => $this->options ?: [], |
||
| 65 | 'palette' => $this->palette, |
||
| 66 | ]; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return array |
||
| 71 | */ |
||
| 72 | protected function onIndex() |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @return array |
||
| 79 | */ |
||
| 80 | protected function onView() |
||
| 83 | } |
||
| 84 | } |