Completed
Push — master ( ecb0b5...acebd9 )
by Ben
9s
created

AbstractTypedMap   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 27.27 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 6
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 6 16 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
/**
4
 * This file is part of the ramsey/collection library
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @copyright Copyright (c) Ben Ramsey <[email protected]>
10
 * @license http://opensource.org/licenses/MIT MIT
11
 * @link https://benramsey.com/projects/ramsey-collection/ Documentation
12
 * @link https://packagist.org/packages/ramsey/collection Packagist
13
 * @link https://github.com/ramsey/collection GitHub
14
 */
15
16
namespace Ramsey\Collection\Map;
17
18
use Ramsey\Collection\Tool\TypeTrait;
19
use Ramsey\Collection\Tool\ValueToStringTrait;
20
21
/**
22
 * This class provides an implementation of the TypedMapInterface, to
23
 * minimize the effort required to implement this interface
24
 */
25
abstract class AbstractTypedMap extends AbstractMap implements TypedMapInterface
26
{
27
    use TypeTrait;
28
    use ValueToStringTrait;
29
30
    public function offsetSet($offset, $value)
31
    {
32
        if (false === $this->checkType($this->getKeyType(), $offset)) {
33
            throw new \InvalidArgumentException(
34
                'Key must be of type ' . $this->getKeyType() . '; key is '
35
                . $this->toolValueToString($offset)
36
            );
37
        }
38 View Code Duplication
        if (false === $this->checkType($this->getValueType(), $value)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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
            throw new \InvalidArgumentException(
40
                'Value must be of type ' . $this->getValueType() . '; value is '
41
                . $this->toolValueToString($value)
42
            );
43
        }
44
        parent::offsetSet($offset, $value);
45
    }
46
}
47