| Total Complexity | 7 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 7 | final class Value implements \Stringable |
||
| 8 | { |
||
| 9 | private string $value; |
||
| 10 | |||
| 11 | |||
| 12 | 48 | public function __construct( |
|
| 13 | string $value, |
||
| 14 | private ?string $quote = null |
||
| 15 | ) { |
||
| 16 | 48 | $this->value = $this->handleValue($value); |
|
| 17 | } |
||
| 18 | |||
| 19 | 48 | private function handleValue(string $value): string |
|
| 20 | { |
||
| 21 | 48 | if (preg_match('/#+/', $value)) { |
|
| 22 | 6 | $this->quote = '"'; |
|
| 23 | } |
||
| 24 | 48 | if (preg_match('/^["\']+/', $value)) { |
|
| 25 | 24 | $this->quote = null; |
|
| 26 | } |
||
| 27 | 48 | return $this->quote ? sprintf('%2$s%1$s%2$s', $value, $this->quote) : $value; |
|
| 28 | } |
||
| 29 | |||
| 30 | 5 | public function __toString(): string |
|
| 31 | { |
||
| 32 | 5 | return $this->value; |
|
| 33 | } |
||
| 34 | |||
| 35 | 43 | public function getValue(): string |
|
| 38 | } |
||
| 39 | |||
| 40 | } |
||
| 41 |