Translations   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 79
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A current() 0 4 1
A next() 0 4 1
A key() 0 4 1
A valid() 0 4 1
A rewind() 0 4 1
A count() 0 4 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\File\FileInterface;
17
use Amplexor\XConnect\Response\Translation;
18
19
/**
20
 * Class representing a collection of translations.
21
 */
22
class Translations implements \Iterator, \Countable
23
{
24
    /**
25
     * The collection.
26
     *
27
     * @var Translation[]
28
     */
29
    private $translations = [];
30
31
    /**
32
     * The current item pointer.
33
     *
34
     * @var int
35
     */
36
    private $pointer = 0;
37
38
39
    /**
40
     * Construct the translations collection from the info file.
41
     *
42
     * @param FileInterface $file
43
     *   The Response file object.
44
     */
45 12
    public function __construct(FileInterface $file)
46
    {
47 12
        $infoFiles = $file->getInfo()->getFiles();
48 12
        foreach ($infoFiles as $infoFile) {
49 9
            $this->translations[] = new Translation($file, $infoFile);
50 12
        }
51 12
    }
52
53
    /**
54
     * Get the current translation.
55
     */
56 3
    public function current()
57
    {
58 3
        return $this->translations[$this->pointer];
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64 3
    public function next()
65
    {
66 3
        $this->pointer++;
67 3
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72 3
    public function key()
73
    {
74 3
        return $this->pointer;
75
    }
76
77
    /**
78
     * @inheritDoc
79
     */
80 3
    public function valid()
81
    {
82 3
        return array_key_exists($this->pointer, $this->translations);
83
    }
84
85
    /**
86
     * @inheritDoc
87
     */
88 3
    public function rewind()
89
    {
90 3
        $this->pointer = 0;
91 3
    }
92
93
    /**
94
     * @inheritDoc
95
     */
96 9
    public function count()
97
    {
98 9
        return count($this->translations);
99
    }
100
}
101