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

ArrayResponse::__isset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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