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

nette / forms / 15763260878

19 Jun 2025 05:19PM UTC coverage: 93.011%. Remained the same
15763260878

push

github

dg
netteForms: restructured package, includes UMD and ESM (BC break)

2076 of 2232 relevant lines covered (93.01%)

0.93 hits per line

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

83.33
/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
use function func_num_args;
14

15

16
/**
17
 * A user group of form controls.
18
 */
19
class ControlGroup
20
{
21
        protected \WeakMap $controls;
22
        private array $options = [];
23

24

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

30

31
        public function add(...$items): static
1✔
32
        {
33
                foreach ($items as $item) {
1✔
34
                        if ($item instanceof Control) {
1✔
35
                                $this->controls[$item] = null;
1✔
36

37
                        } elseif ($item instanceof Container) {
1✔
38
                                foreach ($item->getComponents() as $component) {
1✔
39
                                        $this->add($component);
1✔
40
                                }
41
                        } elseif (is_iterable($item)) {
×
42
                                $this->add(...$item);
×
43

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

50
                return $this;
1✔
51
        }
52

53

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

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

80

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

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

99
                return $this;
1✔
100
        }
101

102

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

115

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