Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
4 / 5
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Option
80.00% covered (warning)
80.00%
4 / 5
75.00% covered (warning)
75.00%
3 / 4
6.29
0.00% covered (danger)
0.00%
0 / 1
 __toString
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 unwrap
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
 json
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isset
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Value;
6
7use function Cosray\escape;
8
9class Option extends Value
10{
11    public function __toString(): string
12    {
13        return escape($this->unwrap());
14    }
15
16    public function unwrap(): string
17    {
18        $value = $this->value();
19
20        return is_string($value) || is_numeric($value) ? (string) $value : '';
21    }
22
23    public function json(): array
24    {
25        return $this->data;
26    }
27
28    public function isset(): bool
29    {
30        return $this->unwrap() !== '';
31    }
32}