Completed
Push — master ( 7c8f9a...d24041 )
by Vitaly
02:09
created

FunctionCommentsGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A code() 0 9 2
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 04.09.16 at 10:43
5
 */
6
namespace samsonphp\generator;
7
8
/**
9
 * Class FunctionCommentsGenerator
10
 *
11
 * @author Vitaly Egorov <[email protected]>
12
 */
13
class FunctionCommentsGenerator extends CommentsGenerator
14
{
15
    /** @var array Argument name to type collection */
16
    protected $arguments = [];
17
18
    /** @var array Argument name to description collection */
19
    protected $descriptions = [];
20
21
    /**
22
     * FunctionCommentsGenerator constructor.
23
     *
24
     * @param array                  $arguments    Argument name to type collection
25
     * @param array                  $descriptions Argument name to description collection
26
     * @param AbstractGenerator|null $parent       Parent generator
27
     */
28
    public function __construct(array $arguments, array $descriptions, AbstractGenerator $parent = null)
29
    {
30
        $this->arguments = $arguments;
31
        $this->descriptions = $descriptions;
32
33
        parent::__construct($parent);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function code(int $indentation = 0) : string
40
    {
41
        // Add parameters comments
42
        foreach ($this->arguments as $argument => $type) {
43
            $this->defParam($argument, $type, $this->descriptions[$argument] ?? '');
44
        }
45
46
        return parent::code($indentation);
47
    }
48
}
49