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

Completed
Pull Request — master (#678)
by Henrique
03:27
created

Factory::getRulePrefixes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Respect\Validation;
13
14
use ReflectionClass;
15
use Respect\Validation\Exceptions\ComponentException;
16
17
class Factory
18
{
19
    protected $rulePrefixes = ['Respect\\Validation\\Rules\\'];
20
21
    public function getRulePrefixes()
22
    {
23
        return $this->rulePrefixes;
24
    }
25
26
    private function filterRulePrefix($rulePrefix)
27
    {
28
        $namespaceSeparator = '\\';
29
        $rulePrefix = rtrim($rulePrefix, $namespaceSeparator);
30
31
        return $rulePrefix.$namespaceSeparator;
32
    }
33
34
    public function appendRulePrefix($rulePrefix)
35
    {
36
        array_push($this->rulePrefixes, $this->filterRulePrefix($rulePrefix));
37
    }
38
39
    public function prependRulePrefix($rulePrefix)
40
    {
41
        array_unshift($this->rulePrefixes, $this->filterRulePrefix($rulePrefix));
42
    }
43
44
    public function rule($ruleName, array $arguments = [])
45
    {
46
        if ($ruleName instanceof Validatable) {
47
            return $ruleName;
48
        }
49
50
        foreach ($this->getRulePrefixes() as $prefix) {
51
            $className = $prefix.ucfirst($ruleName);
52
            if (!class_exists($className)) {
53
                continue;
54
            }
55
56
            $reflection = new ReflectionClass($className);
57
            if (!$reflection->isSubclassOf(Validatable::class)) {
58
                throw new ComponentException(sprintf('"%s" is not a valid respect rule', $className));
59
            }
60
61
            return $reflection->newInstanceArgs($arguments);
62
        }
63
64
        throw new ComponentException(sprintf('"%s" is not a valid rule name', $ruleName));
65
    }
66
}
67