Completed
Push — master ( 58593e...34b479 )
by Luc
05:58
created

DefaultPlaceEditingService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 99
Duplicated Lines 41.41 %

Coupling/Cohesion

Components 2
Dependencies 8

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 2
cbo 8
dl 41
loc 99
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 18 18 1
A createPlace() 15 15 1
A updateMajorInfo() 8 8 1
A updateAddress() 0 8 1
A deletePlace() 0 4 1
A updateFacilities() 0 9 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 CultuurNet\UDB3\Place;
4
5
use Broadway\CommandHandling\CommandBusInterface;
6
use Broadway\Repository\RepositoryInterface;
7
use Broadway\UuidGenerator\UuidGeneratorInterface;
8
use CultuurNet\UDB3\Address\Address;
9
use CultuurNet\UDB3\CalendarInterface;
10
use CultuurNet\UDB3\Event\EventType;
11
use CultuurNet\UDB3\Event\ReadModel\DocumentRepositoryInterface;
12
use CultuurNet\UDB3\Label\LabelServiceInterface;
13
use CultuurNet\UDB3\Language;
14
use CultuurNet\UDB3\Offer\Commands\OfferCommandFactoryInterface;
15
use CultuurNet\UDB3\Offer\DefaultOfferEditingService;
16
use CultuurNet\UDB3\Place\Commands\UpdateAddress;
17
use CultuurNet\UDB3\Place\Commands\UpdateFacilities;
18
use CultuurNet\UDB3\Place\Commands\UpdateMajorInfo;
19
use CultuurNet\UDB3\Theme;
20
use CultuurNet\UDB3\Title;
21
22
class DefaultPlaceEditingService extends DefaultOfferEditingService implements PlaceEditingServiceInterface
23
{
24
    /**
25
     * @var RepositoryInterface
26
     */
27
    protected $writeRepository;
28
29
    /**
30
     * @param CommandBusInterface $commandBus
31
     * @param UuidGeneratorInterface $uuidGenerator
32
     * @param DocumentRepositoryInterface $readRepository
33
     * @param OfferCommandFactoryInterface $commandFactory
34
     * @param RepositoryInterface $writeRepository
35
     * @param LabelServiceInterface $labelService
36
     */
37 View Code Duplication
    public function __construct(
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...
38
        CommandBusInterface $commandBus,
39
        UuidGeneratorInterface $uuidGenerator,
40
        DocumentRepositoryInterface $readRepository,
41
        OfferCommandFactoryInterface $commandFactory,
42
        RepositoryInterface $writeRepository,
43
        LabelServiceInterface $labelService
44
    ) {
45
        parent::__construct(
46
            $commandBus,
47
            $uuidGenerator,
48
            $readRepository,
49
            $commandFactory,
50
            $labelService
51
        );
52
53
        $this->writeRepository = $writeRepository;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 View Code Duplication
    public function createPlace(
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...
60
        Title $title,
61
        EventType $eventType,
62
        Address $address,
63
        CalendarInterface $calendar,
64
        Theme $theme = null
65
    ) {
66
        $id = $this->uuidGenerator->generate();
67
68
        $place = Place::createPlace($id, $title, $eventType, $address, $calendar, $theme, $this->publicationDate);
69
70
        $this->writeRepository->save($place);
71
72
        return $id;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 View Code Duplication
    public function updateMajorInfo($id, Title $title, EventType $eventType, Address $address, CalendarInterface $calendar, Theme $theme = null)
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...
79
    {
80
        $this->guardId($id);
81
82
        return $this->commandBus->dispatch(
83
            new UpdateMajorInfo($id, $title, $eventType, $address, $calendar, $theme)
84
        );
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90
    public function updateAddress($id, Address $address, Language $language)
91
    {
92
        $this->guardId($id);
93
94
        return $this->commandBus->dispatch(
95
            new UpdateAddress($id, $address, $language)
96
        );
97
    }
98
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function deletePlace($id)
104
    {
105
        return $this->delete($id);
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function updateFacilities($id, array $facilities)
112
    {
113
114
        $this->guardId($id);
115
116
        return $this->commandBus->dispatch(
117
            new UpdateFacilities($id, $facilities)
118
        );
119
    }
120
}
121