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 (#1036)
by Henrique
06:46
created

Each::assert()   B

Complexity

Conditions 8
Paths 21

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 8

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 19
cts 19
cp 1
rs 8.1635
c 0
b 0
f 0
cc 8
nc 21
nop 1
crap 8
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 7
    public function __construct(Validatable $itemValidator = null, Validatable $keyValidator = null)
23
    {
24 7
        $this->itemValidator = $itemValidator;
25 7
        $this->keyValidator = $keyValidator;
26 7
    }
27
28 6
    public function assert($input)
29
    {
30 6
        $exceptions = [];
31
32 6
        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 1
            throw $this->reportError($input);
34
        }
35
36 5
        foreach ($input as $key => $item) {
37 5
            if (isset($this->itemValidator)) {
38
                try {
39 3
                    $this->itemValidator->assert($item);
40 3
                } catch (ValidationException $e) {
41 1
                    $exceptions[] = $e;
42
                }
43 3
            }
44
45 5
            if (isset($this->keyValidator)) {
46
                try {
47 3
                    $this->keyValidator->assert($key);
48 3
                } catch (ValidationException $e) {
49 1
                    $exceptions[] = $e;
50
                }
51 3
            }
52 5
        }
53
54 5
        if (!empty($exceptions)) {
55 2
            throw $this->reportError($input)->setRelated($exceptions);
56
        }
57
58 3
        return true;
59
    }
60
61 4
    public function check($input)
62
    {
63 4
        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 1
            throw $this->reportError($input);
65
        }
66
67 3
        foreach ($input as $key => $item) {
68 3
            if (isset($this->itemValidator)) {
69 2
                $this->itemValidator->check($item);
70 2
            }
71
72 3
            if (isset($this->keyValidator)) {
73 2
                $this->keyValidator->check($key);
74 2
            }
75 3
        }
76
77 3
        return true;
78
    }
79
80 11
    public function validate($input)
81
    {
82 11
        if (!parent::validate($input)) {
83 4
            return false;
84
        }
85
86 7
        foreach ($input as $key => $item) {
87 7
            if (isset($this->itemValidator) && !$this->itemValidator->validate($item)) {
88 1
                return false;
89
            }
90
91 6
            if (isset($this->keyValidator) && !$this->keyValidator->validate($key)) {
92 1
                return false;
93
            }
94 5
        }
95
96 5
        return true;
97
    }
98
}
99