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 ( e6a123...4184ab )
by Henrique
03:41
created

Each::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
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
class Each extends IterableType
18
{
19
    public $itemValidator;
20
    public $keyValidator;
21
22
    public function __construct(Validatable $itemValidator = null, Validatable $keyValidator = null)
23
    {
24
        $this->itemValidator = $itemValidator;
25
        $this->keyValidator = $keyValidator;
26
    }
27
28
    public function assert($input)
29
    {
30
        $exceptions = [];
31
32
        if (!parent::validate($input)) {
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (validate() instead of assert()). Are you sure this is correct? If so, you might want to change this to $this->validate().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
33
            throw $this->reportError($input);
34
        }
35
36
        foreach ($input as $key => $item) {
37
            if (isset($this->itemValidator)) {
38
                try {
39
                    $this->itemValidator->assert($item);
40
                } catch (ValidationException $e) {
41
                    $exceptions[] = $e;
42
                }
43
            }
44
45
            if (isset($this->keyValidator)) {
46
                try {
47
                    $this->keyValidator->assert($key);
48
                } catch (ValidationException $e) {
49
                    $exceptions[] = $e;
50
                }
51
            }
52
        }
53
54
        if (!empty($exceptions)) {
55
            throw $this->reportError($input)->setRelated($exceptions);
56
        }
57
58
        return true;
59
    }
60
61
    public function check($input)
62
    {
63
        if (!parent::validate($input)) {
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (validate() instead of check()). Are you sure this is correct? If so, you might want to change this to $this->validate().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
64
            throw $this->reportError($input);
65
        }
66
67
        foreach ($input as $key => $item) {
68
            if (isset($this->itemValidator)) {
69
                $this->itemValidator->check($item);
70
            }
71
72
            if (isset($this->keyValidator)) {
73
                $this->keyValidator->check($key);
74
            }
75
        }
76
77
        return true;
78
    }
79
80
    public function validate($input)
81
    {
82
        if (!parent::validate($input)) {
83
            return false;
84
        }
85
86
        foreach ($input as $key => $item) {
87
            if (isset($this->itemValidator) && !$this->itemValidator->validate($item)) {
88
                return false;
89
            }
90
91
            if (isset($this->keyValidator) && !$this->keyValidator->validate($key)) {
92
                return false;
93
            }
94
        }
95
96
        return true;
97
    }
98
}
99