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