Lines
100.00%
13 / 13
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| AppOverride | 100.00% | 13 / 13 | 100.00% | 2 / 2 | 4 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| fromSection | 100.00% | 12 / 12 | 100.00% | 1 / 1 | 3 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Config; | |
| 6 | ||
| 7 | use Stewart\Contracts\App\AppId; | |
| 8 | use Stewart\Contracts\Exception\IdentifierException; | |
| 9 | use Stewart\Runtime\Exception\ConfigurationException; | |
| 10 | use Stewart\Runtime\Model\LogLevel; | |
| 11 | ||
| 12 | final readonly class AppOverride | |
| 13 | { | |
| 14 | /** @param array<string, mixed> $options */ | |
| 15 | public function __construct( | |
| 16 | public AppId $id, | |
| 17 | public bool $enabled, | |
| 18 | public bool $paused, | |
| 19 | public ?int $worker, | |
| 20 | public array $options, | |
| 21 | public ?LogLevel $logLevel = null, | |
| 22 | public bool $trace = false, | |
| 23 | public ?string $class = null, | |
| 24 | ) {} | |
| 25 | ||
| 26 | /** | |
| 27 | * @throws ConfigurationException | |
| 28 | * @throws IdentifierException | |
| 29 | */ | |
| 30 | public static function fromSection(ConfigSection $app, string $id): self | |
| 31 | { | |
| 32 | $logLevel = $app->findString('log_level'); | |
| 33 | $class = ltrim($app->findString('class') ?? '', '\\'); | |
| 34 | ||
| 35 | return new self( | |
| 36 | id: new AppId($id), | |
| 37 | enabled: $app->readBool('enabled'), | |
| 38 | paused: $app->readBool('paused'), | |
| 39 | worker: $app->findInt('worker'), | |
| 40 | options: $app->readMap('options'), | |
| 41 | logLevel: $logLevel === null ? null : LogLevel::from($logLevel), | |
| 42 | trace: $app->readBool('trace'), | |
| 43 | class: $class === '' ? null : $class, | |
| 44 | ); | |
| 45 | } | |
| 46 | } |