Subscription::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 10
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace PersonalGalaxy\RSS\Entity;
5
6
use PersonalGalaxy\RSS\{
7
    Entity\Subscription\Identity,
8
    Entity\Subscription\User,
9
    Entity\Subscription\Name,
10
    Event\SubscriptionWasAdded,
11
    Event\SubscriptionWasRemoved,
12
};
13
use Innmind\EventBus\{
14
    ContainsRecordedEventsInterface,
15
    EventRecorder,
16
};
17
use Innmind\Url\UrlInterface;
18
19
final class Subscription implements ContainsRecordedEventsInterface
20
{
21
    use EventRecorder;
22
23
    private $identity;
24
    private $user;
25
    private $name;
26
    private $location;
27
28 5
    private function __construct(
29
        Identity $identity,
30
        User $user,
31
        Name $name,
32
        UrlInterface $location
33
    ) {
34 5
        $this->identity = $identity;
35 5
        $this->user = $user;
36 5
        $this->name = $name;
37 5
        $this->location = $location;
38 5
    }
39
40 5
    public static function add(
41
        Identity $identity,
42
        User $user,
43
        Name $name,
44
        UrlInterface $location
45
    ): self {
46 5
        $self = new self($identity, $user, $name, $location);
47 5
        $self->record(new SubscriptionWasAdded($identity, $user, $name, $location));
48
49 5
        return $self;
50
    }
51
52 3
    public function identity(): Identity
53
    {
54 3
        return $this->identity;
55
    }
56
57 2
    public function user(): User
58
    {
59 2
        return $this->user;
60
    }
61
62 2
    public function name(): Name
63
    {
64 2
        return $this->name;
65
    }
66
67 3
    public function location(): UrlInterface
68
    {
69 3
        return $this->location;
70
    }
71
72 2
    public function remove(): void
73
    {
74 2
        $this->record(new SubscriptionWasRemoved($this->identity));
75 2
    }
76
}
77
78