Completed
Pull Request — master (#392)
by Luc
51:23 queued 32:05
created

UDB3SavedSearchesCommandHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 23.08 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 9
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handleSubscribeToSavedSearch() 9 9 1
A handleUnsubscribeFromSavedSearch() 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 CultuurNet\UDB3\SavedSearches;
4
5
use Broadway\CommandHandling\CommandHandler;
6
use CultuurNet\UDB3\SavedSearches\Command\SubscribeToSavedSearch;
7
use CultuurNet\UDB3\SavedSearches\Command\UnsubscribeFromSavedSearch;
8
use CultuurNet\UDB3\SavedSearches\WriteModel\SavedSearchRepositoryInterface;
9
10
class UDB3SavedSearchesCommandHandler extends CommandHandler
11
{
12
    /**
13
     * @var SavedSearchRepositoryInterface
14
     */
15
    private $savedSearchRepository;
16
17
    /**
18
     * @param SavedSearchRepositoryInterface $savedSearchRepository
19
     */
20
    public function __construct(SavedSearchRepositoryInterface $savedSearchRepository)
21
    {
22
        $this->savedSearchRepository = $savedSearchRepository;
23
    }
24
25
    /**
26
     * @param SubscribeToSavedSearch $subscribeToSavedSearch
27
     */
28 View Code Duplication
    public function handleSubscribeToSavedSearch(SubscribeToSavedSearch $subscribeToSavedSearch)
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...
29
    {
30
        $userId = $subscribeToSavedSearch->getUserId();
31
        $name = $subscribeToSavedSearch->getName();
32
        $query = $subscribeToSavedSearch->getQuery();
33
34
35
        $this->savedSearchRepository->write($userId, $name, $query);
36
    }
37
38
    /**
39
     * @param UnsubscribeFromSavedSearch $unsubscribeFromSavedSearch
40
     */
41
    public function handleUnsubscribeFromSavedSearch(UnsubscribeFromSavedSearch $unsubscribeFromSavedSearch)
42
    {
43
        $userId = $unsubscribeFromSavedSearch->getUserId();
44
        $searchId = $unsubscribeFromSavedSearch->getSearchId();
45
46
        $this->savedSearchRepository->delete($userId, $searchId);
47
    }
48
}
49