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
03:00
created

Zend   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 53
ccs 22
cts 24
cp 0.9167
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 1
A __construct() 0 24 5
A assert() 0 15 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 ReflectionClass;
15
use Respect\Validation\Exceptions\ComponentException;
16
17
class Zend extends AbstractRule
18
{
19
    protected $messages = [];
20
    protected $zendValidator;
21
22 9
    public function __construct($validator, $params = [])
23
    {
24 9
        if (is_object($validator)) {
25 2
            return $this->zendValidator = $validator;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
26
        }
27
28 7
        if (!is_string($validator)) {
29
            throw new ComponentException('Invalid Validator Construct');
30
        }
31
32 7
        if (false === stripos($validator, 'Zend')) {
33 6
            $validator = "Zend\\Validator\\{$validator}";
34
        } else {
35 1
            $validator = "\\{$validator}";
36
        }
37
38 7
        $zendMirror = new ReflectionClass($validator);
39
40 7
        if ($zendMirror->hasMethod('__construct')) {
41 7
            $this->zendValidator = $zendMirror->newInstanceArgs($params);
42
        } else {
43
            $this->zendValidator = $zendMirror->newInstance();
44
        }
45 7
    }
46
47 3
    public function assert($input)
48
    {
49 3
        $validator = clone $this->zendValidator;
50
51 3
        if ($validator->isValid($input)) {
52 1
            return true;
53
        }
54
55 2
        $exceptions = [];
56 2
        foreach ($validator->getMessages() as $m) {
57 2
            $exceptions[] = $this->reportError($m, get_object_vars($this));
58
        }
59
60 2
        throw $this->reportError($input)->setRelated($exceptions);
61
    }
62
63 3
    public function validate($input)
64
    {
65 3
        $validator = clone $this->zendValidator;
66
67 3
        return $validator->isValid($input);
68
    }
69
}
70