ImmutableTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 30
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setConstructed() 0 7 2
A __set() 0 4 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
}