Completed
Pull Request — master (#344)
by Luc
05:32
created

DefaultPlaceEditingService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 98
Duplicated Lines 54.08 %

Coupling/Cohesion

Components 2
Dependencies 9

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 9
dl 53
loc 98
rs 10
c 0
b 0
f 0

5 Methods

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