Passed
Push — main ( 5926a8...a239d4 )
by Garbuz
03:10
created

Configuration::setFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GarbuzIvan\LaravelGeneratorPackage;
6
7
use GarbuzIvan\LaravelGeneratorPackage\Contracts\FieldInterface;
8
use GarbuzIvan\LaravelGeneratorPackage\Form\Fields\TextField;
9
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
85
    {
86
        return $this->generator;
87
    }
88
}
89