Lines
100.00%
9 / 9
Functions and Methods
100.00%
5 / 5
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ServiceCallPolicy | 100.00% | 9 / 9 | 100.00% | 5 / 5 | 5 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| fromSection | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 1 | |||||
| limitsPerWorker | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| boundsTotal | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| createDryRunContext | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Config; | |
| 6 | ||
| 7 | use Stewart\Contracts\State\EventContext; | |
| 8 | use Stewart\Runtime\Exception\ConfigurationException; | |
| 9 | use Stewart\Runtime\Model\CorrelationId; | |
| 10 | ||
| 11 | final readonly class ServiceCallPolicy | |
| 12 | { | |
| 13 | private const string DRY_RUN_CONTEXT_PREFIX = 'dry-run:'; | |
| 14 | ||
| 15 | public function __construct( | |
| 16 | public int $perWorker, | |
| 17 | public int $total, | |
| 18 | public bool $dryRun = false, | |
| 19 | ) {} | |
| 20 | ||
| 21 | /** @throws ConfigurationException */ | |
| 22 | public static function fromSection(ConfigSection $serviceCalls): self | |
| 23 | { | |
| 24 | return new self( | |
| 25 | perWorker: $serviceCalls->readInt('max_in_flight_per_worker'), | |
| 26 | total: $serviceCalls->readInt('max_in_flight'), | |
| 27 | dryRun: $serviceCalls->readBool('dry_run'), | |
| 28 | ); | |
| 29 | } | |
| 30 | ||
| 31 | public function limitsPerWorker(): bool | |
| 32 | { | |
| 33 | return $this->perWorker > 0; | |
| 34 | } | |
| 35 | ||
| 36 | public function boundsTotal(): bool | |
| 37 | { | |
| 38 | return $this->total > 0; | |
| 39 | } | |
| 40 | ||
| 41 | public function createDryRunContext(CorrelationId $correlationId): EventContext | |
| 42 | { | |
| 43 | return new EventContext(self::DRY_RUN_CONTEXT_PREFIX . $correlationId->value); | |
| 44 | } | |
| 45 | } |