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

Passed
Push — master ( 2ab1f1...70eb87 )
by Henrique
05:41
created

Zend::assert()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 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
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
use ReflectionClass;
17
use Respect\Validation\Exceptions\ComponentException;
18
19
class Zend extends AbstractRule
20
{
21
    protected $messages = [];
22
    protected $zendValidator;
23
24 9
    public function __construct($validator, $params = [])
25
    {
26 9
        if (is_object($validator)) {
27 2
            return $this->zendValidator = $validator;
28
        }
29
30 7
        if (!is_string($validator)) {
31
            throw new ComponentException('Invalid Validator Construct');
32
        }
33
34 7
        if (false === mb_stripos($validator, 'Zend')) {
35 6
            $validator = "Zend\\Validator\\{$validator}";
36
        } else {
37 1
            $validator = "\\{$validator}";
38
        }
39
40 7
        $zendMirror = new ReflectionClass($validator);
41
42 7
        if ($zendMirror->hasMethod('__construct')) {
43 7
            $this->zendValidator = $zendMirror->newInstanceArgs($params);
44
        } else {
45
            $this->zendValidator = $zendMirror->newInstance();
46
        }
47 7
    }
48
49 3
    public function assert($input): void
50
    {
51 3
        $validator = clone $this->zendValidator;
52
53 3
        if ($validator->isValid($input)) {
54 1
            return;
55
        }
56
57 2
        $exceptions = [];
58 2
        foreach ($validator->getMessages() as $m) {
59 2
            $exceptions[] = $this->reportError($m, get_object_vars($this));
60
        }
61
62 2
        throw $this->reportError($input)->setRelated($exceptions);
0 ignored issues
show
Bug introduced by
The method setRelated() does not exist on Respect\Validation\Exceptions\ValidationException. It seems like you code against a sub-type of Respect\Validation\Exceptions\ValidationException such as Respect\Validation\Excep...stedValidationException. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
        throw $this->reportError($input)->/** @scrutinizer ignore-call */ setRelated($exceptions);
Loading history...
63
    }
64
65 3
    public function validate($input): bool
66
    {
67 3
        $validator = clone $this->zendValidator;
68
69 3
        return $validator->isValid($input);
70
    }
71
}
72