TrackCollection::assertThatTheseAreAllTracks()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 6

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.2
c 0
b 0
f 0
ccs 5
cts 10
cp 0.5
cc 4
eloc 7
nc 3
nop 1
crap 6
1
<?php
2
3
namespace HansOtt\Lastify;
4
5
use Iterator;
6
7
final class TrackCollection implements Iterator
8
{
9
    private $tracks;
10
11
    private $position = 0;
12
13
    /**
14
     * TrackCollection constructor.
15
     *
16
     * @param array $tracks An array of TrackInfo objects.
17
     */
18 6
    public function __construct(array $tracks = [])
19
    {
20 6
        $this->assertThatTheseAreAllTracks($tracks);
21 6
        $this->tracks = $tracks;
22 6
    }
23
24 6 View Code Duplication
    private function assertThatTheseAreAllTracks(array $tracks)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26 6
        foreach ($tracks as $track) {
27 6
            if (! ($track instanceof TrackInfo)) {
28
                throw new \InvalidArgumentException(sprintf(
29
                    'Expected "%s", but instead got: "%s"',
30
                    TrackInfo::class,
31
                    is_object($track) ? get_class($track) : gettype($track)
32
                ));
33
            }
34 6
        }
35 6
    }
36
37
    public function current()
38
    {
39
        return $this->tracks[$this->position];
40
    }
41
42
    public function next()
43
    {
44
        $this->position++;
45
    }
46
47
    public function key()
48
    {
49
        return $this->position;
50
    }
51
52
    public function valid()
53
    {
54
        return isset($this->tracks[$this->position]);
55
    }
56
57
    public function rewind()
58
    {
59
        $this->position = 0;
60
    }
61
62
    /**
63
     * Create a sync progress.
64
     *
65
     * @param SyncProgressCallback|null $callback
66
     *
67
     * @return SyncProgress
68
     */
69 3
    public function createSyncProgress(SyncProgressCallback $callback = null)
70
    {
71 3
        $total = count($this->tracks);
72
73 3
        return new SyncProgress(0, $total, $callback);
74
    }
75
}
76