Completed
Push — master ( 366fbf...5f1478 )
by Rafael
02:45
created

CallableParser::toObjectValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 4
1
<?php
2
3
/**
4
 * LICENSE: This file is subject to the terms and conditions defined in
5
 * file 'LICENSE', which is part of this source code package.
6
 *
7
 * @copyright 2016 Copyright(c) - All rights reserved.
8
 */
9
10
namespace Rafrsr\LibArray2Object\Parser;
11
12
/**
13
 * Class CallableParser
14
 */
15
class CallableParser implements ValueParserInterface
16
{
17
    /**
18
     * @var callable
19
     */
20
    protected $parserCallback;
21
22
    /**
23
     * CallableParser constructor.
24
     *
25
     * @param callable $parserCallback
26
     */
27
    public function __construct(callable $parserCallback)
28
    {
29
        $this->parserCallback = $parserCallback;
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35
    public function getName()
36
    {
37
        //unique name for each callback
38
        return spl_object_hash($this->parserCallback);
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44
    public function toObjectValue($value, $type, \ReflectionProperty $property, $object)
45
    {
46
        return call_user_func($this->parserCallback, $value, $type, $property, $object);
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52
    public function toArrayValue($value, $type, \ReflectionProperty $property, $object)
53
    {
54
        return call_user_func($this->parserCallback, $value, $type, $property, $object);
55
    }
56
}