Completed
Push — master ( 618cc4...aeb328 )
by Neomerx
02:39
created

ValidatorTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 22
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateData() 0 12 3
1
<?php namespace Limoncello\Validation\Validator;
2
3
/**
4
 * Copyright 2015-2016 [email protected] (www.neomerx.com)
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 Generator;
20
use Limoncello\Validation\Contracts\ErrorAggregatorInterface;
21
use Limoncello\Validation\Contracts\RuleInterface;
22
23
/**
24
 * @package Limoncello\Validation
25
 */
26
trait ValidatorTrait
27
{
28
    /**
29
     * @param RuleInterface            $rule
30
     * @param mixed                    $input
31
     * @param ErrorAggregatorInterface $aggregator
32
     *
33
     * @return Generator
34
     */
35 33
    protected static function validateData(RuleInterface $rule, $input, ErrorAggregatorInterface $aggregator)
36
    {
37 33
        foreach ($rule->validate($input) as $error) {
38 29
            yield $error;
39
        };
40
41 33
        $rule->onFinish($aggregator);
42
43 33
        foreach ($aggregator->get() as $error) {
44 4
            yield $error;
45
        }
46 33
    }
47
}
48