ImmutableObjectHelperMethods   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 3 1
A __unset() 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 objects
17
 *
18
 * Implements two basic methods to prevent accidental or implicit modification
19
 * of an objects properties.
20
 *
21
 * @author  Simon Deeley <[email protected]>
22
 */
23
trait ImmutableObjectHelperMethods
24
{
25
    /**
26
     * Prevent implicit setting of properties
27
     *
28
     * @param string $property - Property name to set
29
     * @param mixed $value - Mixed value to set property to
30
     * @return void
31
     * @throws ImmutableMethodCallException - Always throws an exception
32
     */
33 1
    final public function __set(string $property, $value): void
34
    {
35 1
        throw new ImmutableMethodCallException;
36
    }
37
38
    /**
39
     * Prevent implicit unsetting of properties
40
     *
41
     * @param string $property - Property name to set
42
     * @return void
43
     * @throws ImmutableMethodCallException - Always throws an exception
44
     */
45 1
    final public function __unset(string $property): void
46
    {
47 1
        throw new ImmutableMethodCallException;
48
    }
49
}
50