Completed
Push — master ( 983101...820d65 )
by Valentin
03:34
created

ArrayResponse   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 38.46%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
c 1
b 0
f 0
dl 0
loc 54
ccs 5
cts 13
cp 0.3846
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A _transformPropertyName() 0 3 1
A __isset() 0 5 1
A __get() 0 5 2
A __construct() 0 4 1
A getResponseName() 0 3 1
1
<?php
2
3
namespace Pheanstalk\Response;
4
5
use Pheanstalk\Response;
6
7
/**
8
 * A response with an ArrayObject interface to key => value data.
9
 *
10
 * @author  Paul Annesley
11
 * @package Pheanstalk
12
 * @license http://www.opensource.org/licenses/mit-license.php
13
 */
14
class ArrayResponse extends \ArrayObject implements Response
15
{
16
    private $_name;
17
18
    /**
19
     * @param string $name
20
     * @param array  $data
21
     */
22 5
    public function __construct($name, $data)
23
    {
24 5
        $this->_name = $name;
25 5
        parent::__construct($data);
26
    }
27
28
    /* (non-phpdoc)
29
     * @see Response::getResponseName()
30
     */
31 1
    public function getResponseName()
32
    {
33 1
        return $this->_name;
34
    }
35
36
    /**
37
     * Object property access to ArrayObject data.
38
     */
39
    public function __get($property)
40
    {
41
        $key = $this->_transformPropertyName($property);
42
43
        return isset($this[$key]) ? $this[$key] : null;
44
    }
45
46
    /**
47
     * Object property access to ArrayObject data.
48
     */
49
    public function __isset($property)
50
    {
51
        $key = $this->_transformPropertyName($property);
52
53
        return isset($this[$key]);
54
    }
55
56
    // ----------------------------------------
57
58
    /**
59
     * Tranform underscored property name to hyphenated array key.
60
     *
61
     * @param string
62
     *
63
     * @return string
64
     */
65
    private function _transformPropertyName($propertyName)
66
    {
67
        return str_replace('_', '-', $propertyName);
68
    }
69
}
70