Completed
Push — master ( 798002...e60177 )
by Neomerx
02:21
created

Validator::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php namespace Limoncello\Validation;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Validation\Contracts\Execution\ContextStorageInterface;
20
use Limoncello\Validation\Contracts\Rules\RuleInterface;
21
use Limoncello\Validation\Contracts\ValidatorInterface;
22
use Limoncello\Validation\Execution\ContextStorage;
23
use Limoncello\Validation\Validator\BaseValidator;
24
use Limoncello\Validation\Validator\SingleValidation;
25
26
/**
27
 * @package Limoncello\Validation
28
 */
29
class Validator extends BaseValidator
30
{
31
    use SingleValidation;
32
33
    /**
34
     * @param RuleInterface $rule
35
     */
36 4
    public function __construct(RuleInterface $rule)
37
    {
38 4
        parent::__construct();
39
40 4
        $this->setRule($rule);
41
    }
42
43
    /**
44
     * @param RuleInterface $rule
45
     *
46
     * @return ValidatorInterface
47
     */
48 4
    public static function validator(RuleInterface $rule): ValidatorInterface
49
    {
50 4
        $validator = new static ($rule);
51
52 4
        return $validator;
53
    }
54
55
    /**
56
     * @inheritdoc
57
     *
58
     * @SuppressWarnings(PHPMD.StaticAccess)
59
     */
60 4 View Code Duplication
    public function validate($input): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62 4
        if ($this->areAggregatorsDirty() === true) {
63 3
            $this->resetAggregators();
64
        }
65
66 4
        $this->validateImplementation($input, $this->getCaptures(), $this->getErrors());
67 4
        $this->markAggregatorsAsDirty();
68
69 4
        $noErrors = $this->getErrors()->count() <= 0;
70
71 4
        return $noErrors;
72
    }
73
74
    /**
75
     * @param array $blocks
76
     *
77
     * @return ContextStorageInterface
78
     */
79 4
    protected function createContextStorageFromBlocks(array $blocks): ContextStorageInterface
80
    {
81 4
        return new ContextStorage($blocks);
82
    }
83
}
84