Lines
100.00%
9 / 9
Methods
100.00%
5 / 5
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __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 | ||
| 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 | } |