ReportTrimmer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A trim() 0 12 3
A needsToBeTrimmed() 0 4 1
A getMaxPayloadSize() 0 4 1
A setMaxPayloadSize() 0 4 1
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