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

nepada / email-address-input / 41030319538

30 Oct 2026 09:00AM UTC coverage: 96.226% (-0.07%) from 96.296%
41030319538

push

github

xificurk
Fix PHPStan with nette/forms 3.3.1

nette/forms 3.3.1 types the extensionMethod() callback parameters as never, so the cast of $name is reported as useless and the ignore needed since 3.2.9 no longer matches.

Co-Authored-By: Claude Code

51 of 53 relevant lines covered (96.23%)

0.96 hits per line

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

94.74
/src/EmailAddressInput/EmailAddressInput.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\EmailAddressInput;
5

6
use Nepada\EmailAddress\CaseInsensitiveEmailAddress;
7
use Nepada\EmailAddress\EmailAddress;
8
use Nepada\EmailAddress\InvalidEmailAddressException;
9
use Nepada\EmailAddress\RfcEmailAddress;
10
use Nette\Forms\Controls\TextInput;
11
use Nette\Forms\Form;
12
use Nette\Utils\Html;
13
use Nette\Utils\Strings;
14

15
class EmailAddressInput extends TextInput
16
{
17

18
    public function __construct(
1 ✔
19
        string|Html|null $label = null,
20
        ?int $maxLength = null,
21
        private bool $caseSensitive = false,
22
    )
23
    {
24
        parent::__construct($label, $maxLength);
1 ✔
25
        $this->setNullable();
1 ✔
26
        $this->addRule(Form::EMAIL);
1 ✔
27
    }
1 ✔
28

29
    public function setCaseSensitive(bool $caseSensitive): void
1 ✔
30
    {
31
        $this->caseSensitive = $caseSensitive;
1 ✔
32
    }
1 ✔
33

34
    public function getValue(): ?EmailAddress
35
    {
36
        /** @var EmailAddress|null $value */
37
        $value = parent::getValue();
1 ✔
38
        return $value;
1 ✔
39
    }
40

41
    /**
42
     * @internal
43
     * @return $this
44
     */
45
    public function setValue(mixed $value): static
1 ✔
46
    {
47
        if (is_string($value) || $value instanceof EmailAddress) {
1 ✔
48
            $value = $this->toEmailAddress($value);
1 ✔
49
        } elseif ($value !== null) {
1 ✔
50
            throw new \InvalidArgumentException(
1 ✔
51
                sprintf(
1 ✔
52
                    'Value must be null, EmailAddress instance, or string with a valid email address, %s given in field "%s".',
1 ✔
53
                    gettype($value),
1 ✔
54
                    $this->getName(),
1 ✔
55
                ),
56
            );
57
        }
58

59
        parent::setValue($value);
1 ✔
60
        return $this;
1 ✔
61
    }
62

63
    /**
64
     * @param EmailAddress|string|null $value
65
     * @return $this
66
     */
67
    public function setDefaultValue(mixed $value): static
68
    {
69
        parent::setDefaultValue($value);
×
70
        return $this;
×
71
    }
72

73
    public function loadHttpData(): void
74
    {
75
        /** @var string $value */
76
        $value = $this->getHttpData(Form::DATA_LINE);
1 ✔
77

78
        if ($value === '' || $value === Strings::trim($this->translate($this->emptyValue))) {
1 ✔
79
            $this->value = null;
1 ✔
80
            $this->rawValue = $value;
1 ✔
81
            return;
1 ✔
82
        }
83

84
        try {
85
            $this->setValue($value);
1 ✔
86
        } catch (InvalidEmailAddressException $exception) {
1 ✔
87
            $this->value = null;
1 ✔
88
            $this->rawValue = $value;
1 ✔
89
        }
90
    }
1 ✔
91

92
    public function isFilled(): bool
93
    {
94
        return $this->rawValue !== '' && $this->rawValue !== Strings::trim($this->translate($this->emptyValue));
1 ✔
95
    }
96

97
    /**
98
     * @throws InvalidEmailAddressException
99
     */
100
    private function toEmailAddress(string|EmailAddress $value): EmailAddress
1 ✔
101
    {
102
        if ($this->caseSensitive) {
1 ✔
103
            return RfcEmailAddress::fromString((string) $value);
1 ✔
104
        }
105

106
        return CaseInsensitiveEmailAddress::fromString((string) $value);
1 ✔
107
    }
108

109
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc