Sender::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupMiddleware\CommandHandlingBundle\Value;
20
21
use Stringable;
22
use Surfnet\StepupMiddleware\CommandHandlingBundle\Exception\InvalidArgumentException;
23
24
class Sender implements Stringable
25
{
26
    private readonly string $email;
27
28
    public function __construct(private readonly string $name, string $email)
29
    {
30
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
31
            throw new InvalidArgumentException(
32
                sprintf("Invalid argument type: expected e-mail address for 'email', got '%s'", $email),
33
            );
34
        }
35
        $this->email = $email;
0 ignored issues
show
Bug introduced by
The property email is declared read-only in Surfnet\StepupMiddleware...lingBundle\Value\Sender.
Loading history...
36
    }
37
38
    public function equals(Sender $other): bool
39
    {
40
        return $this == $other;
41
    }
42
43
    public function getName(): string
44
    {
45
        return $this->name;
46
    }
47
48
    public function getEmail(): string
49
    {
50
        return $this->email;
51
    }
52
53
    public function __toString(): string
54
    {
55
        return sprintf('%s <%s>', $this->name, $this->email);
56
    }
57
}
58