Completed
Push — master ( 511437...7c8f9a )
by Vitaly
02:06
created

CodeTrait::buildArguments()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 04.09.16 at 10:13
5
 */
6
namespace samsonphp\generator;
7
8
/**
9
 * Trait for generators that can generate internal code.
10
 *
11
 * @author Vitaly Egorov <[email protected]>
12
 */
13
trait CodeTrait
14
{
15
    /** @var array Collection of code lines */
16
    protected $code = [];
17
18
    /**
19
     * Add function code line.
20
     *
21
     * @param string $code Code line
22
     *
23
     * @return $this
24
     */
25
    public function defLine(string $code)
26
    {
27
        $this->code[] = $code;
28
29
        return $this;
30
    }
31
32
    /**
33
     * Build arguments list with types.
34
     *
35
     * @param array $arguments Arguments collection
36
     *
37
     * @return string Arguments list
38
     */
39
    protected function buildArguments(array $arguments) : string
40
    {
41
        $argumentsString = [];
42
        foreach ($arguments as $argumentName => $argumentType) {
43
            // Group name with type
44
            $argumentsString[] = ($argumentType !== null ? $argumentType . ' ' : '') . '$' . $argumentName;
45
        }
46
47
        return implode(', ', $argumentsString);
48
    }
49
}
50