Immutable::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: tom
5
 * Date: 08/05/2016
6
 * Time: 14:25
7
 */
8
9
namespace twhiston\twLib\Immutable;
10
11
12
/**
13
 * Class Immutable
14
 * @package twhiston\twLib\Immutable
15
 */
16
abstract class Immutable
17
{
18
19
    /**
20
     * Set in parent constructor to resist future attempts to clone or reconstruct
21
     * @var bool
22
     */
23
    private $constructed;
24
25
    /**
26
     * Immutable constructor.
27
     * This must be called from your child class to make the object immutable
28
     */
29 7
    public function __construct()
30
    {
31 7
        if ($this->constructed) {
32 1
            throw new ImmutableException('Immutable Object');
33
        }
34 7
        $this->constructed = true;
35 7
    }
36
37
    /**
38
     * Throw an exception on setting
39
     * @param $name
40
     * @param $value
41
     */
42 4
    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...
43
    {
44 4
        throw new ImmutableException('Immutable Object');
45
    }
46
47
    /**
48
     * Throw an exception on cloning
49
     */
50 1
    final public function __clone()
51
    {
52 1
        throw new ImmutableException('Immutable Object');
53
    }
54
55
56
}