EpisodeCollection   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 15
eloc 21
dl 0
loc 75
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A hasNextPage() 0 2 1
A next() 0 2 1
A current() 0 2 1
A offsetExists() 0 2 1
A __construct() 0 3 1
A key() 0 2 1
A offsetSet() 0 5 2
A rewind() 0 2 1
A nextPage() 0 2 1
A offsetGet() 0 2 2
A offsetUnset() 0 2 1
A count() 0 3 1
A valid() 0 2 1
1
<?php
2
3
namespace musa11971\TVDB;
4
5
use ArrayAccess;
6
use Countable;
7
use Iterator;
8
9
class EpisodeCollection implements ArrayAccess, Iterator, Countable {
10
    public $page;
11
    public $episodes;
12
    protected $iteratorPosition = 0;
13
14
    public function __construct($page, $episodes) {
15
        $this->page = $page;
16
        $this->episodes = $episodes;
17
    }
18
19
    /**
20
     * Checks whether or not the episode collection has a follow-up page
21
     * .. with more results
22
     *
23
     * @return bool
24
     */
25
    public function hasNextPage() {
26
        return (count($this->episodes) >= TVDB::EPISODES_PER_PAGE);
27
    }
28
29
    /**
30
     * Returns the page number of the next page
31
     *
32
     * @return int
33
     */
34
    public function nextPage() {
35
        return ($this->page + 1);
36
    }
37
38
    /** Method from interface Countable */
39
    public function count()
40
    {
41
        return count($this->episodes);
42
    }
43
44
    /** Methods from interface ArrayAccess */
45
    public function offsetSet($offset, $value) {
46
        if(is_null($offset)) {
47
            $this->episodes[] = $value;
48
        } else {
49
            $this->episodes[$offset] = $value;
50
        }
51
    }
52
53
    public function offsetExists($offset) {
54
        return isset($this->episodes[$offset]);
55
    }
56
57
    public function offsetUnset($offset) {
58
        unset($this->episodes[$offset]);
59
    }
60
61
    public function offsetGet($offset) {
62
        return isset($this->episodes[$offset]) ? $this->episodes[$offset] : null;
63
    }
64
65
    /** Methods from interface Iterator */
66
    public function rewind() {
67
        $this->iteratorPosition = 0;
68
    }
69
70
    public function current() {
71
        return $this->episodes[$this->iteratorPosition];
72
    }
73
74
    public function key() {
75
        return $this->iteratorPosition;
76
    }
77
78
    public function next() {
79
        ++$this->iteratorPosition;
80
    }
81
82
    public function valid() {
83
        return isset($this->episodes[$this->iteratorPosition]);
84
    }
85
}