Issues (868)

app/Services/Backfill/BackfillConfig.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Services\Backfill;
6
7
use App\Models\Settings;
8
9
/**
10
 * Configuration DTO for Backfill processing.
11
 * Encapsulates all settings in an immutable object for easier testing and injection.
12
 */
13
final readonly class BackfillConfig
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_READONLY, expecting T_CLASS on line 13 at column 6
Loading history...
14
{
15
    public function __construct(
16
        public bool $compressedHeaders = true,
17
        public bool $echoCli = false,
18
        public string $safeBackFillDate = '2012-08-14',
19
        public string $safePartRepair = 'backfill',
20
        public bool $disableBackfillGroup = false,
21
    ) {}
22
23
    /**
24
     * Create configuration from application settings.
25
     */
26
    public static function fromSettings(): self
27
    {
28
        return new self(
29
            compressedHeaders: (bool) config('nntmux_nntp.compressed_headers'),
30
            echoCli: (bool) config('nntmux.echocli'),
31
            safeBackFillDate: self::getSettingString('safebackfilldate', '2012-08-14'),
32
            safePartRepair: self::getSettingInt('safepartrepair', 0) === 1 ? 'update' : 'backfill',
33
            disableBackfillGroup: self::getSettingInt('disablebackfillgroup', 0) === 1,
34
        );
35
    }
36
37
    private static function getSettingString(string $key, string $default): string
38
    {
39
        $value = Settings::settingValue($key);
40
41
        return $value !== '' ? (string) $value : $default;
42
    }
43
44
    private static function getSettingInt(string $key, int $default): int
45
    {
46
        $value = Settings::settingValue($key);
47
48
        return $value !== '' ? (int) $value : $default;
49
    }
50
}
51
52