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

Reviews::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 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 5
c 1
b 1
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;
4
5
use ArrayObject;
6
use GeminiLabs\SiteReviews\Defaults\SiteReviewsDefaults;
7
use GeminiLabs\SiteReviews\Modules\Html\Partials\SiteReviews as SiteReviewsPartial;
8
use GeminiLabs\SiteReviews\Modules\Html\ReviewsHtml;
9
10
class Reviews extends ArrayObject
11
{
12
	/**
13
	 * @var array
14
	 */
15
	public $args;
16
17
	/**
18
	 * @var int
19
	 */
20
	public $max_num_pages;
21
22
	/**
23
	 * @var array
24
	 */
25
	public $reviews;
26
27
	public function __construct( array $reviews, $maxPageCount, array $args )
28
	{
29
		$this->args = $args;
30
		$this->max_num_pages = $maxPageCount;
31
		$this->reviews = $reviews;
32
		parent::__construct( $reviews, ArrayObject::STD_PROP_LIST|ArrayObject::ARRAY_AS_PROPS );
33
	}
34
35
	/**
36
	 * @return string
37
	 */
38
	public function __toString()
39
	{
40
		return (string)$this->build();
41
	}
42
43
	/**
44
	 * @return ReviewsHtml
45
	 */
46
	public function build()
47
	{
48
		$args = glsr( SiteReviewsDefaults::class )->merge( $this->args );
49
		return glsr( SiteReviewsPartial::class )->build( $args, $this );
50
	}
51
52
	/**
53
	 * @param mixed $key
54
	 * @return mixed
55
	 */
56
	public function offsetGet( $key ) {
57
		if( property_exists( $this, $key )) {
58
			return $this->key;
0 ignored issues
show
Bug Best Practice introduced by
The property key does not exist on GeminiLabs\SiteReviews\Reviews. Did you maybe forget to declare it?
Loading history...
59
		}
60
		return array_key_exists( $key, $this->reviews )
61
			? $this->reviews[$key]
62
			: null;
63
	}
64
65
	/**
66
	 * @return void
67
	 */
68
	public function render()
69
	{
70
		echo $this->build();
71
	}
72
}
73