Passed
Push — hotfix/fix-counts ( 673622...5fa6b5 )
by Paul
05:31
created

ReviewHtml::offsetGet()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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