ImmutableTrait::__set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Wambo\Core\Immutable;
4
5
use Wambo\Core\Immutable\Exception\ImmutableException;
6
7
trait ImmutableTrait
8
{
9
    /** @var bool $constructed */
10
    private $constructed = false;
11
12
13
    /**
14
     * ImmutableTrait constructor.
15
     *
16
     * @throws ImmutableException
17
     */
18 8
    public function setConstructed()
19
    {
20 8
        if ($this->constructed === true) {
21 2
            throw new ImmutableException('Can not recall constructor again because this object is immutable.');
22
        }
23 8
        $this->constructed = true;
24 8
    }
25
26
    /**
27
     * Disable the magic function to prevent change the immutable object
28
     *
29
     * @param string $name
30
     * @param string $value
31
     */
32 2
    final public function __set($name, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $name 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 $value 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...
33
    {
34 2
        throw new ImmutableException('Can not set any value because this object is immutable.');
35
    }
36
}