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::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 12
     */
28
    private $reference;
29 12
30 12
    /**
31 7
     * @var Rule|null
32
     */
33
    private $rule;
34 12
35 12
    /**
36 12
     * @var bool
37 12
     */
38
    private $mandatory = true;
39 5
40
    public function __construct($reference, Rule $rule = null, bool $mandatory = true)
41 5
    {
42
        $this->reference = $reference;
43 5
        $this->rule = $rule;
44
        $this->mandatory = $mandatory;
45
    }
46
47 5
    /**
48
     * @param string $input
49
     *
50 3
     * @return bool
51
     */
52 3
    abstract protected function hasReference($input, $reference): bool;
53 3
54 3
    /**
55
     * @param string $input
56
     *
57 1
     * @return mixed
58
     */
59 1
    abstract protected function getReferenceValue($input, $reference);
60 1
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function validate($input): Result
65 1
    {
66
        $properties = ['reference' => $this->reference, 'mandatory' => $this->mandatory];
67
68
        if (!$this->hasReference($input, $this->reference)) {
69
            return new Result(!$this->mandatory, $input, $this, $properties);
70
        }
71
72
        if ($this->rule === null) {
73 1
            return new Result(true, $input, $this, $properties);
74
        }
75 1
76 1
        $referenceValue = $this->getReferenceValue($input, $this->reference);
77
        $referenceValueResult = $this->rule->validate($referenceValue);
78
79
        return new Result($referenceValueResult->isValid(), $input, $this, $properties, $referenceValueResult);
80 1
    }
81
}
82