Lines 100.00% 7 / 7
Methods 100.00% 4 / 4
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 unsubscribe 100.00% 4 / 4 100.00% 1 / 1 2
 isActive 100.00% 1 / 1 100.00% 1 / 1 1
 getId 100.00% 1 / 1 100.00% 1 / 1 1
11final class LocalSubscription implements Subscription
12{
13    private bool $active = true;
14
15    /** @param Closure(SubscriptionId): void $onCancel */
16    public function __construct(
17        private readonly SubscriptionId $id,
18        private readonly Closure $onCancel,
19    ) {}
20
21    public function unsubscribe(): void
22    {
23        if (!$this->active) {
24            return;
25        }
26
27        $this->active = false;
28        ($this->onCancel)($this->id);
29    }
30
31    public function isActive(): bool
32    {
33        return $this->active;
34    }
35
36    public function getId(): string
37    {
38        return $this->id->value;
39    }
40}