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

nette / forms / 26452888331

26 May 2026 02:01PM UTC coverage: 93.307% (+0.07%) from 93.241%
26452888331

push

github

dg
added CLAUDE.md

2105 of 2256 relevant lines covered (93.31%)

0.93 hits per line

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

91.18
/src/Forms/ControlGroup.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Nette\Forms;
9

10
use function func_num_args;
11

12

13
/**
14
 * Named group of form controls, typically rendered as a fieldset.
15
 */
16
class ControlGroup
17
{
18
        /** @var \WeakMap<Control, null> */
19
        protected \WeakMap $controls;
20

21
        /** @var array<string, mixed> */
22
        private array $options = [];
23

24

25
        public function __construct()
26
        {
27
                $this->controls = new \WeakMap;
1✔
28
        }
1✔
29

30

31
        /** @param Control|Container|iterable<Control|Container> ...$items */
32
        public function add(Control|Container|iterable ...$items): static
1✔
33
        {
34
                foreach ($items as $item) {
1✔
35
                        if ($item instanceof Control) {
1✔
36
                                $this->controls[$item] = null;
1✔
37

38
                        } elseif ($item instanceof Container) {
1✔
39
                                foreach ($item->getComponents() as $component) {
1✔
40
                                        if ($component instanceof Control || $component instanceof Container) {
1✔
41
                                                $this->add($component);
1✔
42
                                        }
43
                                }
44
                        } else {
45
                                $this->add(...$item);
×
46
                        }
47
                }
48

49
                return $this;
1✔
50
        }
51

52

53
        public function remove(Control $control): void
1✔
54
        {
55
                unset($this->controls[$control]);
1✔
56
        }
1✔
57

58

59
        /**
60
         * Removes controls that are no longer attached to a form.
61
         */
62
        public function removeOrphans(): void
63
        {
64
                foreach ($this->controls as $control => $foo) {
1✔
65
                        if (!$control->getForm(false)) {
1✔
66
                                unset($this->controls[$control]);
1✔
67
                        }
68
                }
69
        }
1✔
70

71

72
        /**
73
         * Returns all controls in this group.
74
         * @return list<Control>
75
         */
76
        public function getControls(): array
77
        {
78
                $res = [];
1✔
79
                foreach ($this->controls as $control => $foo) {
1✔
80
                        $res[] = $control;
1✔
81
                }
82
                return $res;
1✔
83
        }
84

85

86
        /**
87
         * Sets a rendering option. Options recognized by DefaultFormRenderer:
88
         * - 'label' - group label (string or HtmlStringable)
89
         * - 'visual' - whether the group is rendered as a visual fieldset
90
         * - 'container' - custom container Html element
91
         * - 'description' - group description (string or HtmlStringable)
92
         * - 'embedNext' - whether to embed the next group inside this group's container
93
         */
94
        public function setOption(string $key, mixed $value): static
1✔
95
        {
96
                if ($value === null) {
1✔
97
                        unset($this->options[$key]);
1✔
98

99
                } else {
100
                        $this->options[$key] = $value;
1✔
101
                }
102

103
                return $this;
1✔
104
        }
105

106

107
        /**
108
         * Returns a rendering option value.
109
         */
110
        public function getOption(string $key): mixed
1✔
111
        {
112
                if (func_num_args() > 1) {
1✔
113
                        trigger_error(__METHOD__ . '() parameter $default is deprecated, use operator ??', E_USER_DEPRECATED);
×
114
                        $default = func_get_arg(1);
×
115
                }
116
                return $this->options[$key] ?? $default ?? null;
1✔
117
        }
118

119

120
        /**
121
         * Returns all rendering options.
122
         * @return array<string, mixed>
123
         */
124
        public function getOptions(): array
125
        {
126
                return $this->options;
1✔
127
        }
128
}
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