Completed
Pull Request — master (#143)
by Alexander
05:04
created

ObjectModel::next()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Yandex PHP Library
4
 *
5
 * @copyright NIX Solutions Ltd.
6
 * @link https://github.com/nixsolutions/yandex-php-library
7
 */
8
9
/**
10
 * @namespace
11
 */
12
namespace Yandex\Common;
13
14
/**
15
 * Class ObjectModel
16
 * @package Yandex\Common
17
 */
18
class ObjectModel extends Model implements \Iterator, \Countable
19
{
20
    protected $collection = [];
21
    protected $innerCounter = -1;
22
23 41
    public function current()
24
    {
25 41
        if (is_array(current($this->collection))) {
26
            return new ObjectModel(current($this->collection));
27
        }
28
29 41
        return current($this->collection);
30
    }
31
32 26
    public function next()
33
    {
34 26
        $this->innerCounter++;
35 26
        return next($this->collection);
36
    }
37
38 1
    public function key()
39
    {
40 1
        return key($this->collection);
41
    }
42
43 1
    public function valid()
44
    {
45 1
        return $this->innerCounter < count($this->collection);
46
    }
47
48 1
    public function rewind()
49
    {
50 1
        $this->innerCounter = 0;
51 1
        reset($this->collection);
52 1
        return;
53
    }
54
55
    public function count()
56
    {
57
        return count($this->collection);
58
    }
59
}
60