EventAdapter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 23.81 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 20
loc 84
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A renameField() 0 9 1
A rename() 0 4 1
A enrich() 10 10 1
A removeField() 0 8 1
A changeValue() 10 10 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 DDDominio\EventSourcing\Versioning;
4
5
use DDDominio\EventSourcing\EventStore\StoredEvent;
6
use DDDominio\EventSourcing\Versioning\JsonTransformer\JsonTransformer;
7
8
class EventAdapter
9
{
10
    /**
11
     * @var JsonTransformer
12
     */
13
    private $jsonTransformer;
14
15
    /**
16
     * @param JsonTransformer $jsonTransformer
17
     */
18 85
    public function __construct(JsonTransformer $jsonTransformer)
19
    {
20 85
        $this->jsonTransformer = $jsonTransformer;
21 85
    }
22
23
    /**
24
     * @param StoredEvent $storedEvent
25
     * @param string $pathExpression
26
     * @param string $newName
27
     */
28 14
    public function renameField($storedEvent, $pathExpression, $newName)
29
    {
30 14
        $data = $this->jsonTransformer->renameKey(
31 14
            $storedEvent->data(),
32
            $pathExpression,
33
            $newName
34
        );
35 14
        $storedEvent->setData($data);
36 14
    }
37
38
    /**
39
     * @param StoredEvent $storedEvent
40
     * @param string $newName
41
     */
42 1
    public function rename($storedEvent, $newName)
43
    {
44 1
        $storedEvent->setType($newName);
45 1
    }
46
47
    /**
48
     * @param StoredEvent $storedEvent
49
     * @param string $pathExpression
50
     * @param \Closure $closure
51
     */
52 1 View Code Duplication
    public function enrich($storedEvent, $pathExpression, \Closure $closure)
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...
53
    {
54 1
        $value = $closure(json_decode($storedEvent->data()));
55 1
        $data = $this->jsonTransformer->addKey(
56 1
            $storedEvent->data(),
57
            $pathExpression,
58
            $value
59
        );
60 1
        $storedEvent->setData($data);
61 1
    }
62
63
    /**
64
     * @param StoredEvent $storedEvent
65
     * @param string $pathExpression
66
     */
67 1
    public function removeField($storedEvent, $pathExpression)
68
    {
69 1
        $data = $this->jsonTransformer->removeKey(
70 1
            $storedEvent->data(),
71
            $pathExpression
72
        );
73 1
        $storedEvent->setData($data);
74 1
    }
75
76
    /**
77
     * @param StoredEvent $storedEvent
78
     * @param string $pathExpression
79
     * @param \Closure $closure
80
     */
81 3 View Code Duplication
    public function changeValue($storedEvent, $pathExpression, \Closure $closure)
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...
82
    {
83 3
        $value = $closure(json_decode($storedEvent->data()));
84 3
        $data = $this->jsonTransformer->addKey(
85 3
            $storedEvent->data(),
86
            $pathExpression,
87
            $value
88
        );
89 3
        $storedEvent->setData($data);
90 3
    }
91
}
92