Lines 100.00% 7 / 7
Functions and Methods 100.00% 4 / 4
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
LocalSubscription 100.00% 7 / 7 100.00% 4 / 4 5 100.00% 1 / 1
 __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
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Dispatch;
6
7use Closure;
8use Stewart\Contracts\Subscription;
9use Stewart\Runtime\Model\SubscriptionId;
10
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}