ImmutableTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleImmutableConstructor() 0 8 2
A __set() 0 4 1
1
<?php
2
3
namespace Igorsgm\TibiaDataApi\Traits;
4
5
use Igorsgm\TibiaDataApi\Exceptions\ImmutableException;
6
7
/**
8
 * Trait ImmutableTrait
9
 * @package Igorsgm\TibiaDataApi\Models
10
 */
11
trait ImmutableTrait
12
{
13
    /**
14
     * @var bool
15
     */
16
    protected $mutable = true;
17
18
    /**
19
     * @throws ImmutableException
20
     */
21
    public function handleImmutableConstructor()
22
    {
23
        if (!$this->mutable) {
24
            throw new ImmutableException();
25
        }
26
27
        $this->mutable = false;
28
    }
29
30
    /**
31
     * @param $key
32
     * @param $value
33
     * @throws ImmutableException
34
     */
35
    public function __set($key, $value)
36
    {
37
        throw new ImmutableException();
38
    }
39
}
40