Test Failed
Push — master ( a0eed4...bb00ac )
by Kirill
149:40
created

AbstractValueNode   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
parse() 0 1 ?
A toPrimitive() 0 8 2
A toValue() 0 4 1
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\Frontend\AST\Invocation;
11
12
use Railt\Io\Readable;
13
use Railt\Parser\Ast\Rule;
14
use Railt\SDL\IR\Value;
15
use Railt\SDL\IR\ValueInterface;
16
17
/**
18
 * Class AbstractValue
19
 */
20
abstract class AbstractValueNode extends Rule implements AstValueInterface
21
{
22
    /**
23
     * @var mixed
24
     */
25
    private $value;
26
27
    /**
28
     * @return mixed
29
     */
30
    abstract protected function parse();
31
32
    /**
33
     * @return mixed
34
     */
35
    public function toPrimitive()
36
    {
37
        if ($this->value === null) {
38
            $this->value = $this->parse();
39
        }
40
41
        return $this->value;
42
    }
43
44
    /**
45
     * @param Readable $file
46
     * @return ValueInterface
47
     */
48
    public function toValue(Readable $file): ValueInterface
49
    {
50
        return (new Value($this->toPrimitive()))->in($file, $this->getOffset());
51
    }
52
}
53