Passed
Push — master ( e28d83...33fdd0 )
by Dominik
59s queued 14s
created

Dependency   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 12
eloc 26
c 2
b 1
f 0
dl 0
loc 106
ccs 30
cts 30
cp 1
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setLicenses() 0 5 1
A setVersion() 0 5 1
A getPackageName() 0 9 2
A setName() 0 5 1
A getName() 0 3 1
A hasAnyLicense() 0 3 1
A getVersion() 0 3 1
A __construct() 0 5 1
A getAuthorName() 0 3 1
A getLicenses() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dominikb\ComposerLicenseChecker;
6
7
class Dependency
8
{
9
    /** @var string */
10
    private $name;
11
12
    /** @var string */
13
    private $version;
14
15
    /** @var string[] */
16
    private $licenses;
17
18
    // This is a constant that is used to represent the absence of a license.
19
    // Matches the value of the 'none' license in the composer.json file.
20
    const NO_LICENSES = ['none'];
21
22
    /**
23
     * Dependency constructor.
24
     *
25
     * @param  string  $name
26
     * @param  string  $version
27
     * @param  string[]  $licenses
28
     */
29 13
    public function __construct(string $name = '', string $version = '', array $licenses = [])
30
    {
31 13
        $this->name = $name;
32 13
        $this->version = $version;
33 13
        $this->licenses = $licenses;
34
    }
35
36
    /**
37
     * @return string
38
     */
39 5
    public function getName(): string
40
    {
41 5
        return $this->name;
42
    }
43
44
    /**
45
     * @param  string  $name
46
     */
47 5
    public function setName(string $name): self
48
    {
49 5
        $this->name = $name;
50
51 5
        return $this;
52
    }
53
54
    /**
55
     * @return string
56
     */
57 5
    public function getVersion(): string
58
    {
59 5
        return $this->version;
60
    }
61
62
    /**
63
     * @param  string  $version
64
     */
65 5
    public function setVersion(string $version): self
66
    {
67 5
        $this->version = $version;
68
69 5
        return $this;
70
    }
71
72 10
    public function hasAnyLicense(): bool
73
    {
74 10
        return ! empty($this->licenses);
75
    }
76
77
    /**
78
     * @return string[]
79
     */
80 10
    public function getLicenses(): array
81
    {
82 10
        if ($this->hasAnyLicense()) {
83 9
            return $this->licenses;
84
        } else {
85 1
            return self::NO_LICENSES;
86
        }
87
    }
88
89
    /**
90
     * @param  string[]  $licenses
91
     */
92 9
    public function setLicenses(array $licenses): self
93
    {
94 9
        $this->licenses = $licenses;
95
96 9
        return $this;
97
    }
98
99 2
    public function getAuthorName(): string
100
    {
101 2
        return explode('/', $this->name)[0];
102
    }
103
104 2
    public function getPackageName(): string
105
    {
106 2
        $parts = explode('/', $this->name);
107
108 2
        if (count($parts) != 2) {
109 1
            return '';
110
        }
111
112 1
        return $parts[1];
113
    }
114
}
115