ToggleCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author  : Jagepard <[email protected]>
7
 * @license https://mit-license.org/ MIT
8
 */
9
10
namespace Behavioral\Command;
11
12
class ToggleCommand implements CommandInterface
13
{
14
    private int $toggle = 1;
15
16
    /**
17
     * Switches from one command to another
18
     * -------------------------------------
19
     * Переключает с одной команды на другую
20
     *
21
     * @return void
22
     */
23
    public function execute(): void
24
    {
25
        $command = ($this->toggle % 2) ? new TurnOnCommand() : new TurnOffCommand();
26
        $this->toggle++;
27
        $command->execute();
28
    }
29
}
30