Test Failed
Push — master ( ecd78b...d05c81 )
by Kirill
02:43
created

State::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Backend\State;
11
12
use Railt\Reflection\Contracts\Reflection;
13
use Railt\SDL\Backend\Runtime;
14
use Railt\SDL\Frontend\IR\OpcodeInterface;
15
16
/**
17
 * Class State
18
 */
19
abstract class State implements StateInterface
20
{
21
    /**
22
     * @var mixed
23
     */
24
    private $result;
25
26
    /**
27
     * @var bool
28
     */
29
    private $resolved = false;
30
31
    /**
32
     * @var Runtime
33
     */
34
    private $runtime;
35
36
    /**
37
     * State constructor.
38
     * @param Runtime $runtime
39
     */
40
    public function __construct(Runtime $runtime)
41
    {
42
        $this->runtime = $runtime;
43
    }
44
45
    /**
46
     * @return Reflection
47
     */
48
    public function getReflection(): Reflection
49
    {
50
        return $this->runtime->getReflection();
51
    }
52
53
    /**
54
     * @param OpcodeInterface $opcode
55
     * @return mixed
56
     */
57
    abstract protected function execute(OpcodeInterface $opcode);
58
59
    /**
60
     * @param OpcodeInterface $opcode
61
     * @return mixed
62
     */
63
    final public function resolve(OpcodeInterface $opcode)
64
    {
65
        if ($this->resolved === false) {
66
            $this->result = $this->execute($opcode);
67
            $this->resolved = true;
68
        }
69
70
        return $this->result;
71
    }
72
}
73