• 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

88.89
/src/Forms/Controls/Checkbox.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\Controls;
9

10
use Nette;
11
use Nette\Utils\Html;
12
use Stringable;
13
use function is_scalar, sprintf;
14

15

16
/**
17
 * Checkbox control returning a boolean value.
18
 */
19
class Checkbox extends BaseControl
20
{
21
        private Html $container;
22

23

24
        public function __construct(string|Stringable|null $label = null)
1✔
25
        {
26
                parent::__construct($label);
1✔
27
                $this->control->type = 'checkbox';
1✔
28
                $this->container = Html::el();
1✔
29
                $this->setOption('type', 'checkbox');
1✔
30
        }
1✔
31

32

33
        /**
34
         * @return static
35
         * @internal
36
         */
37
        public function setValue($value)
38
        {
39
                if (!is_scalar($value) && $value !== null) {
1✔
40
                        throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or null, %s given in field '%s'.", get_debug_type($value), $this->getName()));
1✔
41
                }
42

43
                $this->value = (bool) $value;
1✔
44
                return $this;
1✔
45
        }
46

47

48
        public function isFilled(): bool
49
        {
50
                return $this->getValue() !== false; // back compatibility
1✔
51
        }
52

53

54
        public function getControl(): Html
55
        {
56
                return $this->container->setHtml($this->getLabelPart()->insert(0, $this->getControlPart()));
1✔
57
        }
58

59

60
        /**
61
         * Bypasses label generation.
62
         */
63
        public function getLabel($caption = null): Html|string|null
1✔
64
        {
65
                return null;
1✔
66
        }
67

68

69
        public function getControlPart(): Html
70
        {
71
                return parent::getControl()->checked($this->value);
1✔
72
        }
73

74

75
        public function getLabelPart(): Html
76
        {
77
                return parent::getLabel();
1✔
78
        }
79

80

81
        /**
82
         * Returns container HTML element template.
83
         */
84
        public function getContainerPrototype(): Html
85
        {
86
                return $this->container;
×
87
        }
88

89

90
        /** @deprecated  use getContainerPrototype() */
91
        public function getSeparatorPrototype(): Html
92
        {
93
                return $this->container;
×
94
        }
95
}
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