Cast   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace Mvkasatkin\typecast;
4
5
use Mvkasatkin\typecast\type\CastInterface;
6
7
class Cast
8
{
9
    const INT = 'type_int';
10
    const BOOL = 'type_bool';
11
    const FLOAT = 'type_float';
12
    const STRING = 'type_string';
13
    const BINARY = 'type_binary';
14
    const OBJECT = 'type_object';
15
    const UNSET = 'type_unset';
16
    const ARRAY = 'type_array';
17
18
    const TYPES = [self::INT, self::BOOL, self::FLOAT, self::STRING,
19
        self::BINARY, self::OBJECT, self::UNSET, self::ARRAY];
20
21
    /**
22
     * @var CastInterface
23
     */
24
    protected $type;
25
26
    /**
27
     * @param CastInterface $type
28
     */
29
    public function __construct(CastInterface $type)
30
    {
31
        $this->type = $type;
32
    }
33
34
    /**
35
     * @param $value
36
     *
37
     * @return mixed|null
38
     */
39
    public function process($value)
40
    {
41
        return $this->type->cast($value);
42
    }
43
}
44