Passed
Push — main ( ea000f...009e2f )
by Garbuz
02:44
created

Builder   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Test Coverage

Coverage 84.38%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 15
eloc 29
c 1
b 0
f 0
dl 0
loc 90
ccs 27
cts 32
cp 0.8438
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getPackageName() 0 3 1
A initFilter() 0 14 4
A isIgnore() 0 9 5
A getPackageVendor() 0 3 1
A init() 0 12 3
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GarbuzIvan\LaravelGeneratorPackage\Builder;
6
7
use GarbuzIvan\LaravelGeneratorPackage\Configuration;
8
9
class Builder
10
{
11
    /**
12
     * @var Configuration
13
     */
14
    private Configuration $config;
15
16
    /**
17
     * @var string|null
18
     */
19
    private ?string $packageVendor = null;
20
    private ?string $packageName = null;
21
22
    /**
23
     * Builder constructor.
24
     * @param Configuration $config
25
     */
26 7
    public function __construct(Configuration $config)
27
    {
28 7
        $this->config = $config;
29 7
    }
30
31
    /**
32
     * @param string|null $package
33
     * @return bool
34
     */
35 3
    public function init(?string $package = null): bool
36
    {
37 3
        $this->initFilter($package);
38 3
        $configGenerator = $this->config->getGenerator();
39 3
        foreach ($configGenerator as $package) {
40
            if ($this->isIgnore($package['vendor'], $package['package'])) {
41
                continue;
42
            }
43
            /* Generation */
44
            var_dump($this->packageVendor, $this->packageName);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($this->packageV...or, $this->packageName) looks like debug code. Are you sure you do not want to remove it?
Loading history...
45
        }
46 3
        return true;
47
    }
48
49
    /**
50
     * @param string $vandor
51
     * @param string $name
52
     * @return bool
53
     */
54 1
    public function isIgnore(string $vandor, string $name): bool
55
    {
56 1
        if ($this->getPackageVendor() != null && $this->getPackageVendor() != $vandor) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $this->getPackageVendor() of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
57 1
            return true;
58
        }
59 1
        if ($this->getPackageName() != null && $this->getPackageName() != $name) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $this->getPackageName() of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
60 1
            return true;
61
        }
62 1
        return false;
63
    }
64
65
    /**
66
     * @param string|null $package
67
     * @return bool
68
     */
69 7
    public function initFilter(?string $package = null): bool
70
    {
71 7
        if (is_null($package)) {
72 3
            return true;
73
        }
74 4
        $package = str_replace('\\', '/', $package);
75 4
        if (!mb_stripos($package, '/')) {
76
            $this->packageVendor = $package;
77
            return true;
78
        }
79 4
        $match = explode('/', $package, 2);
80 4
        $this->packageVendor = $match[0];
81 4
        $this->packageName = mb_strlen(trim($match[1])) > 0 ? $match[1] : null;
82 4
        return true;
83
    }
84
85
    /**
86
     * @return string|null
87
     */
88 4
    public function getPackageVendor(): ?string
89
    {
90 4
        return $this->packageVendor;
91
    }
92
93
    /**
94
     * @return string|null
95
     */
96 4
    public function getPackageName(): ?string
97
    {
98 4
        return $this->packageName;
99
    }
100
}
101