Passed
Push — master ( ac7767...ce6fb4 )
by PHPinnacle
06:06 queued 03:22
created

Signal::getIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of PHPinnacle/Ensign.
4
 *
5
 * (c) PHPinnacle Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types = 1);
12
13
namespace PHPinnacle\Ensign;
14
15
final class Signal implements \Countable, \IteratorAggregate
16
{
17
    /**
18
     * @var string
19
     */
20
    private $name;
21
22
    /**
23
     * @var array
24
     */
25
    private $arguments;
26
27
    /**
28
     * @param string    $name
29
     * @param mixed  ...$arguments
30
     */
31 5
    public function __construct(string $name, ...$arguments)
32
    {
33 5
        $this->name      = $name;
34 5
        $this->arguments = $arguments;
35 5
    }
36
37
    /**
38
     * @param mixed $signal
39
     * @param array $arguments
40
     *
41
     * @return Signal
42
     */
43 5
    public static function create($signal, array $arguments = []): self
44
    {
45 5
        $name      = $signal;
46 5
        $arguments = \array_values($arguments);
47
48 5
        if (\is_object($signal)) {
49 1
            $name = \get_class($signal);
50
51 1
            \array_unshift($arguments, $signal);
52
        }
53
54 5
        return new self($name, ...$arguments);
55
    }
56
57
    /**
58
     * @return string
59
     */
60 5
    public function name(): string
61
    {
62 5
        return $this->name;
63
    }
64
65
    /**
66
     * @return array
67
     */
68 5
    public function arguments(): array
69
    {
70 5
        return $this->arguments;
71
    }
72
73
    /**
74
     * @return string
75
     */
76 1
    public function __toString()
77
    {
78 1
        return $this->name;
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 1
    public function getIterator()
85
    {
86 1
        yield from $this->arguments;
87 1
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92 1
    public function count()
93
    {
94 1
        return \count($this->arguments);
95
    }
96
}
97