ReportTrimmer::getMaxPayloadSize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Facade\FlareClient\Truncation;
4
5
class ReportTrimmer
6
{
7
    protected static $maxPayloadSize = 524288;
8
9
    protected $strategies = [
10
        TrimStringsStrategy::class,
11
        TrimContextItemsStrategy::class,
12
    ];
13
14
    public function trim(array $payload): array
15
    {
16
        foreach ($this->strategies as $strategy) {
17
            if (! $this->needsToBeTrimmed($payload)) {
18
                break;
19
            }
20
21
            $payload = (new $strategy($this))->execute($payload);
22
        }
23
24
        return $payload;
25
    }
26
27
    public function needsToBeTrimmed(array $payload): bool
28
    {
29
        return strlen(json_encode($payload)) > self::getMaxPayloadSize();
30
    }
31
32
    public static function getMaxPayloadSize(): int
33
    {
34
        return self::$maxPayloadSize;
35
    }
36
37
    public static function setMaxPayloadSize(int $maxPayloadSize): void
38
    {
39
        self::$maxPayloadSize = $maxPayloadSize;
40
    }
41
}
42