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

nette / forms / 20836962018

09 Jan 2026 12:35AM UTC coverage: 93.481%. Remained the same
20836962018

push

github

dg
Container::setValues() and setDefaults() accepts array|Traversable|stdClass (BC break)

3 of 4 new or added lines in 1 file covered. (75.0%)

44 existing lines in 9 files now uncovered.

2065 of 2209 relevant lines covered (93.48%)

0.93 hits per line

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

87.88
/src/Forms/ControlGroup.php
1
<?php
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
declare(strict_types=1);
9

10
namespace Nette\Forms;
11

12
use Nette;
13

14

15
/**
16
 * A user group of form controls.
17
 */
18
class ControlGroup
19
{
20
        protected \WeakMap $controls;
21

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

25

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

31

32
        public function add(...$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
                                        $this->add($component);
1✔
41
                                }
UNCOV
42
                        } elseif (is_iterable($item)) {
×
UNCOV
43
                                $this->add(...$item);
×
44

45
                        } else {
UNCOV
46
                                $type = get_debug_type($item);
×
UNCOV
47
                                throw new Nette\InvalidArgumentException("Control or Container items expected, $type given.");
×
48
                        }
49
                }
50

51
                return $this;
1✔
52
        }
53

54

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

60

61
        public function removeOrphans(): void
62
        {
63
                foreach ($this->controls as $control => $foo) {
1✔
64
                        if (!$control->getForm(false)) {
1✔
65
                                unset($this->controls[$control]);
1✔
66
                        }
67
                }
68
        }
1✔
69

70

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

81

82
        /**
83
         * Sets user-specific option.
84
         * Options recognized by DefaultFormRenderer
85
         * - 'label' - textual or Nette\HtmlStringable object label
86
         * - 'visual' - indicates visual group
87
         * - 'container' - container as Html object
88
         * - 'description' - textual or Nette\HtmlStringable object description
89
         * - 'embedNext' - describes how render next group
90
         */
91
        public function setOption(string $key, mixed $value): static
1✔
92
        {
93
                if ($value === null) {
1✔
94
                        unset($this->options[$key]);
1✔
95

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

100
                return $this;
1✔
101
        }
102

103

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

112

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