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 — 1.1 (#1169)
by Henrique
02:59
created

AbstractRelated   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 82.86%

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 2
dl 0
loc 76
ccs 29
cts 35
cp 0.8286
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
hasReference() 0 1 ?
getReferenceValue() 0 1 ?
A decision() 0 6 4
A check() 0 9 3
A validate() 0 9 3
A __construct() 0 11 3
A setName() 0 10 2
A assert() 0 15 4
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\Exceptions\ValidationException;
15
use Respect\Validation\Validatable;
16
17
abstract class AbstractRelated extends AbstractRule
18
{
19
    public $mandatory = true;
20
    public $reference = '';
21
    public $validator;
22
23
    abstract public function hasReference($input);
24
25
    abstract public function getReferenceValue($input);
26
27 12
    public function __construct($reference, Validatable $validator = null, $mandatory = true)
28
    {
29 12
        $this->setName($reference);
30 12
        if ($validator && !$validator->getName()) {
31 7
            $validator->setName($reference);
32
        }
33
34 12
        $this->reference = $reference;
35 12
        $this->validator = $validator;
36 12
        $this->mandatory = $mandatory;
37 12
    }
38
39 5
    public function setName($name)
40
    {
41 5
        parent::setName($name);
42
43 5
        if ($this->validator instanceof Validatable) {
44
            $this->validator->setName($name);
45
        }
46
47 5
        return $this;
48
    }
49
50 3
    private function decision($type, $hasReference, $input)
51
    {
52 3
        return (!$this->mandatory && !$hasReference)
53 3
            || (is_null($this->validator)
54 3
                || $this->validator->$type($this->getReferenceValue($input)));
55
    }
56
57 1
    public function assert($input)
58
    {
59 1
        $hasReference = $this->hasReference($input);
60 1
        if ($this->mandatory && !$hasReference) {
61
            throw $this->reportError($input, ['hasReference' => false]);
62
        }
63
64
        try {
65 1
            return $this->decision('assert', $hasReference, $input);
66
        } catch (ValidationException $e) {
67
            throw $this
68
                ->reportError($this->reference, ['hasReference' => true])
69
                ->addRelated($e);
70
        }
71
    }
72
73 1
    public function check($input)
74
    {
75 1
        $hasReference = $this->hasReference($input);
76 1
        if ($this->mandatory && !$hasReference) {
77
            throw $this->reportError($input, ['hasReference' => false]);
78
        }
79
80 1
        return $this->decision('check', $hasReference, $input);
81
    }
82
83 2
    public function validate($input)
84
    {
85 2
        $hasReference = $this->hasReference($input);
86 2
        if ($this->mandatory && !$hasReference) {
87 1
            return false;
88
        }
89
90 1
        return $this->decision('validate', $hasReference, $input);
91
    }
92
}
93