TransformerMap   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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