Completed
Push — master ( 58a57e...9c59b1 )
by Vitaly
02:16
created

AbstractFinalTrait::defFinal()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
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 samsonphp\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
    public function defFinal()
28
    {
29
        if ($this->isAbstract) {
30
            throw new \InvalidArgumentException('Method cannot be final as it is already abstract');
31
        }
32
33
        $this->isFinal = true;
34
35
        return $this;
36
    }
37
38
    /**
39
     * Set to be abstract.
40
     *
41
     * @return $this
42
     * @throws \InvalidArgumentException
43
     */
44
    public function defAbstract()
45
    {
46
        if ($this->isFinal) {
47
            throw new \InvalidArgumentException('Method cannot be abstract as it is already final');
48
        }
49
50
        $this->isAbstract = true;
51
52
        return $this;
53
    }
54
}
55