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

ArrayyIterator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 40.82 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 64.29%

Importance

Changes 0
Metric Value
dl 20
loc 49
ccs 9
cts 14
cp 0.6429
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A current() 10 10 2
A offsetGet() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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