Completed
Pull Request — master (#159)
by Ian
12:51
created

LegacyFormatter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 69
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setData() 0 6 1
A getData() 0 14 3
1
<?php
2
/**
3
 * Copyright (c) 1998-2015 Browser Capabilities Project
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 * copy of this software and associated documentation files (the "Software"),
7
 * to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
 * and/or sell copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included
13
 * in all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 *
23
 * @category   Browscap-PHP
24
 * @package    Formatter
25
 * @copyright  1998-2015 Browser Capabilities Project
26
 * @license    http://www.opensource.org/licenses/MIT MIT License
27
 * @link       https://github.com/browscap/browscap-php/
28
 * @since      added with version 3.0
29
 */
30
31
namespace BrowscapPHP\Formatter;
32
33
/**
34
 * formatter for backwards compatibility with 2.x
35
 *
36
 * @category   Browscap-PHP
37
 * @package    Formatter
38
 * @author     Christoph Ziegenberg <[email protected]>
39
 * @author     Thomas Müller <[email protected]>
40
 * @copyright  Copyright (c) 1998-2015 Browser Capabilities Project
41
 * @version    3.0
42
 * @license    http://www.opensource.org/licenses/MIT MIT License
43
 * @link       https://github.com/browscap/browscap-php/
44
 */
45
class LegacyFormatter implements FormatterInterface
46
{
47
    /**
48
     * Options for the formatter
49
     * 
50
     * @var array
51
     */
52
    private $options = array();
53
54
    /**
55
     * Default formatter options
56
     * 
57
     * @var array
58
     */
59
    private $defaultOptions = array(
60
        'lowercase' => false
61
    );
62
63
    /**
64
     * Variable to save the settings in, type depends on implementation
65
     *
66
     * @var array
67
     */
68
    private $settings = array();
69
70
    /**
71
     * LegacyFormatter constructor.
72
     * 
73
     * @param array $options Formatter optioms
74
     */
75 2
    public function __construct($options = array())
76
    {
77 2
        $this->options = array_merge($this->defaultOptions, $options);
78 2
    }
79
80
    /**
81
     * Sets the data (done by the parser)
82
     *
83
     * @param array $settings
84
     *
85
     * @return \BrowscapPHP\Formatter\PhpGetBrowser
86
     */
87 2
    public function setData(array $settings)
88
    {
89 2
        $this->settings = $settings;
90
91 2
        return $this;
92
    }
93
94
    /**
95
     * Gets the data (in the preferred format)
96
     *
97
     * @return \stdClass
98
     */
99 2
    public function getData()
100
    {
101 2
        $output = new \stdClass();
102
103 2
        foreach ($this->settings as $key => $property) {
104 2
            if ($this->options['lowercase']) {
105 1
                $key = strtolower($key);
106
            }
107
108 2
            $output->$key = $property;
109 2
        }
110
111 2
        return $output;
112
    }
113
}
114