| 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
Loading history...
|
|||
| 37 | } |
||
| 38 | } |
||
| 39 |