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

nepada / form-renderer / 4066231894

pending completion
4066231894

Pull #101

github

GitHub
Merge bfe15b2cf into e9ceeb336
Pull Request #101: Update spaze/phpstan-disallowed-calls requirement from 2.11.2 to 2.11.5

244 of 262 relevant lines covered (93.13%)

0.93 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
    public function __invoke(Nette\Forms\Control $control): ?string
24
    {
25
        if (count($control->getErrors()) > 0) {
1✔
26
            return $this->invalidClass;
1✔
27
        }
28

29
        if ($this->isFilled($control)) {
1✔
30
            return $this->validClass;
1✔
31
        }
32

33
        return null;
1✔
34
    }
35

36
    private function isFilled(Nette\Forms\Control $control): bool
37
    {
38
        if ($control instanceof Nette\Forms\Controls\TextInput && $control->getControlPrototype()->type === 'password') {
1✔
39
            return false;
1✔
40
        }
41

42
        if ($control instanceof Nette\Forms\Controls\BaseControl || method_exists($control, 'isFilled')) {
1✔
43
            return $control->isFilled();
1✔
44
        }
45

46
        $value = $control->getValue();
1✔
47
        return $value !== null && $value !== [] && $value !== '';
1✔
48
    }
49

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