InfoFiles::key()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the Amplexor\XConnect library
4
 *
5
 * @license http://opensource.org/licenses/MIT
6
 * @link https://github.com/amplexor-drupal/xconnect/
7
 * @version 1.0.0
8
 * @package Amplexor.XConnect
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Amplexor\XConnect\Response;
15
16
use Amplexor\XConnect\Response\InfoFile;
17
18
/**
19
 * Class representing a single delivery file details.
20
 */
21
class InfoFiles implements \Iterator, \Countable
22
{
23
    /**
24
     * The array collection.
25
     *
26
     * @var InfoFile[]
27
     */
28
    private $files = [];
29
30
    /**
31
     * The current item.
32
     *
33
     * @var int
34
     */
35
    private $pointer = 0;
36
37
    /**
38
     * Construct the object by passing the \SimpleXmlElement.
39
     *
40
     * @param \SimpleXmlElement $xml
41
     */
42 12
    public function __construct(\SimpleXMLElement $xml)
43
    {
44 12
        if (empty($xml)) {
45 6
            return;
46
        }
47
48
        // Single elements are by default not an array.
49 12
        if (1 < count($xml->DeliveryFile)) {
50 12
            foreach ($xml->DeliveryFile as $fileXml) {
51 12
                $this->files[] = new InfoFile($fileXml);
52 12
            }
53 12
            return;
54
        }
55
56
        // Add a single file to the collection.
57 3
        $this->files[] = new InfoFile($xml->DeliveryFile);
58 3
    }
59
60
    /**
61
     * Get the current file.
62
     *
63
     * @return InfoFile
64
     */
65 3
    public function current()
66
    {
67 3
        return $this->files[$this->pointer];
68
    }
69
70
    /**
71
     * @inheritDoc
72
     */
73 3
    public function next()
74
    {
75 3
        $this->pointer++;
76 3
    }
77
78
    /**
79
     * @inheritDoc
80
     */
81 3
    public function key()
82
    {
83 3
        return $this->pointer;
84
    }
85
86
    /**
87
     * @inheritDoc
88
     */
89 6
    public function valid()
90
    {
91 6
        return array_key_exists($this->pointer, $this->files);
92
    }
93
94
    /**
95
     * @inheritDoc
96
     */
97 3
    public function rewind()
98
    {
99 3
        $this->pointer = 0;
100 3
    }
101
102
    /**
103
     * @inheritDoc
104
     */
105 6
    public function count()
106
    {
107 6
        return count($this->files);
108
    }
109
}
110