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   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 59
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
hasReference() 0 1 ?
getReferenceValue() 0 1 ?
A validate() 0 17 3
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