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

nette / forms / 20472712574

23 Dec 2025 10:10PM UTC coverage: 93.282% (-0.1%) from 93.405%
20472712574

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%)

22 existing lines in 4 files now uncovered.

2069 of 2218 relevant lines covered (93.28%)

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
        private array $options = [];
22

23

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

29

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

43
                        } else {
UNCOV
44
                                $type = get_debug_type($item);
×
45
                                throw new Nette\InvalidArgumentException("Control or Container items expected, $type given.");
×
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
        public function removeOrphans(): void
60
        {
61
                foreach ($this->controls as $control => $foo) {
1✔
62
                        if (!$control->getForm(false)) {
1✔
63
                                unset($this->controls[$control]);
1✔
64
                        }
65
                }
66
        }
1✔
67

68

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

79

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

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

98
                return $this;
1✔
99
        }
100

101

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

110

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

© 2025 Coveralls, Inc