Immutable::__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 2
Bugs 0 Features 1
Metric Value
c 2
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
 * 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
}