LegacyFormatter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 65
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setData() 0 4 1
A getData() 0 14 3
1
<?php
2
declare(strict_types = 1);
3
4
namespace BrowscapPHP\Formatter;
5
6
/**
7
 * formatter for backwards compatibility with 2.x
8
 */
9
final class LegacyFormatter implements FormatterInterface
10
{
11
    /**
12
     * Options for the formatter
13
     *
14
     * @var array
15
     */
16
    private $options = [];
17
18
    /**
19
     * Default formatter options
20
     *
21
     * @var array
22
     */
23
    private $defaultOptions = [
24
        'lowercase' => false,
25
    ];
26
27
    /**
28
     * Variable to save the settings in, type depends on implementation
29
     *
30
     * @var array
31
     */
32
    private $data = [];
33
34
    /**
35
     * LegacyFormatter constructor.
36
     *
37
     * @param array $options Formatter optioms
38
     */
39 2
    public function __construct(array $options = [])
40
    {
41 2
        $this->options = array_merge($this->defaultOptions, $options);
42 2
    }
43
44
    /**
45
     * Sets the data (done by the parser)
46
     *
47
     * @param array $settings
48
     */
49 2
    public function setData(array $settings) : void
50
    {
51 2
        $this->data = $settings;
52 2
    }
53
54
    /**
55
     * Gets the data (in the preferred format)
56
     *
57
     * @return \stdClass
58
     */
59 2
    public function getData() : \stdClass
60
    {
61 2
        $output = new \stdClass();
62
63 2
        foreach ($this->data as $key => $property) {
64 2
            if ($this->options['lowercase']) {
65 1
                $key = strtolower($key);
66
            }
67
68 2
            $output->{$key} = $property;
69
        }
70
71 2
        return $output;
72
    }
73
}
74