ImmutableArrayAccessTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 5 1
A offsetUnset() 0 5 1
A throwImmutable() 0 4 1
1
<?php
2
namespace Shrikeh\Collection;
3
4
use Shrikeh\Collection\Exception\ImmutableCollection as ImmutableCollectionException;
5
6
/**
7
 * Trait ImmutableArrayAccessTrait
8
 * @package Shrikeh\Collection
9
 */
10
trait ImmutableArrayAccessTrait
11
{
12
    /**
13
     * Immutable collections should not have setters or unsetters.
14
     *
15
     * @param $offset
16
     * @param $data
17
     * @throws ImmutableCollectionException
18
     */
19
    final public function offsetSet($offset, $data)
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
20
    {
21
        $msg = 'Collection %s is immutable and values cannot be set.';
22
        $this->throwImmutable(sprintf($msg, static::class));
23
    }
24
25
    /**
26
     * Immutable collections should not have setters or unsetters.
27
     *
28
     * @param $offset
29
     * @throws ImmutableCollectionException
30
     */
31
    final public function offsetUnset($offset)
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
    {
33
        $msg = 'Collection %s is immutable and values cannot be unset.';
34
        $this->throwImmutable(sprintf($msg, static::class));
35
    }
36
37
    /**
38
     * @param string $msg
39
     * @throws ImmutableCollectionException
40
     */
41
    protected function throwImmutable($msg, $errorCode = null)
42
    {
43
        throw new ImmutableCollectionException($msg, $errorCode);
44
    }
45
}
46