• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

conedevelopment / root / 20694177656

04 Jan 2026 02:13PM UTC coverage: 74.594% (-0.5%) from 75.049%
20694177656

push

github

iamgergo
version

3491 of 4680 relevant lines covered (74.59%)

32.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/src/Fields/Option.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Cone\Root\Fields;
6

7
use Closure;
8
use Cone\Root\Traits\HasAttributes;
9
use Cone\Root\Traits\Makeable;
10
use Illuminate\Contracts\Support\Arrayable;
11
use Illuminate\Support\Traits\Conditionable;
12
use JsonSerializable;
13

14
use function Illuminate\Support\enum_value;
15

16
class Option implements Arrayable, JsonSerializable
17
{
18
    use Conditionable;
19
    use HasAttributes;
20
    use Makeable;
21

22
    /**
23
     * The option label.
24
     */
25
    protected string $label;
26

27
    /**
28
     * Create a new option instance.
29
     */
30
    public function __construct(mixed $value, string $label)
10✔
31
    {
32
        $this->label = $label;
10✔
33
        $this->setAttribute('value', enum_value($value));
10✔
34
        $this->selected(false);
10✔
35
    }
36

37
    /**
38
     * Set the "disabled" HTML attribute.
39
     */
40
    public function disabled(bool $value = true): static
×
41
    {
42
        return $this->setAttribute('disabled', $value);
×
43
    }
44

45
    /**
46
     * Set the "selected" HTML attribute.
47
     */
48
    public function selected(bool|Closure $value = true): static
8✔
49
    {
50
        $value = $value instanceof Closure ? call_user_func_array($value, [$this]) : $value;
8✔
51

52
        return $this->setAttribute('selected', $value);
8✔
53
    }
54

55
    /**
56
     * Convert the element to a JSON serializable format.
57
     */
58
    public function jsonSerialize(): array
2✔
59
    {
60
        return $this->toArray();
2✔
61
    }
62

63
    /**
64
     * Get the array representation of the object.
65
     */
66
    public function toArray(): array
10✔
67
    {
68
        return [
10✔
69
            'attrs' => $this->newAttributeBag(),
10✔
70
            'label' => $this->label,
10✔
71
            'selected' => $this->getAttribute('selected'),
10✔
72
            'value' => $this->getAttribute('value'),
10✔
73
        ];
10✔
74
    }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc