Callback::format()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 4
c 2
b 1
f 0
dl 0
loc 9
rs 10
cc 2
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
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminBundle\Display\Property\Formatter;
13
14
use FSi\Bundle\AdminBundle\Display\Property\ValueFormatter;
15
16
class Callback implements ValueFormatter
17
{
18
    /**
19
     * @var callable
20
     */
21
    private $callable;
22
23
    /**
24
     * @param callable $callable
25
     */
26
    public function __construct(callable $callable)
27
    {
28
        $this->callable = $callable;
29
    }
30
31
    /**
32
     * @param mixed $value
33
     * @return mixed
34
     */
35
    public function format($value)
36
    {
37
        if (empty($value)) {
38
            return $value;
39
        }
40
41
        $callable = $this->callable;
42
43
        return $callable($value);
44
    }
45
}
46