Assertion   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A email() 0 7 3
A notNull() 0 7 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nordic\EmailAddress;
6
7
/**
8
 * Assertion class
9
 */
10
final class Assertion
11
{
12 42
    public static function email(string $email, string $message = ''): string
13
    {
14 42
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
15 12
            throw new InvalidEmailAddressException($email, $message ?: sprintf('Expected valid email address string. Got: `%s`', $email));
16
        }
17
18 30
        return $email;
19
    }
20
21 6
    public static function notNull(EmailAddressInterface $emailAddress, string $message = ''): EmailAddressInterface
22
    {
23 6
        if ($emailAddress instanceof NullEmailAddress) {
24 3
            throw new InvalidEmailAddressException((string)$emailAddress, $message ?: 'Null email address is not allowed');
25
        }
26
27 3
        return $emailAddress;
28
    }
29
}
30