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

Callback   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A format() 0 10 2
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