Passed
Push — main ( 009e2f...54edb8 )
by Garbuz
02:25
created

Builder   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 15
eloc 29
c 1
b 0
f 0
dl 0
loc 91
ccs 30
cts 32
cp 0.9375
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A isIgnore() 0 9 5
A __construct() 0 3 1
A getPackageName() 0 3 1
A initFilter() 0 15 4
A getPackageVendor() 0 3 1
A init() 0 12 3
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 3
            if ($this->isIgnore($package['vendor'], $package['package'])) {
41 1
                continue;
42
            }
43
            /* Generation */
44
            //var_dump($this->packageVendor, $this->packageName);
45
        }
46 3
        return true;
47
    }
48
49
    /**
50
     * @param string $vandor
51
     * @param string $name
52
     * @return bool
53
     */
54 4
    public function isIgnore(string $vandor, string $name): bool
55
    {
56 4
        if (!is_null($this->getPackageVendor()) && $this->getPackageVendor() != $vandor) {
57 2
            return true;
58
        }
59 3
        if (!is_null($this->getPackageName()) && $this->getPackageName() != $name) {
60 1
            return true;
61
        }
62 3
        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 2
            return true;
73
        }
74 5
        $package = mb_strtolower($package);
75 5
        $package = str_replace('\\', '/', $package);
76 5
        if (!mb_stripos($package, '/')) {
77
            $this->packageVendor = $package;
78
            return true;
79
        }
80 5
        $match = explode('/', $package, 2);
81 5
        $this->packageVendor = $match[0];
82 5
        $this->packageName = mb_strlen(trim($match[1])) > 0 ? $match[1] : null;
83 5
        return true;
84
    }
85
86
    /**
87
     * @return string|null
88
     */
89 7
    public function getPackageVendor(): ?string
90
    {
91 7
        return $this->packageVendor;
92
    }
93
94
    /**
95
     * @return string|null
96
     */
97 6
    public function getPackageName(): ?string
98
    {
99 6
        return $this->packageName;
100
    }
101
}
102