Completed
Push — master ( 0da056...260312 )
by Aleksander
05:02
created

ObjectModel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.12%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
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
A count() 0 4 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 47
    public function current()
24
    {
25 47
        if (is_array(current($this->collection))) {
26
            return new ObjectModel(current($this->collection));
27
        }
28
29 47
        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 3
    public function valid()
44
    {
45 3
        return $this->innerCounter < count($this->collection);
46
    }
47
48 3
    public function rewind()
49
    {
50 3
        $this->innerCounter = 0;
51 3
        reset($this->collection);
52 3
        return;
53
    }
54
55 1
    public function count()
56
    {
57 1
        return count($this->collection);
58
    }
59
}
60