Completed
Push — master ( d925db...e7e919 )
by Vitaly
02:50
created

GenericGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 53
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A defFunction() 0 4 1
A defClass() 0 4 1
A code() 0 12 3
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 03.09.16 at 11:37
5
 */
6
namespace samsonphp\generator;
7
8
/**
9
 * Class GenericGenerator
10
 *
11
 * @author Vitaly Egorov <[email protected]>
12
 */
13
class GenericGenerator extends AbstractGenerator
14
{
15
    /** @var ClassGenerator[] Collection of classes */
16
    protected $classes = [];
17
18
    /** @var FunctionGenerator[] Collection of functions */
19
    protected $functions = [];
20
21
    /**
22
     * Set function.
23
     *
24
     * @param string $name Function
25
     * @param bool   $isStatic Flag that function is static
0 ignored issues
show
Bug introduced by
There is no parameter named $isStatic. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
26
     *
27
     * @return FunctionGenerator New function generator instance
28
     */
29
    public function defFunction(string $name) : FunctionGenerator
30
    {
31
        return $this->functions[] = new FunctionGenerator($name, $this);
32
    }
33
34
    /**
35
     * Set class.
36
     *
37
     * @param string $name Class name
38
     *
39
     * @return ClassGenerator
40
     */
41
    public function defClass(string $name) : ClassGenerator
42
    {
43
        return $this->classes[] = new ClassGenerator($this, $name);
0 ignored issues
show
Documentation introduced by
$this is of type this<samsonphp\generator\GenericGenerator>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$name is of type string, but the function expects a object<samsonphp\generator\GenericGenerator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44
    }
45
46
    /**
47
     * Generate code.
48
     *
49
     * @param int $indentation Code level
50
     *
51
     * @return string Generated code
52
     */
53
    public function code(int $indentation = 0) : string
54
    {
55
        foreach ($this->classes as $classGenerator) {
56
            $this->code[] = $classGenerator->code($indentation);
57
        }
58
59
        foreach ($this->functions as $functionGenerator) {
60
            $this->code[] = $functionGenerator->code($indentation);
61
        }
62
63
        return implode("\n".$this->indentation($indentation), $this->code);
64
    }
65
}
66