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

nette / forms / 28113569902

24 Jun 2026 04:27PM UTC coverage: 93.649% (+0.2%) from 93.412%
28113569902

push

github

dg
added CLAUDE.md

2138 of 2283 relevant lines covered (93.65%)

0.94 hits per line

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

96.77
/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

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

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

22

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

28

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

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

47
                return $this;
1✔
48
        }
49

50

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

56

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

69

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

83

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

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

101
                return $this;
1✔
102
        }
103

104

105
        /**
106
         * Returns a rendering option value.
107
         */
108
        public function getOption(string $key): mixed
1✔
109
        {
110
                return $this->options[$key] ?? null;
1✔
111
        }
112

113

114
        /**
115
         * Returns all rendering options.
116
         * @return array<string, mixed>
117
         */
118
        public function getOptions(): array
119
        {
120
                return $this->options;
1✔
121
        }
122
}
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