Completed
Push — master ( 2a5486...81459b )
by Vitaly
02:39
created

MethodGenerator   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 71
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A buildDefinition() 0 7 4
A defStatic() 0 6 1
A defFinal() 0 10 2
A defAbstract() 0 10 2
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 03.09.16 at 11:30
5
 */
6
namespace samsonphp\generator;
7
8
/**
9
 * Class method generation class.
10
 *
11
 * @author Vitaly Egorov <[email protected]>
12
 */
13
class MethodGenerator extends FunctionGenerator
14
{
15
    /** @var bool Flag that method is static */
16
    protected $isStatic = false;
17
18
    /** @var bool Flag that method is abstract */
19
    protected $isAbstract = false;
20
21
    /** @var bool Flag that method is final */
22
    protected $isFinal = false;
23
24
    /** @var string Method visibility */
25
    protected $visibility = ClassGenerator::VISIBILITY_PUBLIC;
26
27
    /**
28
     * Build function definition.
29
     *
30
     * @return string Function definition
31
     */
32
    protected function buildDefinition()
33
    {
34
        return ($this->isFinal ? 'final ' : '').
35
            ($this->isAbstract ? 'abstract ' : '').
36
            ($this->isStatic ? 'static ' : '').
37
            'function '.$this->name.'()';
38
    }
39
40
    /**
41
     * Set method to be static.
42
     *
43
     * @return MethodGenerator
44
     */
45
    public function defStatic() : MethodGenerator
46
    {
47
        $this->isStatic = true;
48
49
        return $this;
50
    }
51
52
    /**
53
     * Set method to be final.
54
     *
55
     * @return MethodGenerator
56
     */
57
    public function defFinal() : MethodGenerator
58
    {
59
        if ($this->isAbstract) {
60
            throw new \InvalidArgumentException('Method cannot be final as it is already abstract');
61
        }
62
63
        $this->isFinal = true;
64
65
        return $this;
66
    }
67
68
    /**
69
     * Set method to be abstract.
70
     *
71
     * @return MethodGenerator
72
     */
73
    public function defAbstract() : MethodGenerator
74
    {
75
        if ($this->isFinal) {
76
            throw new \InvalidArgumentException('Method cannot be abstract as it is already final');
77
        }
78
79
        $this->isAbstract = true;
80
81
        return $this;
82
    }
83
}
84