Completed
Branch feature/pre-split (9d6b17)
by Anton
03:28
created

TransactionalCommand::addCommand()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * components
4
 *
5
 * @author    Wolfy-J
6
 */
7
namespace Spiral\ORM\Commands;
8
9
use Spiral\ORM\CommandInterface;
10
11
/**
12
 * Command to handle multiple inner commands.
13
 */
14
class TransactionalCommand extends AbstractCommand implements \IteratorAggregate
15
{
16
    /**
17
     * Nested commands.
18
     *
19
     * @var CommandInterface[]
20
     */
21
    private $commands = [];
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function addCommand(CommandInterface $command)
27
    {
28
        if ($command instanceof NullCommand) {
29
            return;
30
        }
31
32
        $this->commands[] = $command;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getIterator()
39
    {
40
        foreach ($this->commands as $command) {
41
            if ($command instanceof \Traversable) {
42
                yield from $command;
43
            }
44
45
            yield $command;
46
        }
47
    }
48
49
    public function execute()
50
    {
51
        //nothing to do (see getCommands())
52
    }
53
54
    public function complete()
55
    {
56
        //nothing to do (see getCommands())
57
    }
58
59
    public function rollBack()
60
    {
61
        //nothing to do (see getCommands())
62
    }
63
}