Boolean::format()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 3
c 2
b 1
f 0
dl 0
loc 7
rs 10
cc 4
nc 3
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 Boolean implements ValueFormatter
17
{
18
    /**
19
     * @var string
20
     */
21
    private $true;
22
23
    /**
24
     * @var string
25
     */
26
    private $false;
27
28
    public function __construct(string $true, string $false)
29
    {
30
        $this->true = $true;
31
        $this->false = $false;
32
    }
33
34
    /**
35
     * @param mixed $value
36
     * @return mixed|string
37
     */
38
    public function format($value)
39
    {
40
        if (empty($value) && !is_bool($value)) {
41
            return $value;
42
        }
43
44
        return $value ? $this->true : $this->false;
45
    }
46
}
47