PrivateStrictGetter::__get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Teto\Object;
4
5
/**
6
 * Private property behaves like read only.
7
 *
8
 * NOTICE: You may not be able to imagine the behavior of this trait in the inherited class.
9
 *
10
 * @see \Teto\Object\PrivateGetterTest
11
 *
12
 * @author    USAMI Kenta <[email protected]>
13
 * @copyright 2016 Baguette HQ
14
 * @license   http://www.apache.org/licenses/LICENSE-2.0
15
 */
16
trait PrivateStrictGetter
17
{
18 13
    public function __get($name)
19
    {
20 13
        if (property_exists($this, $name)) {
21 7
            return $this->$name;
22
        }
23
24 6
        throw new \OutOfRangeException("Unexpected key:'$name'");
25
    }
26
27 3
    public function __isset($name)
28
    {
29 3
        return isset($this->$name);
30
    }
31
}
32