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

ToggleCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 5 2
A setToggle() 0 3 1
A getToggle() 0 3 1
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