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 (#745)
by Oliver
06:39
created

Factory   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.1%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 63
ccs 27
cts 29
cp 0.931
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getRulePrefixes() 0 4 1
A filterRulePrefix() 0 7 1
A appendRulePrefix() 0 4 1
A prependRulePrefix() 0 4 1
B rule() 0 35 6
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
        // statically cache the reflections for performance reasons.
51
        // Since using RelectionClass is not very performant we statically cache
52
        // the initantized reflect objects so that subsequent requests for the
53
        // same rule to not have to do the expensive reflection startup process
54
        // once again.
55 6
        static $reflections = array();
56
57 6
        foreach ($this->getRulePrefixes() as $prefix) {
58 6
            $className = $prefix.ucfirst($ruleName);
59
60 6
            if(isset($reflections[$className]) === true) {
61
                return $reflections[$className]->newInstanceArgs($arguments);
62
            }
63
64 6
            if (!class_exists($className)) {
65 3
                continue;
66
            }
67
68 4
            $reflection = new ReflectionClass($className);
69 4
            if (!$reflection->isSubclassOf('Respect\\Validation\\Validatable')) {
70 1
                throw new ComponentException(sprintf('"%s" is not a valid respect rule', $className));
71
            }
72 3
            $reflections[$className] = $reflection;
73
74 3
            return $reflection->newInstanceArgs($arguments);
75 2
        }
76
77 2
        throw new ComponentException(sprintf('"%s" is not a valid rule name', $ruleName));
78
    }
79
}
80