Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Optgroup
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addOption
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addOptions
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getOptions
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
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 optgroup 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 Optgroup extends Child
30{
31
32    /**
33     * Constructor
34     *
35     * Instantiate the option element object
36     *
37     * @param  ?string $value
38     * @param  array   $options
39     */
40    public function __construct(?string $value = null, array $options = [])
41    {
42        parent::__construct('optgroup', $value, $options);
43    }
44
45    /**
46     * Add an option element
47     *
48     * @param  Child $option
49     * @return Optgroup
50     */
51    public function addOption(Child $option): Optgroup
52    {
53        $this->addChild($option);
54        return $this;
55    }
56
57    /**
58     * Add option elements
59     *
60     * @param  array $options
61     * @return Optgroup
62     */
63    public function addOptions(array $options): Optgroup
64    {
65        $this->addChildren($options);
66        return $this;
67    }
68
69    /**
70     * Get option elements
71     *
72     * @return array
73     */
74    public function getOptions(): array
75    {
76        $options = [];
77
78        foreach ($this->childNodes as $child) {
79            if ($child instanceof Option) {
80                $options[] = $child;
81            }
82        }
83
84        return $options;
85    }
86
87}