ImmutableArrayHelperMethods   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
dl 0
loc 29
ccs 4
cts 4
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetUnset() 0 3 1
A offsetSet() 0 3 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * This file is part of the Type package.
5
 * For the full copyright information please view the LICENCE file that was
6
 * distributed with this package.
7
 *
8
 * @copyright Simon Deeley 2017
9
 */
10
11
namespace simondeeley\Helpers;
12
13
use simondeeley\Exceptions\ImmutableMethodCallException;
14
15
/**
16
 * Helper trait to implement immutable arrays
17
 *
18
 * Implements two basic methods to prevent accidental or implicit modification
19
 * of an arrays properties.
20
 *
21
 * @author Simon Deeley <[email protected]>
22
 */
23
trait ImmutableArrayHelperMethods
24
{
25
    /**
26
     * Prevent implicit setting of properties
27
     *
28
     * @see http://php.net/manual/en/arrayaccess.offsetset.php
29
     *
30
     * @param string $property - Property name to set
31
     * @param mixed $value - Mixed value to set property to
32
     * @return void
33
     * @throws ImmutableMethodCallException - Always throws an exception
34
     */
35 1
    final public function offsetSet($property, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

35
    final public function offsetSet($property, /** @scrutinizer ignore-unused */ $value)

This check looks for 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 $property is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

35
    final public function offsetSet(/** @scrutinizer ignore-unused */ $property, $value)

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

Loading history...
36
    {
37 1
        throw new ImmutableMethodCallException;
38
    }
39
40
    /**
41
     * Prevent implicit unsetting of properties
42
     *
43
     * @see http://php.net/manual/en/arrayaccess.offsetunset.php
44
     *
45
     * @param string $property - Property name to unset
46
     * @return void
47
     * @throws ImmutableMethodCallException - Always throws an exception
48
     */
49 1
    final public function offsetUnset($property)
0 ignored issues
show
Unused Code introduced by
The parameter $property is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

49
    final public function offsetUnset(/** @scrutinizer ignore-unused */ $property)

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

Loading history...
50
    {
51 1
        throw new ImmutableMethodCallException;
52
    }
53
}
54