Assertion::notNull()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 3
rs 10
c 0
b 0
f 0
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