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

Passed
Pull Request — master (#907)
by Henrique
03:13
created

CountryBasedWrapper::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
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
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
use Respect\Validation\Exceptions\ComponentException;
17
use Respect\Validation\Validatable;
18
use function sprintf;
19
20
/**
21
 * Abstract class for helping on creating rules that use a rule inside to validate.
22
 *
23
 * @author Henrique Moody <[email protected]>
24
 */
25
abstract class CountryBasedWrapper extends AbstractRule
26
{
27
    /**
28
     * @var Validatable
29
     */
30
    private $validatable;
31
32
    /**
33
     * @var string
34
     */
35
    private $countryCode;
36
37
    /**
38
     * Initializes the rule.
39
     *
40
     * @param string $countryCode
41
     *
42
     * @throws ComponentException When country is not supported.
43
     */
44
    public function __construct(string $countryCode)
45
    {
46
        $className = $this->getClassName(ucfirst(mb_strtolower($countryCode)));
47
        if (!class_exists($className)) {
48
            throw new ComponentException(sprintf('"%s" is not a supported country code', $countryCode));
49
        }
50
51
        $this->countryCode = $countryCode;
52
        $this->validatable = new $className;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function assert($input)
59
    {
60
        return $this->validatable->assert($input);
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function check($input)
67
    {
68
        return $this->validatable->check($input);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function validate($input)
75
    {
76
        return $this->validatable->validate($input);
77
    }
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function setName($name)
82
    {
83
        $this->validatable->setName($name);
84
85
        return parent::setName($name);
86
    }
87
88
    /**
89
     * Returns the class name based on the identifier.
90
     *
91
     * @param string $identifier
92
     * @return string
93
     */
94
    abstract protected function getClassName(string $identifier): string;
95
}
96