RuleMap   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 4
c 5
b 1
f 1
lcom 0
cbo 3
dl 40
loc 40
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 8 8 2
A get() 6 6 1
A add() 6 6 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 DCP\Mapper\Collections\Maps;
4
5
use DCP\Mapper\Exception\InvalidArgumentException;
6
use DCP\Mapper\RuleCollection;
7
use DCP\Mapper\RuleInterface;
8
9 View Code Duplication
class RuleMap extends CollectionMap
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...
10
{
11
    /**
12
     * @param mixed $key
13
     * @param RuleCollection $value
14
     * @return $this
15
     * @throws InvalidArgumentException
16
     */
17
    public function set($key, $value)
18
    {
19
        if (!($value instanceof RuleCollection)) {
20
            throw new InvalidArgumentException('$value must be an instance of RuleCollection');
21
        }
22
23
        return parent::set($key, $value);
24
    }
25
26
    /**
27
     * @param mixed $key
28
     * @param bool $default
29
     * @return RuleCollection|RuleInterface[]
30
     */
31
    public function get($key, $default = true)
32
    {
33
        return parent::get($key, $default, function () {
34
            return new RuleCollection();
35
        });
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     * @throws InvalidArgumentException
41
     */
42
    public function add($key, $value)
43
    {
44
        return $this->addWithTypeCheck($key, $value, 'DCP\Mapper\RuleInterface', function () {
45
            return new RuleCollection();
46
        });
47
    }
48
}
49