Passed
Push — main ( 317075...c1e860 )
by Garbuz
02:43
created

Configuration::getGenerator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GarbuzIvan\LaravelGeneratorPackage;
6
7
use GarbuzIvan\LaravelGeneratorPackage\Form\Fields\TextField;
8
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
77
    {
78 20
        return $this->fields;
79
    }
80
81
    /**
82
     * @return array
83
     */
84 1
    public function getGenerator(): array
85
    {
86 1
        return $this->generator;
87
    }
88
}
89