Coasters::rewind()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Thepixeldeveloper\Nolimits2PackageLoader;
4
5
use Countable;
6
use Iterator;
7
use SimpleXMLElement;
8
9
/**
10
 * Class Coasters
11
 * @package Thepixeldeveloper\Nolimits2PackageLoader
12
 */
13
class Coasters implements Iterator, Countable
14
{
15
    /**
16
     * @var int
17
     */
18
    protected $position = 0;
19
20
    /**
21
     * @var SimpleXMLElement
22
     */
23
    protected $parkXML;
24
25
    /**
26
     * @var Styles
27
     */
28
    protected $styles;
29
30
    /**
31
     * Coasters constructor.
32
     * @param SimpleXMLElement $parkXML
33
     * @param Styles $styles
34
     */
35
    public function __construct(SimpleXMLElement $parkXML, Styles $styles)
36
    {
37
        $this->parkXML = $parkXML;
38
        $this->styles = $styles;
39
    }
40
41
    /**
42
     * @return Coaster
43
     */
44
    public function current()
45
    {
46
        return new Coaster($this->parkXML->coaster[$this->position], $this->styles);
47
    }
48
49
    /**
50
     *
51
     */
52
    public function next()
53
    {
54
        $this->position++;
55
    }
56
57
    /**
58
     * @return int
59
     */
60
    public function key()
61
    {
62
        return $this->position;
63
    }
64
65
    /**
66
     * @return bool
67
     */
68
    public function valid()
69
    {
70
        return isset($this->parkXML->coaster[$this->position]);
71
    }
72
73
    /**
74
     *
75
     */
76
    public function rewind()
77
    {
78
        $this->position--;
79
    }
80
81
    /**
82
     * @return int
83
     */
84
    public function count()
85
    {
86
        return count($this->parkXML->coaster);
87
    }
88
}
89