Completed
Push — master ( 2a86f1...70e886 )
by Lars
02:23 queued 10s
created

ArrayyIterator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arrayy;
6
7
/**
8
 * Class ArrayyIterator
9
 */
10
class ArrayyIterator extends \ArrayIterator
11
{
12
    /**
13
     * @var string
14
     */
15
    private $class;
16
17
    /**
18
     * @param array  $array
19
     * @param int    $flags
20
     * @param string $class
21
     */
22 22
    public function __construct(array $array = [], int $flags = 0, string $class = '')
23
    {
24 22
        $this->class = $class;
25
26 22
        parent::__construct($array, $flags);
27 22
    }
28
29
    /**
30
     * @return Arrayy|mixed will return a "Arrayy"-object instead of an array
31
     */
32 21 View Code Duplication
    public function current()
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...
33
    {
34 21
        $value = parent::current();
35
36 21
        if (\is_array($value)) {
37 2
            $value = call_user_func([$this->class, 'create'], $value);
38
        }
39
40 21
        return $value;
41
    }
42
43
    /**
44
     * @param string $offset
45
     *
46
     * @return Arrayy|mixed will return a "Arrayy"-object instead of an array
47
     */
48 View Code Duplication
    public function offsetGet($offset)
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...
49
    {
50
        $value = parent::offsetGet($offset);
51
52
        if (\is_array($value)) {
53
            $value = call_user_func([$this->class, 'create'], $value);
54
        }
55
56
        return $value;
57
    }
58
}
59