Passed
Push — master ( ece31d...41b8a6 )
by Paul
10:20 queued 04:17
created

ReviewHtml::__get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 6
rs 10
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Html;
4
5
use ArrayObject;
6
use GeminiLabs\SiteReviews\Review;
7
8
class ReviewHtml extends ArrayObject
9
{
10
    /**
11
     * @var Review
12
     */
13
    public $review;
14
15
    /**
16
     * @var array
17
     */
18
    public $values;
19
20
    public function __construct(Review $review, array $values = [])
21
    {
22
        $this->review = $review;
23
        $this->values = $values;
24
        parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
25
    }
26
27
    /**
28
     * @return string|void
29
     */
30
    public function __toString()
31
    {
32
        if (empty($this->values)) {
33
            return;
34
        }
35
        return glsr(Template::class)->build('templates/review', [
36
            'context' => $this->values,
37
            'review' => $this->review,
38
        ]);
39
    }
40
41
    /**
42
     * @param mixed $key
43
     * @return mixed
44
     */
45
    public function offsetGet($key)
46
    {
47
        if (property_exists($this, $key)) {
48
            return $this->$key;
49
        }
50
        return array_key_exists($key, $this->values)
51
            ? $this->values[$key]
52
            : null;
53
    }
54
}
55