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 (#644)
by Augusto
04:27
created

Factory::appendRulePrefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

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