TrimContextItemsStrategy::iterateContextItems()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Facade\FlareClient\Truncation;
4
5
class TrimContextItemsStrategy extends AbstractTruncationStrategy
6
{
7
    public static function thresholds()
8
    {
9
        return [100, 50, 25, 10];
10
    }
11
12 View Code Duplication
    public function execute(array $payload): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
    {
14
        foreach (static::thresholds() as $threshold) {
15
            if (! $this->reportTrimmer->needsToBeTrimmed($payload)) {
16
                break;
17
            }
18
19
            $payload['context'] = $this->iterateContextItems($payload['context'], $threshold);
20
        }
21
22
        return $payload;
23
    }
24
25
    protected function iterateContextItems(array $contextItems, int $threshold): array
26
    {
27
        array_walk($contextItems, [$this, 'trimContextItems'], $threshold);
28
29
        return $contextItems;
30
    }
31
32
    protected function trimContextItems(&$value, $key, int $threshold)
33
    {
34
        if (is_array($value)) {
35
            if (count($value) > $threshold) {
36
                $value = array_slice($value, $threshold * -1, $threshold);
37
            }
38
39
            array_walk($value, [$this, 'trimContextItems'], $threshold);
40
        }
41
42
        return $value;
43
    }
44
}
45