PhpTrait::createMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Murtukov\PHPCodeGenerator;
6
7
class PhpTrait extends OOPStructure
8
{
9 1
    public function addProperty(string $name, string $modifier = Modifier::PUBLIC, string $type = '', $defaulValue = Property::NO_PARAM): self
10
    {
11 1
        return $this->append(new Property($name, $modifier, $type, $defaulValue));
12
    }
13
14 1
    public function createProperty(string $name, string $modifier = Modifier::PUBLIC, string $type = '', $defaulValue = Property::NO_PARAM)
15
    {
16 1
        $property = new Property($name, $modifier, $type, $defaulValue);
17
18 1
        $this->append($property);
19
20 1
        return $property;
21
    }
22
23 1
    public function addMethod(string $name, string $modifier = 'public', string $returnType = ''): self
24
    {
25 1
        return $this->append(new Method($name, $modifier, $returnType))->emptyLine();
26
    }
27
28 1
    public function createMethod(string $name, string $modifier = 'public', string $returnType = ''): Method
29
    {
30 1
        $method = new Method($name, $modifier, $returnType);
31
32 1
        $this->append($method)->emptyLine();
33
34 1
        return $method;
35
    }
36
37 1
    public function createConstructor(string $modifier = 'public'): Method
38
    {
39 1
        $constructor = new Method('__construct', $modifier, '');
40
41 1
        $this->append($constructor)->emptyLine();
42
43 1
        return $constructor;
44
    }
45
46 4
    public function generate(): string
47
    {
48
        return <<<CODE
49 4
        {$this->buildDocBlock()}trait $this->name
50
        {
51 4
        {$this->generateContent()}
52
        }
53
        CODE;
54
    }
55
}