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

contributte / utils / 6877995345

15 Nov 2023 01:31PM UTC coverage: 91.765% (+0.6%) from 91.124%
6877995345

push

github

f3l1x
Composer: require PHP 8.1+

312 of 340 relevant lines covered (91.76%)

0.92 hits per line

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

88.89
/src/Values/Email.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Utils\Values;
4

5
use Contributte\Utils\Exception\Runtime\InvalidEmailAddressException;
6
use Nette\Utils\Strings;
7
use Nette\Utils\Validators;
8

9
class Email
10
{
11

12
        private string $domainPart;
13

14
        private string $localPart;
15

16
        public function __construct(string $value)
1✔
17
        {
18
                if (!Validators::isEmail($value)) {
1✔
19
                        throw new InvalidEmailAddressException($value);
×
20
                }
21

22
                $parts = Strings::split($value, '~@~');
1✔
23
                $domain = array_pop($parts);
1✔
24

25
                // Try normalize the domain part
26
                if (function_exists('idn_to_ascii')) {
1✔
27
                        $normalizedDomain = idn_to_ascii($domain, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
1✔
28
                        if ($normalizedDomain !== false) {
1✔
29
                                $domain = $normalizedDomain;
1✔
30
                        }
31
                }
32

33
                $this->domainPart = $domain;
1✔
34
                $this->localPart = implode('@', $parts);
1✔
35
        }
1✔
36

37
        public function get(): string
38
        {
39
                return $this->getLocalPart() . '@' . $this->getDomainPart();
1✔
40
        }
41

42
        public function getLocalPart(): string
43
        {
44
                return $this->localPart;
1✔
45
        }
46

47
        public function getDomainPart(): string
48
        {
49
                return $this->domainPart;
1✔
50
        }
51

52
        public function equal(Email $email): bool
1✔
53
        {
54
                return $email->get() === $this->get();
1✔
55
        }
56

57
        public function __toString(): string
58
        {
59
                return $this->get();
×
60
        }
61

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