Value::createFromString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\VariableResolver\Variable\Value;
6
7
final class Value implements ValueInterface
8
{
9
    /** @var callable|string */
10
    private $value;
11
12
    /**
13
     * @param string|callable $value
14
     */
15
    private function __construct($value)
16
    {
17
        $this->value = $value;
18
    }
19
20
    public static function createFromString(string $value): self
21
    {
22
        return new self($value);
23
    }
24
25
    public static function createFromCallable(callable $callable): self
26
    {
27
        return new self($callable);
28
    }
29
30
    public function getValue(): string
31
    {
32
        if (is_callable($this->value)) {
33
            $this->value = call_user_func($this->value);
34
        }
35
36
        return $this->value;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->value could return the type callable which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
37
    }
38
}
39