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 — 0.9 (#692)
by
unknown
02:58
created

Factory::rule()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5.0113

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
ccs 12
cts 13
cp 0.9231
rs 8.6737
cc 5
eloc 12
nc 5
nop 2
crap 5.0113
1
<?php
2
3
namespace Respect\Validation;
4
5
use ReflectionClass;
6
use Respect\Validation\Exceptions\ComponentException;
7
8
class Factory
9
{
10
    protected $rulePrefixes = array('Respect\\Validation\\Rules\\');
11
12 35
    public function getRulePrefixes()
13
    {
14 35
        return $this->rulePrefixes;
15
    }
16
17 2
    public function appendRulePrefix($rulePrefix)
18 1
    {
19 2
        array_push($this->rulePrefixes, $rulePrefix);
20 2
    }
21
22 1
    public function prependRulePrefix($rulePrefix)
23
    {
24 1
        array_unshift($this->rulePrefixes, $rulePrefix);
25 1
    }
26
27 32
    public function rule($ruleName, array $arguments = array())
28
    {
29 32
        if ($ruleName instanceof Validatable) {
30
            return $ruleName;
31
        }
32
33 32
        foreach ($this->getRulePrefixes() as $prefix) {
34 32
            $className = $prefix.ucfirst($ruleName);
35 32
            if (! class_exists($className)) {
36 3
                continue;
37
            }
38
39 30
            $reflection = new ReflectionClass($className);
40 30
            if (! $reflection->isSubclassOf('Respect\\Validation\\Validatable')) {
41 1
                throw new ComponentException(sprintf('"%s" is not a valid respect rule', $className));
42
            }
43
44 29
            return $reflection->newInstanceArgs($arguments);
45 2
        }
46
47 2
        throw new ComponentException(sprintf('"%s" is not a valid rule name', $ruleName));
48
    }
49
}
50