Completed
Pull Request — master (#366)
by Beñat
04:55
created

User   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 23.81 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 10
loc 42
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A signUp() 0 7 1
A applyUserSignedUp() 0 3 1
A reconstitute() 10 10 2
A id() 0 4 1
A __toString() 0 4 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
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\Notifier\Domain\Model\Inbox;
16
17
use Kreta\SharedKernel\Domain\Model\AggregateRoot;
18
use Kreta\SharedKernel\Domain\Model\EventSourcedAggregateRoot;
19
use Kreta\SharedKernel\Event\EventStream;
20
21
class User extends AggregateRoot implements EventSourcedAggregateRoot
22
{
23
    private $id;
24
25
    private function __construct(UserId $id)
26
    {
27
        $this->id = $id;
28
    }
29
30
    public static function signUp(UserId $id) : self
31
    {
32
        $user = new self($id);
33
        $user->publish(new UserSignedUp($id));
34
35
        return $user;
36
    }
37
38
    protected function applyUserSignedUp(UserSignedUp $event) : void
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
    {
40
    }
41
42 View Code Duplication
    public static function reconstitute(EventStream $stream) : EventSourcedAggregateRoot
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
        $user = new self($stream->aggregateRootId());
0 ignored issues
show
Compatibility introduced by
$stream->aggregateRootId() of type object<Kreta\SharedKerne...\Model\Identity\BaseId> is not a sub-type of object<Kreta\Notifier\Domain\Model\Inbox\UserId>. It seems like you assume a concrete implementation of the interface Kreta\SharedKernel\Domain\Model\Identity\BaseId to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
45
        $events = $stream->events()->toArray();
46
        foreach ($events as $event) {
47
            $user->apply($event);
48
        }
49
50
        return $user;
51
    }
52
53
    public function id() : UserId
54
    {
55
        return $this->id;
56
    }
57
58
    public function __toString() : string
59
    {
60
        return (string) $this->id()->id();
61
    }
62
}
63