Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
Option
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setValue
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getValue
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 select
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 deselect
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 isSelected
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Form\Element\Select;
15
16use Pop\Dom\Child;
17
18/**
19 * Form select option element class
20 *
21 * @category   Pop
22 * @package    Pop\Form
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    4.0.0
27 */
28
29class Option extends Child
30{
31
32    /**
33     * Constructor
34     *
35     * Instantiate the option element object
36     *
37     * @param  string  $value
38     * @param  string  $nodeValue
39     * @param  array   $options
40     */
41    public function __construct(string $value, string $nodeValue, array $options = [])
42    {
43        parent::__construct('option', $nodeValue, $options);
44        $this->setValue($value);
45    }
46
47    /**
48     * Set the option value
49     *
50     * @param  mixed $value
51     * @return Option
52     */
53    public function setValue(mixed $value): Option
54    {
55        $this->setAttribute('value', $value);
56        return $this;
57    }
58
59    /**
60     * Get the option value
61     *
62     * @return ?string
63     */
64    public function getValue(): ?string
65    {
66        return $this->getAttribute('value');
67    }
68
69    /**
70     * Select the option value
71     *
72     * @return Option
73     */
74    public function select(): Option
75    {
76        $this->setAttribute('selected', 'selected');
77        return $this;
78    }
79
80    /**
81     * Deselect the option value
82     *
83     * @return Option
84     */
85    public function deselect(): Option
86    {
87        $this->removeAttribute('selected');
88        return $this;
89    }
90
91    /**
92     * Determine if the option value is selected
93     *
94     * @return bool
95     */
96    public function isSelected(): bool
97    {
98        return ($this->getAttribute('selected') == 'selected');
99    }
100
101}