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

nepada / form-renderer / 7356952821

29 Dec 2023 01:10PM UTC coverage: 97.275%. First build
7356952821

push

github

xificurk
Bootstrap 5: add support for floating labels in basic mode

357 of 367 relevant lines covered (97.28%)

0.97 hits per line

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

100.0
/src/FormRenderer/Filters/ValidationClassFilter.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\FormRenderer\Filters;
5

6
use Nette;
7

8
final class ValidationClassFilter
1✔
9
{
10

11
    use Nette\SmartObject;
12

13
    private ?string $invalidClass;
14

15
    private ?string $validClass;
16

17
    public function __construct(?string $invalidClass, ?string $validClass)
18
    {
19
        $this->invalidClass = $invalidClass;
1✔
20
        $this->validClass = $validClass;
1✔
21
    }
1✔
22

23
    /**
24
     * @template T
25
     * @param Nette\Forms\Control<T> $control
26
     */
27
    public function __invoke(Nette\Forms\Control $control): ?string
28
    {
29
        if (count($control->getErrors()) > 0) {
1✔
30
            return $this->invalidClass;
1✔
31
        }
32

33
        if ($this->isFilled($control)) {
1✔
34
            return $this->validClass;
1✔
35
        }
36

37
        return null;
1✔
38
    }
39

40
    /**
41
     * @template T
42
     * @param Nette\Forms\Control<T> $control
43
     */
44
    private function isFilled(Nette\Forms\Control $control): bool
45
    {
46
        if ($control instanceof Nette\Forms\Controls\TextInput && $control->getControlPrototype()->type === 'password') {
1✔
47
            return false;
1✔
48
        }
49

50
        if ($control instanceof Nette\Forms\Controls\BaseControl || method_exists($control, 'isFilled')) {
1✔
51
            return $control->isFilled();
1✔
52
        }
53

54
        $value = $control->getValue();
1✔
55
        return $value !== null && $value !== [] && $value !== '';
1✔
56
    }
57

58
}
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