Test Failed
Push — master ( 33bfdc...47f867 )
by Kirill
02:32
created

InvocationPrimitive::addArgument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Frontend\Invocation;
11
12
use Railt\SDL\IR\SymbolTable\PrimitiveInterface;
13
use Railt\SDL\IR\Type\TypeNameInterface;
14
15
/**
16
 * Class InvocationPrimitive
17
 */
18
class InvocationPrimitive implements InvocationInterface
19
{
20
    /**
21
     * @var TypeNameInterface
22
     */
23
    private $name;
24
25
    /**
26
     * @var array
27
     */
28
    private $arguments = [];
29
30
    /**
31
     * InvocationPrimitive constructor.
32
     * @param TypeNameInterface $name
33
     */
34
    public function __construct(TypeNameInterface $name)
35
    {
36
        $this->name = $name;
37
    }
38
39
    /**
40
     * @return array|InvocationPrimitive[]
41
     */
42
    public function getArguments(): array
43
    {
44
        return $this->arguments;
45
    }
46
47
    /**
48
     * @param string $name
49
     * @param InvocationPrimitive|PrimitiveInterface $value
50
     * @return InvocationPrimitive
51
     */
52
    public function addArgument(string $name, $value): InvocationPrimitive
53
    {
54
        $this->arguments[$name] = $value;
55
56
        return $this;
57
    }
58
59
    /**
60
     * @return bool
61
     */
62
    public function hasArguments(): bool
63
    {
64
        return \count($this->arguments) > 0;
65
    }
66
67
    /**
68
     * @return TypeNameInterface
69
     */
70
    public function getName(): TypeNameInterface
71
    {
72
        return $this->name;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function __toString(): string
79
    {
80
        if ($this->hasArguments()) {
81
            $arguments = [];
82
83
            foreach ($this->arguments as $name => $value) {
84
                $arguments[] = $name . ': ' . $value;
85
            }
86
87
            return \sprintf('%s<%s>', $this->name->getFullyQualifiedName(), \implode(', ', $arguments));
88
        }
89
90
        return $this->name->getFullyQualifiedName();
91
    }
92
}
93