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 (#678)
by Henrique
03:31
created

AbstractRelated::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
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\Rules;
13
14
use Respect\Validation\Result;
15
use Respect\Validation\Rule;
16
17
abstract class AbstractRelated implements Rule
18
{
19
    /**
20
     * @var string
21
     */
22
    private $reference;
23
24
    /**
25
     * @var Rule|null
26
     */
27
    private $rule;
28
29
    /**
30
     * @var bool
31
     */
32
    private $mandatory = true;
33
34 1
    public function __construct($reference, Rule $rule = null, bool $mandatory = true)
35
    {
36 1
        $this->reference = $reference;
37 1
        $this->rule = $rule;
38 1
        $this->mandatory = $mandatory;
39 1
    }
40
41
    /**
42
     * @param string $input
43
     *
44
     * @return bool
45
     */
46
    abstract protected function hasReference($input, $reference): bool;
47
48
    /**
49
     * @param string $input
50
     *
51
     * @return mixed
52
     */
53
    abstract protected function getReferenceValue($input, $reference);
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 16
    public function validate($input): Result
59
    {
60 16
        $properties = ['reference' => $this->reference, 'mandatory' => $this->mandatory];
61
62 16
        if (!$this->hasReference($input, $this->reference)) {
63 6
            return new Result(!$this->mandatory, $input, $this, $properties);
64
        }
65
66 10
        if ($this->rule === null) {
67 3
            return new Result(true, $input, $this, $properties);
68
        }
69
70 7
        $referenceValue = $this->getReferenceValue($input, $this->reference);
71 7
        $referenceValueResult = $this->rule->validate($referenceValue);
72
73 7
        return new Result($referenceValueResult->isValid(), $input, $this, $properties, $referenceValueResult);
74
    }
75
}
76