Completed
Push — master ( 53ce3b...45b5c0 )
by Mike
153:15 queued 138:20
created

Validator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Mediadevs\Validator;
4
5
use Mediadevs\Validator\Factories\FilterFactory;
6
7
class Validator
8
{
9
    /**
10
     * The validation results will be stored in here
11
     * @var array
12
     */
13
    private $results = array();
14
15
    /**
16
     * Validating all the values and applying all the assigned filters
17
     *
18
     * @param array $request
19
     * @param array $configuration
20
     *
21
     * @return array
22
     */
23
    public function validate(array $request, array $configuration = array()): array
24
    {
25
        $factory    = new FilterFactory();
26
        $arguments  = new Arguments();
0 ignored issues
show
Bug introduced by
The type Mediadevs\Validator\Arguments was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
28
        // Parsing through all the fields
29
        foreach ($arguments->getArguments($configuration) as $config) {
30
            // Assigning the variables for the factory
31
            $filter     = $config['filter'];
32
            $thresholds = $config['thresholds'];
33
            $field      = $config['field'];
34
35
            // Making sure $values is an array
36
            $values = is_array($request[$field]) ? $request[$field] : array($request[$field]);
37
38
            // Getting the configuration for the filter
39
            $results = $factory->build($filter, $values, $thresholds);
40
41
            // Creating a validation config for the current operation
42
            $this->results[] = [
43
                'valid'         => (bool)   $results,
44
                'field'         => (string) $field,
45
                'filter'        => (string) $filter,
46
                'values'        => (array)  $values,
47
                'thresholds'    => (array)  $thresholds,
48
            ];
49
        }
50
51
        return $this->results;
52
    }
53
}
54