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
Push — 2.0 ( 7d4223 )
by Henrique
05:27
created

AbstractRelated::assert()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 6

Importance

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