Passed
Pull Request — master (#4)
by Korotkov
02:42
created

ToggleCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @license   https://mit-license.org/ MIT
8
 */
9
10
namespace Behavioral\Command;
11
12
/**
13
 * Class ToggleCommand
14
 * @package Behavioral\Command
15
 */
16
class ToggleCommand implements CommandInterface
17
{
18
19
    /**
20
     * @var int
21
     */
22
    protected $toggle = 1;
23
24
    /**
25
     * @param DeviceInterface $device
26
     */
27
    public function execute(DeviceInterface $device): void
28
    {
29
        ($this->toggle % 2) ? $device->turnOn() : $device->turnOff();
30
        $this->toggle++;
31
    }
32
}
33