AbstractFinalTrait::defFinal()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php declare(strict_types=1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 04.09.16 at 12:07
5
 */
6
namespace samsonframework\generator;
7
8
/**
9
 * Class AbstractFinalTrait
10
 *
11
 * @author Vitaly Egorov <[email protected]>
12
 */
13
trait AbstractFinalTrait
14
{
15
    /** @var bool Flag that method is abstract */
16
    protected $isAbstract = false;
17
18
    /** @var bool Flag that method is final */
19
    protected $isFinal = false;
20
21
    /**
22
     * Set to be final.
23
     *
24
     * @return $this
25
     * @throws \InvalidArgumentException
26
     */
27 7
    public function defFinal()
28
    {
29 7
        if ($this->isAbstract) {
30 2
            throw new \InvalidArgumentException('Method cannot be final as it is already abstract');
31
        }
32
33 5
        $this->isFinal = true;
34
35 5
        return $this;
36
    }
37
38
    /**
39
     * Set to be abstract.
40
     *
41
     * @return $this
42
     * @throws \InvalidArgumentException
43
     */
44 8
    public function defAbstract()
45
    {
46 8
        if ($this->isFinal) {
47 2
            throw new \InvalidArgumentException('Method cannot be abstract as it is already final');
48
        }
49
50 6
        $this->isAbstract = true;
51
52 6
        return $this;
53
    }
54
}
55