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

Reviews   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 17
c 2
b 1
f 0
dl 0
loc 62
ccs 0
cts 28
cp 0
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A build() 0 4 1
A __toString() 0 3 1
A render() 0 3 1
A offsetGet() 0 8 3
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
    {
58
        if (property_exists($this, $key)) {
59
            return $this->$key;
60
        }
61
        return array_key_exists($key, $this->reviews)
62
            ? $this->reviews[$key]
63
            : null;
64
    }
65
66
    /**
67
     * @return void
68
     */
69
    public function render()
70
    {
71
        echo $this->build();
72
    }
73
}
74