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 — 1.1 (#1169)
by Henrique
02:59
created

Factory::rule()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5.0144

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 11
cts 12
cp 0.9167
rs 9.2568
c 0
b 0
f 0
cc 5
nc 5
nop 2
crap 5.0144
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 11
    public function getRulePrefixes()
22
    {
23 11
        return $this->rulePrefixes;
24
    }
25
26 5
    private function filterRulePrefix($rulePrefix)
27
    {
28 5
        $namespaceSeparator = '\\';
29 5
        $rulePrefix = rtrim($rulePrefix, $namespaceSeparator);
30
31 5
        return $rulePrefix.$namespaceSeparator;
32
    }
33
34 3
    public function appendRulePrefix($rulePrefix)
35
    {
36 3
        array_push($this->rulePrefixes, $this->filterRulePrefix($rulePrefix));
37 3
    }
38
39 2
    public function prependRulePrefix($rulePrefix)
40
    {
41 2
        array_unshift($this->rulePrefixes, $this->filterRulePrefix($rulePrefix));
42 2
    }
43
44 6
    public function rule($ruleName, array $arguments = [])
45
    {
46 6
        if ($ruleName instanceof Validatable) {
47
            return $ruleName;
48
        }
49
50 6
        foreach ($this->getRulePrefixes() as $prefix) {
51 6
            $className = $prefix.ucfirst($ruleName);
52 6
            if (!class_exists($className)) {
53 3
                continue;
54
            }
55
56 4
            $reflection = new ReflectionClass($className);
57 4
            if (!$reflection->isSubclassOf('Respect\\Validation\\Validatable')) {
58 1
                throw new ComponentException(sprintf('"%s" is not a valid respect rule', $className));
59
            }
60
61 3
            return $reflection->newInstanceArgs($arguments);
62
        }
63
64 2
        throw new ComponentException(sprintf('"%s" is not a valid rule name', $ruleName));
65
    }
66
}
67