Value   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 30
ccs 0
cts 18
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromString() 0 3 1
A getValue() 0 7 2
A createFromCallable() 0 3 1
A __construct() 0 3 1
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