Completed
Push — master ( d7040d...7fcf0d )
by Craig
08:15
created

SearchableModuleCollector   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 12.96 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A add() 7 7 2
A get() 0 4 2
A getAll() 0 4 1
A getKeys() 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
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zikula\SearchModule\Collector;
13
14
use Zikula\SearchModule\SearchableInterface;
15
16
/**
17
 * Class SearchableModuleCollector
18
 */
19
class SearchableModuleCollector
20
{
21
    /**
22
     * @var SearchableInterface[] e.g. [<moduleName> => <ServiceObject>]
23
     */
24
    private $searchableModules = [];
25
26
    /**
27
     * SearchableModuleCollector constructor.
28
     */
29
    public function __construct()
30
    {
31
    }
32
33
    /**
34
     * Add a service to the collection.
35
     * @param string $moduleName
36
     * @param SearchableInterface $service
37
     */
38 View Code Duplication
    public function add($moduleName, SearchableInterface $service)
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...
39
    {
40
        if (isset($this->searchableModules[$moduleName])) {
41
            throw new \InvalidArgumentException('Attempting to register a searchable module with a duplicate module name. (' . $moduleName . ')');
42
        }
43
        $this->searchableModules[$moduleName] = $service;
44
    }
45
46
    /**
47
     * Get a SearchableInterface from the collection by moduleName.
48
     * @param $moduleName
49
     * @return SearchableInterface|null
50
     */
51
    public function get($moduleName)
52
    {
53
        return isset($this->searchableModules[$moduleName]) ? $this->searchableModules[$moduleName] : null;
54
    }
55
56
    /**
57
     * Get all the searchableModules in the collection.
58
     * @return SearchableInterface[]
59
     */
60
    public function getAll()
61
    {
62
        return $this->searchableModules;
63
    }
64
65
    /**
66
     * @return array of service aliases
67
     */
68
    public function getKeys()
69
    {
70
        return array_keys($this->searchableModules);
71
    }
72
}
73