| Total Complexity | 8 |
| Total Lines | 77 |
| Duplicated Lines | 0 % |
| Coverage | 52.38% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class Configuration |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | protected string $configFile = 'laravel-generator-package'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * The array of class fields. |
||
| 19 | * |
||
| 20 | * @var array |
||
| 21 | */ |
||
| 22 | protected array $fields = [ |
||
| 23 | 'text' => TextField::class, |
||
| 24 | ]; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Конфиг генерации пакетов |
||
| 28 | * |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | protected array $generator = []; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Configuration constructor. |
||
| 35 | */ |
||
| 36 | 16 | public function __construct() |
|
| 37 | { |
||
| 38 | 16 | $this->load(); |
|
| 39 | 16 | } |
|
| 40 | |||
| 41 | /** |
||
| 42 | * @return $this|Configuration |
||
| 43 | */ |
||
| 44 | 16 | public function load(): Configuration |
|
| 45 | { |
||
| 46 | 16 | $fields = config($this->configFile . '.fields'); |
|
| 47 | 16 | if (is_array($fields)) { |
|
| 48 | $this->setFields($fields); |
||
| 49 | } |
||
| 50 | 16 | $generator = config($this->configFile . '.generator'); |
|
| 51 | 16 | if (is_array($generator)) { |
|
| 52 | $this->generator = $generator; |
||
| 53 | } |
||
| 54 | 16 | return $this; |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param array $fields |
||
| 59 | */ |
||
| 60 | public function setFields(array $fields): void |
||
| 61 | { |
||
| 62 | $this->fields = $fields; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @param FieldInterface $field |
||
| 67 | */ |
||
| 68 | public function setField(FieldInterface $field): void |
||
| 69 | { |
||
| 70 | $this->fields[] = $field; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @return array |
||
| 75 | */ |
||
| 76 | 15 | public function getFields(): array |
|
| 77 | { |
||
| 78 | 15 | return $this->fields; |
|
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return array |
||
| 83 | */ |
||
| 84 | public function getGenerator(): array |
||
| 87 | } |
||
| 88 | } |
||
| 89 |