Completed
Pull Request — master (#13)
by Korotkov
02:36
created

ToggleCommand::setToggle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
     * @var int
20
     */
21
    private $toggle = 1;
22
23
    /**
24
     * @param DeviceInterface $device
25
     * @param TypeInterface   $type
26
     */
27
    public function execute(DeviceInterface $device, TypeInterface $type): void
28
    {
29
        ($this->getToggle() % 2) ? $type->setName('on') : $type->setName('off');
30
        $this->setToggle($this->getToggle() + 1);
31
        $device->execute($type);
32
    }
33
34
    /**
35
     * @return int
36
     */
37
    public function getToggle(): int
38
    {
39
        return $this->toggle;
40
    }
41
42
    /**
43
     * @param int $toggle
44
     */
45
    public function setToggle(int $toggle): void
46
    {
47
        $this->toggle = $toggle;
48
    }
49
}
50