Completed
Push — master ( 5c79cc...0d8b4c )
by
unknown
29s queued 10s
created

Sapi3FixedSavedSearchRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A ownedByCurrentUser() 26 26 3

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 CultuurNet\UDB3\SavedSearches\Properties\CreatorQueryString;
6
use CultuurNet\UDB3\SavedSearches\ReadModel\SavedSearch;
7
use CultuurNet\UDB3\SavedSearches\ReadModel\SavedSearchRepositoryInterface;
8
use CultuurNet\UDB3\SavedSearches\ValueObject\CreatedByQueryMode;
9
use ValueObjects\StringLiteral\StringLiteral;
10
11
/**
12
 * Sapi3FixedSavedSearchRepository is used for Sapi3.
13
 *
14
 * Class FixedSavedSearchRepository
15
 * @package CultuurNet\UDB3\SavedSearches
16
 */
17 View Code Duplication
class Sapi3FixedSavedSearchRepository implements SavedSearchRepositoryInterface
0 ignored issues
show
Duplication introduced by
This class 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...
18
{
19
    /**
20
     * @var \CultureFeed_User
21
     */
22
    private $user;
23
24
    /**
25
     * @var CreatedByQueryMode
26
     */
27
    protected $createdByQueryMode;
28
29
    /**
30
     * @param \CultureFeed_User $user
31
     * @param CreatedByQueryMode $createdByQueryMode
32
     */
33
    public function __construct(
34
        \CultureFeed_User $user,
35
        CreatedByQueryMode $createdByQueryMode
36
    ) {
37
        $this->user = $user;
38
        $this->createdByQueryMode = $createdByQueryMode;
39
    }
40
41
    /**
42
     * @return SavedSearch[]
43
     */
44
    public function ownedByCurrentUser(): array
45
    {
46
        $name = new StringLiteral('Door mij ingevoerd');
47
48
        switch ($this->createdByQueryMode->toNative()) {
49
            case CreatedByQueryMode::EMAIL:
50
                $createdByQueryString = new CreatorQueryString(
51
                    $this->user->mbox
52
                );
53
                break;
54
            case CreatedByQueryMode::MIXED:
55
                $createdByQueryString = new CreatorQueryString(
56
                    $this->user->mbox,
57
                    $this->user->id
58
                );
59
                break;
60
            default:
61
                $createdByQueryString = new CreatorQueryString(
62
                    $this->user->id
63
                );
64
        }
65
66
        return [
67
            new SavedSearch($name, $createdByQueryString),
68
        ];
69
    }
70
}
71