Passed
Branch master (f320c5)
by Xavier
01:33
created

Identifier   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 105
rs 10
c 0
b 0
f 0
ccs 17
cts 17
cp 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 3 1
A getRelatedResources() 0 3 1
A __construct() 0 3 1
A getComplementaryResources() 0 3 1
A getQueryString() 0 3 1
A getUrl() 0 3 1
A __toString() 0 3 1
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Identifiers;
4
5
abstract class Identifier
6
{
7
    /**
8
     * The query string.
9
     *
10
     * @var string
11
     */
12
    private $queryString;
13
14
    /**
15
     * The regex matches.
16
     *
17
     * @var array
18
     */
19
    protected $matches;
20
21
    /**
22
     * The regex to identify an identifier.
23
     *
24
     * @var string
25
     */
26
    protected $regex;
27
28
    /**
29
     * Array containing API resources to be fetched.
30
     *
31
     * @var array
32
     */
33
    protected $resources;
34
35
    /**
36
     * Base resource webpage URL.
37
     *
38
     * @var string
39
     */
40
    protected $baseUrl;
41 28
42
    /**
43 28
     * Identifier constructor.
44 28
     *
45
     * @param string $queryString
46
     */
47
    public function __construct(string $queryString)
48
    {
49
        $this->queryString = $queryString;
50
    }
51
52
    /**
53 24
     * Does the query contain a valid Identifier?
54
     *
55 24
     * @return bool
56 24
     */
57
    public function isValid(): bool
58 24
    {
59 24
        return (bool) preg_match($this->regex, $this->queryString, $this->matches);
60
    }
61
62
    /**
63 1
     * Resources getter.
64
     *
65
     * @return array
66
     */
67
    public function getRelatedResources(): array
68
    {
69
        return $this->resources;
70
    }
71 24
72
    /**
73 24
     * Complementary Resources getter.
74
     *
75
     * @return array
76
     */
77
    public function getComplementaryResources(): array
78
    {
79
        return $this->complementaryResources ?? [];
80
    }
81 3
82
    /**
83 3
     * Return URL to the identifier's publication website.
84
     *
85
     * @return string
86
     */
87
    public function getUrl()
88
    {
89
        return $this->baseUrl.$this->getQueryString();
90
    }
91 4
92
    /**
93 4
     * Class to String.
94
     *
95
     * @return string
96
     */
97
    public function __toString(): string
98
    {
99
        return $this->getQueryString();
100
    }
101 9
102
    /**
103 9
     * QueryString getter.
104
     *
105
     * @return string
106
     */
107
    public function getQueryString()
108
    {
109
        return rtrim($this->queryString, ' .');
110
    }
111
}
112