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

AbstractTypedMap::offsetSet()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 6
Ratio 37.5 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 16
rs 9.4285
cc 3
eloc 10
nc 3
nop 2
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