Lines
71.42%
5 / 7
Functions and Methods
50.00%
2 / 4
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| PushSubscription | 71.42% | 5 / 7 | 50.00% | 2 / 4 | 5.58 | 0.00% | 0 / 1 | |||
| __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 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Testing\Stream; | |
| 6 | ||
| 7 | use Closure; | |
| 8 | use Stewart\Contracts\Subscription; | |
| 9 | ||
| 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 | } |