Test Failed
Push — master ( 5f8db2...b3d8d2 )
by Waaaaaaaaaa
02:26
created

Truncation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 23
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A truncate() 0 11 2
1
<?php declare(strict_types=1);
2
3
namespace Logfile\Inspection;
4
5
class Truncation
6
{
7
    protected $payload;
8
9
    protected $threshold;
10
11
    public function __construct(string $payload, int $threshold = 1024)
12
    {
13
        $this->payload = $payload;
14
        $this->threshold = $threshold;
15
    }
16
17
    public function truncate(): string
18
    {
19
        $size = \mb_strlen($this->payload);
20
21
        if ($size > $this->threshold) {
22
            $newPayload = \mb_substr($this->payload, 0, $this->threshold);
23
            $truncated = $size - $this->threshold;
24
            return \sprintf('%s .. (truncated %d)', $newPayload, $truncated);
25
        }
26
27
        return $this->payload;
28
    }
29
}
30