Completed
Pull Request — master (#244)
by Łukasz
11:47
created

Callback::format()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace FSi\Bundle\AdminBundle\Display\Property\Formatter;
11
12
use FSi\Bundle\AdminBundle\Display\Property\ValueFormatter;
13
14
class Callback implements ValueFormatter
15
{
16
    /**
17
     * @var \Closure
18
     */
19
    private $closure;
20
21
    /**
22
     * @param callable $closure
23
     */
24
    public function __construct(\Closure $closure)
25
    {
26
        $this->closure = $closure;
27
    }
28
29
    /**
30
     * @param mixed $value
31
     * @return mixed
32
     */
33
    public function format($value)
34
    {
35
        if (empty($value)) {
36
            return $value;
37
        }
38
39
        $closure = $this->closure;
40
41
        return $closure($value);
42
    }
43
}
44