Passed
Push — main ( 8a862c...a6fdb3 )
by Garbuz
02:58
created

Package::setPackageName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GarbuzIvan\LaravelGeneratorPackage\Builder;
6
7
use GarbuzIvan\LaravelGeneratorPackage\Facades\Field;
8
9
class Package
10
{
11
    private array $packageArr;
12
    /**
13
     * @var string
14
     */
15
    private string $name = 'name new package';
16
    private string $description = 'Description new package';
17
18
    /**
19
     * @var string|null
20
     */
21
    private ?string $packageVendor = null;
22
    private ?string $packageName = null;
23
24
    /**
25
     * @var bool
26
     */
27
    private bool $generator_tests = true;
28
    private bool $generator_seed = true;
29
    private bool $generator_api = true;
30
    private bool $generator_api_frontend = true;
31
    private bool $generator_laravel_admin = true;
32
33
    /**
34
     * @var array
35
     */
36
    private array $fields = [];
37
    private array $form = [];
38
    private array $filter = [];
39
40
    /**
41
     * @param array $package
42
     * @return $this
43
     */
44 15
    public function init(array $package): self
45
    {
46 15
        $this->packageArr = $package;
47 15
        $this->setName($this->packageArr['name'] ?? $this->name);
48 15
        $this->setDescription($this->packageArr['description'] ?? $this->description);
49 15
        $this->setPackageVendor(/** @scrutinizer ignore-type */ $this->packageArr['vendor'] ?? $this->packageVendor);
50 15
        $this->setPackageName(/** @scrutinizer ignore-type */ $this->packageArr['package'] ?? $this->packageName);
51
52 15
        $this->setGeneratorTests($this->packageArr['generator']['tests'] ?? $this->generator_tests);
53 15
        $this->setGeneratorSeed($this->packageArr['generator']['seed'] ?? $this->generator_seed);
54 15
        $this->setGeneratorApi($this->packageArr['generator']['api'] ?? $this->generator_api);
55 15
        $this->setGeneratorApiFrontend($this->packageArr['generator']['api_frontend'] ?? $this->generator_api_frontend);
56 15
        $this->setGeneratorLaravelAdmin($this->packageArr['generator']['laravel_admin'] ?? $this->generator_laravel_admin);
57
58 15
        $this->setFields($this->packageArr['fields'] ?? null);
59 15
        $this->setForm($this->packageArr['form'] ?? $this->form);
60 15
        $this->setFilter($this->packageArr['filter'] ?? $this->filter);
61
62 15
        return $this;
63
    }
64
65
    /**
66
     * @param string $name
67
     * @return $this
68
     */
69 15
    public function setName(string $name): self
70
    {
71 15
        $this->name = $name;
72 15
        return $this;
73
    }
74
75
    /**
76
     * @param string $description
77
     * @return $this
78
     */
79 15
    public function setDescription(string $description): self
80
    {
81 15
        $this->description = $description;
82 15
        return $this;
83
    }
84
85
    /**
86
     * @param string $packageVendor
87
     * @return $this
88
     */
89 16
    public function setPackageVendor(string $packageVendor): self
90
    {
91 16
        $this->packageVendor = $packageVendor;
92 16
        return $this;
93
    }
94
95
    /**
96
     * @param string $packageName
97
     * @return $this
98
     */
99 16
    public function setPackageName(string $packageName): self
100
    {
101 16
        $this->packageName = $packageName;
102 16
        return $this;
103
    }
104
105
    /**
106
     * @param bool $generator_tests
107
     * @return $this
108
     */
109 16
    public function setGeneratorTests(bool $generator_tests = true): self
110
    {
111 16
        $this->generator_tests = $generator_tests;
112 16
        return $this;
113
    }
114
115
    /**
116
     * @param bool $generator_seed
117
     * @return $this
118
     */
119 16
    public function setGeneratorSeed(bool $generator_seed = true): self
120
    {
121 16
        $this->generator_seed = $generator_seed;
122 16
        return $this;
123
    }
124
125
    /**
126
     * @param bool $generator_api
127
     * @return $this
128
     */
129 16
    public function setGeneratorApi(bool $generator_api = true): self
130
    {
131 16
        $this->generator_api = $generator_api;
132 16
        return $this;
133
    }
134
135
    /**
136
     * @param bool $generator_api_frontend
137
     * @return $this
138
     */
139 16
    public function setGeneratorApiFrontend(bool $generator_api_frontend = true): self
140
    {
141 16
        $this->generator_api_frontend = $generator_api_frontend;
142 16
        return $this;
143
    }
144
145
    /**
146
     * @param bool $generator_laravel_admin
147
     * @return $this
148
     */
149 16
    public function setGeneratorLaravelAdmin(bool $generator_laravel_admin = true): self
150
    {
151 16
        $this->generator_laravel_admin = $generator_laravel_admin;
152 16
        return $this;
153
    }
154
155
    /**
156
     * @param array|null $fields
157
     * @return $this
158
     */
159 15
    public function setFields(?array $fields): self
160
    {
161 15
        if (!is_array($fields)) {
0 ignored issues
show
introduced by
The condition is_array($fields) is always true.
Loading history...
162 1
            return $this;
163
        }
164 15
        foreach ($fields as $fieldKey => $fieldParam) {
165 15
            $this->fields[$fieldKey] = Field::loadFieldFromArray($fieldKey, $fieldParam);
166
        }
167 15
        return $this;
168
    }
169
170
    /**
171
     * @param array $form
172
     * @return $this
173
     */
174 15
    public function setForm(array $form): self
175
    {
176 15
        $this->form = $form;
177 15
        return $this;
178
    }
179
180
    /**
181
     * @param array $filter
182
     * @return $this
183
     */
184 15
    public function setFilter(array $filter): self
185
    {
186 15
        $this->filter = $filter;
187 15
        return $this;
188
    }
189
190
    /**
191
     * @return string
192
     */
193 1
    public function getName(): string
194
    {
195 1
        return $this->name;
196
    }
197
198
    /**
199
     * @return string
200
     */
201 1
    public function getDescripton(): string
202
    {
203 1
        return $this->description;
204
    }
205
206
    /**
207
     * @return string|null
208
     */
209 4
    public function getPackageVendor(): ?string
210
    {
211 4
        return $this->packageVendor;
212
    }
213
214
    /**
215
     * @return string|null
216
     */
217 5
    public function getPackageName(): ?string
218
    {
219 5
        return $this->packageName;
220
    }
221
222
    /**
223
     * @return bool
224
     */
225 4
    public function getGeneratorTests(): bool
226
    {
227 4
        return $this->generator_tests;
228
    }
229
230
    /**
231
     * @return bool
232
     */
233 4
    public function getGeneratorSeed(): bool
234
    {
235 4
        return $this->generator_seed;
236
    }
237
238
    /**
239
     * @return bool
240
     */
241 4
    public function getGeneratorApi(): bool
242
    {
243 4
        return $this->generator_api;
244
    }
245
246
    /**
247
     * @return bool
248
     */
249 4
    public function getGeneratorApiFrontend(): bool
250
    {
251 4
        return $this->generator_api_frontend;
252
    }
253
254
    /**
255
     * @return bool
256
     */
257 4
    public function getGeneratorLaravelAdmin(): bool
258
    {
259 4
        return $this->generator_laravel_admin;
260
    }
261
262
    /**
263
     * @return array
264
     */
265 2
    public function getFields(): array
266
    {
267 2
        return $this->fields;
268
    }
269
270
    /**
271
     * @return array
272
     */
273 1
    public function getForm(): array
274
    {
275 1
        return $this->form;
276
    }
277
278
    /**
279
     * @return array
280
     */
281 1
    public function getFilter(): array
282
    {
283 1
        return $this->filter;
284
    }
285
286
    /**
287
     * @param string $path
288
     * @return string
289
     */
290 3
    public function getPath(string $path): string
291
    {
292 3
        return base_path('packages/' . $this->getPackageVendor() . '/' . $this->getPackageName() . '/' . $path);
293
    }
294
}
295