Completed
Push — master ( 59d7ed...ae11c9 )
by Marcos
05:17
created

ArrayManipulator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 67.65 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 46
loc 68
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1
ccs 38
cts 38
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A append() 11 11 1
A setNestedValue() 12 12 2
A filter() 11 11 1
A unsetNestedValue() 12 12 2
A process() 0 7 1

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
namespace Uvinum\Joiner\Manipulator;
4
5
use League\Pipeline\Pipeline;
6
7
final class ArrayManipulator implements Manipulator
8
{
9
    /** @var Pipeline */
10
    private $pipeline;
11
12 15
    public function __construct()
13
    {
14 15
        $this->pipeline = new Pipeline();
15 15
    }
16
17 12 View Code Duplication
    public function append($key, $args)
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...
18
    {
19 12
        $this->pipeline = $this->pipeline->pipe(
20
            function ($serializedBase) use ($key, $args) {
21 12
                $keysDepth = \explode('>', $key);
22 12
                $this->setNestedValue($serializedBase, $keysDepth, $args);
23
24 12
                return $serializedBase;
25 8
            }
26 4
        );
27 12
    }
28
29 13 View Code Duplication
    private function setNestedValue(&$serializedBase, array $keysDepth, $value)
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...
30
    {
31 12
        $currentKey = \current($keysDepth);
32 12
        $nextKey    = \next($keysDepth);
33 12
        if (!$nextKey) {
34 12
            $serializedBase[\strtolower($currentKey)] = $value;
35
36 13
            return $serializedBase;
37
        }
38
39 3
        return $this->setNestedValue($serializedBase[\strtolower($currentKey)], $keysDepth, $value);
40
    }
41
42 3 View Code Duplication
    public function filter($key)
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...
43
    {
44 3
        $this->pipeline = $this->pipeline->pipe(
45 3
            function ($serializedBase) use ($key) {
46 3
                $keysDepth = \explode('>', $key);
47 3
                $this->unsetNestedValue($serializedBase, $keysDepth);
48
49 3
                return $serializedBase;
50 2
            }
51 1
        );
52 3
    }
53
54 3 View Code Duplication
    private function unsetNestedValue(&$serializedBase, array $keysDepth)
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...
55
    {
56 3
        $currentKey = \current($keysDepth);
57 3
        $nextKey    = \next($keysDepth);
58 3
        if (!$nextKey) {
59 3
            unset($serializedBase[\strtolower($currentKey)]);
60
61 3
            return $serializedBase;
62
        }
63
64 3
        return $this->unsetNestedValue($serializedBase[\strtolower($currentKey)], $keysDepth);
65
    }
66
67 15
    public function process($serializedBase)
68
    {
69 15
        $result         = $this->pipeline->process($serializedBase);
70 15
        $this->pipeline = new Pipeline();
71
72 15
        return $result;
73
    }
74
}
75