Dataset::first()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
namespace MachineLearning\Domain\Model;
3
4
use MachineLearning\Domain\Hypothesis\HypothesisInterface;
5
6
class Dataset implements \Iterator, \Countable
7
{
8
    /**
9
     * @var array[]
10
     */
11
    protected $data;
12
13
    /**
14
     * @var int
15
     */
16
    protected $position;
17
18
    /**
19
     * @var HypothesisInterface
20
     */
21
    protected $hypothesis;
22
23
    /**
24
     * @param array[] $data
25
     */
26 2
    public function __construct(
27
        array $data,
28
        HypothesisInterface $hypothesis
29
    ) {
30 2
        $this->position = 0;
31 2
        $this->hypothesis = $hypothesis;
32 2
        $this->data = $data;
33 2
    }
34
35 1
    public function first()
36
    {
37 1
        return $this->hypothesis->createResultFromData(
38 1
            $this->data[0]
39 1
        );
40
    }
41
42
    /**
43
     * @return Result
44
     */
45 2
    public function current()
46
    {
47 2
        return $this->hypothesis->createResultFromData(
48 2
            $this->data[$this->position]
49 2
        );
50
    }
51
52 2
    public function next()
53
    {
54 2
        $this->position++;
55 2
    }
56
57
    public function key()
58
    {
59
        return $this->position;
60
    }
61
62 2
    public function valid()
63
    {
64 2
        return isset($this->data[$this->position]);
65
    }
66
67 2
    public function rewind()
68
    {
69 2
        $this->position = 0;
70 2
    }
71
72 2
    public function count()
73
    {
74 2
        return count($this->data);
75
    }
76
77
    /**
78
     * @return HypothesisInterface
79
     */
80 1
    public function getHypothesis()
81
    {
82 1
        return $this->hypothesis;
83
    }
84
85
}