AbstractCommand::setIndex()   A
last analyzed

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
namespace Remorhaz\UniLex\Example\Brainfuck\Command;
6
7
use Remorhaz\UniLex\Example\Brainfuck\Exception;
8
use Remorhaz\UniLex\Example\Brainfuck\Runtime;
9
10
abstract class AbstractCommand
11
{
12
    protected $runtime;
13
14
    protected $index;
15
16
    public function __construct(Runtime $runtime)
17
    {
18
        $this->runtime = $runtime;
19
    }
20
21
    abstract public function exec(): void;
22
23
    public function setIndex(int $index): void
24
    {
25
        $this->index = $index;
26
    }
27
28
    /**
29
     * @return int
30
     * @throws Exception
31
     */
32
    public function getIndex(): int
33
    {
34
        if (!isset($this->index)) {
35
            throw new Exception("Command index is undefined");
36
        }
37
        return $this->index;
38
    }
39
}
40