BooleanEncoder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultOptions() 0 3 1
A encode() 0 7 4
A supports() 0 3 1
1
<?php
2
3
namespace Riimu\Kit\PHPEncoder\Encoder;
4
5
/**
6
 * Encoder for boolean values.
7
 * @author Riikka Kalliomäki <[email protected]>
8
 * @copyright Copyright (c) 2014-2020 Riikka Kalliomäki
9
 * @license http://opensource.org/licenses/mit-license.php MIT License
10
 */
11
class BooleanEncoder implements Encoder
12
{
13
    /** @var array Default values for options in the encoder */
14
    private static $defaultOptions = [
15
        'boolean.capitalize' => false,
16
    ];
17
18
    public function getDefaultOptions()
19
    {
20
        return self::$defaultOptions;
21
    }
22
23
    public function supports($value)
24
    {
25
        return \is_bool($value);
26
    }
27
28
    public function encode($value, $depth, array $options, callable $encode)
29
    {
30
        if ($options['boolean.capitalize']) {
31
            return $value ? 'TRUE' : 'FALSE';
32
        }
33
34
        return $value ? 'true' : 'false';
35
    }
36
}
37