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
04: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 Method

Rating   Name   Duplication   Size   Complexity  
AbstractRelated::getReferenceValue() 0 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
/**
18
 * @author Alexandre Gomes Gaigalas <[email protected]>
19
 * @author Henrique Moody <[email protected]>
20
 *
21
 * @since 0.3.9
22
 */
23
abstract class AbstractRelated implements Rule
24
{
25
    /**
26
     * @var string
27
     */
28
    private $reference;
29
30
    /**
31
     * @var Rule|null
32
     */
33
    private $rule;
34
35
    /**
36
     * @var bool
37
     */
38
    private $mandatory = true;
39
40 1
    public function __construct($reference, Rule $rule = null, bool $mandatory = true)
41
    {
42 1
        $this->reference = $reference;
43 1
        $this->rule = $rule;
44 1
        $this->mandatory = $mandatory;
45 1
    }
46
47
    /**
48
     * @param string $input
49
     *
50
     * @return bool
51
     */
52
    abstract protected function hasReference($input, $reference): bool;
53
54
    /**
55
     * @param string $input
56
     *
57
     * @return mixed
58
     */
59
    abstract protected function getReferenceValue($input, $reference);
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 21
    public function validate($input): Result
65
    {
66 21
        $properties = ['reference' => $this->reference, 'mandatory' => $this->mandatory];
67
68 21
        if (!$this->hasReference($input, $this->reference)) {
69 8
            return new Result(!$this->mandatory, $input, $this, $properties);
70
        }
71
72 13
        if ($this->rule === null) {
73 4
            return new Result(true, $input, $this, $properties);
74
        }
75
76 9
        $referenceValue = $this->getReferenceValue($input, $this->reference);
77 9
        $referenceValueResult = $this->rule->validate($referenceValue);
78
79 9
        return new Result($referenceValueResult->isValid(), $input, $this, $properties, $referenceValueResult);
80
    }
81
}
82