Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 729110...d7d6ce )
by
unknown
03:40
created

AnnotationTarget::isScoreRange()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Kitodo\Dlf\Domain\Model;
4
5
/**
6
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
7
 *
8
 * This file is part of the Kitodo and TYPO3 projects.
9
 *
10
 * @license GNU General Public License version 3 or later.
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 */
14
15
class AnnotationTarget
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $url;
21
22
    /**
23
     * @var string
24
     */
25
    protected $objectId;
26
27
    /**
28
     * @var string
29
     */
30
    protected $id;
31
32
    /**
33
     * @var string
34
     */
35
    protected $rangeParameterName;
36
37
    /**
38
     * @var string
39
     */
40
    protected $rangeValue;
41
42
    public function __construct($url)
43
    {
44
        $this->url = $url;
45
46
        $path = parse_url($url, PHP_URL_PATH);
47
        $fragment = parse_url($url, PHP_URL_FRAGMENT);
48
        list($objectId, $id) = explode('/', trim($path, '/'));
49
        list($rangeParameterName, $rangeValue) = explode('=', $fragment);
50
51
        $this->objectId = $objectId;
52
        $this->id = $id;
53
        $this->rangeParameterName = $rangeParameterName;
54
        $this->rangeValue = preg_replace('/\s+/', '', $rangeValue);
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getUrl(): string
61
    {
62
        return $this->url;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getObjectId()
69
    {
70
        return $this->objectId;
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getId()
77
    {
78
        return $this->id;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getRangeParameterName()
85
    {
86
        return $this->rangeParameterName;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getRangeValue()
93
    {
94
        return $this->rangeValue;
95
    }
96
97
    /**
98
     * @return bool
99
     */
100
    public function isValid()
101
    {
102
        if (empty($this->getObjectId())) {
103
            return false;
104
        }
105
106
        if (parse_url($this->getUrl(), PHP_URL_FRAGMENT)) {
107
            return !empty($this->getId()) && $this->isValidRange();
108
        }
109
110
        return true;
111
    }
112
113
    /**
114
     * @return bool
115
     */
116
    public function isValidRange()
117
    {
118
        if (empty($this->rangeParameterName) && empty($this->rangeValue)) {
119
            return true;
120
        } elseif ($this->isFacsimileRange()) {
121
            return preg_match("/^(\d+)(,\d+){3}?$/", $this->rangeValue) === 1;
122
        } elseif ($this->isAudioRange()) {
123
            return preg_match("/^(?:\d+(?:\.\d*)?|\.\d+){0,1}(?:,(?:\d+(?:\.\d*)?|\.\d+))*$/", $this->rangeValue) === 1;
124
        } elseif ($this->isScoreRange()) {
125
            return preg_match("/^((\d+|start|end|all|(\d+|start)(-(\d+|end)){0,1})+)(,(\d+|start|end|all|(\d+|start)(-(\d+|end)){0,1})+){0,}?$/", $this->rangeValue) === 1;
126
        }
127
128
        return false;
129
    }
130
131
    /**
132
     * @return bool
133
     */
134
    public function isScoreRange()
135
    {
136
        return $this->getRangeParameterName() === 'measureRanges';
137
    }
138
139
    /**
140
     * @return bool
141
     */
142
    public function isAudioRange()
143
    {
144
        return $this->getRangeParameterName() === 't';
145
    }
146
147
    /**
148
     * @return bool
149
     */
150
    public function isFacsimileRange()
151
    {
152
        return $this->getRangeParameterName() === 'xywh';
153
    }
154
}
155