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

ObjectModel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 82.35%

Importance

Changes 2
Bugs 1 Features 2
Metric Value
wmc 7
c 2
b 1
f 2
lcom 1
cbo 1
dl 0
loc 42
ccs 14
cts 17
cp 0.8235
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 4 1
A current() 0 8 2
A next() 0 5 1
A key() 0 4 1
A valid() 0 4 1
A rewind() 0 6 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