Completed
Pull Request — master (#396)
by Kristof
04:45
created

SavedSearchWriteRepositoryCollection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A withRepository() 0 8 1
A getRepository() 0 8 2
1
<?php
2
3
namespace CultuurNet\UDB3\SavedSearches;
4
5
use CultuurNet\UDB3\SavedSearches\WriteModel\SavedSearchRepositoryInterface;
6
use CultuurNet\UDB3\ValueObject\SapiVersion;
7
8
class SavedSearchWriteRepositoryCollection
9
{
10
    /**
11
     * @var SavedSearchRepositoryInterface
12
     */
13
    private $savedSearchRepositories;
14
15
    /**
16
     * @param SapiVersion $sapiVersion
17
     * @param SavedSearchRepositoryInterface $savedSearchRepository
18
     * @return SavedSearchWriteRepositoryCollection
19
     */
20
    public function withRepository(
21
        SapiVersion $sapiVersion,
22
        SavedSearchRepositoryInterface $savedSearchRepository
23
    ): SavedSearchWriteRepositoryCollection {
24
        $c = clone $this;
25
        $c->savedSearchRepositories[$sapiVersion->toNative()] = $savedSearchRepository;
26
        return $c;
27
    }
28
29
    /**
30
     * @param SapiVersion $sapiVersion
31
     * @return SavedSearchRepositoryInterface|null
32
     */
33
    public function getRepository(SapiVersion $sapiVersion): ?SavedSearchRepositoryInterface
34
    {
35
        if (!isset($this->savedSearchRepositories[$sapiVersion->toNative()])) {
36
            return null;
37
        }
38
39
        return $this->savedSearchRepositories[$sapiVersion->toNative()];
40
    }
41
}
42