Cast::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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