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