Validator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 34
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedTypes() 0 4 1
A register() 0 10 1
A __call() 0 13 3
1
<?php
2
3
namespace Almendra\Validators;
4
5
use Almendra\Validators\Interfaces\ValidatorInterface;
6
use Almendra\Validators\Traits\ArrayTrait;
7
8
/**
9
 * The validator.
10
 */
11
class Validator implements ValidatorInterface
12
{
13
    use ArrayTrait;
14
15
    public function getSupportedTypes()
16
    {
17
        return $this->register();
18
    }
19
20
    public function register()
21
    {
22
        return [
23
            \Almendra\Validators\Types\IntegerType::class => 'integer',
24
            \Almendra\Validators\Types\StringType::class => 'string',
25
            \Almendra\Validators\Types\FloatType::class => 'float',
26
            \Almendra\Validators\Types\DoubleType::class => 'double',
27
            \Almendra\Validators\Types\FileType::class => 'file',
28
        ];
29
    }
30
31
    public function __call($name, $values)
32
    {
33
        foreach ($this->register() as $type => $alias) {
34
            if ($alias == $name) {
35
                // call that method
36
                return $this->type = new $type(
0 ignored issues
show
Bug introduced by
The property type does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37
                    $this->toArray($values)
38
                    );
39
            }
40
        }
41
42
        throw new \Exception('The called method is not defined or unsupported');
43
    }
44
}
45