Passed
Push — master ( b3d8d2...49adaa )
by Waaaaaaaaaa
02:33
created

Truncation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 23
ccs 8
cts 11
cp 0.7272
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 1
    public function __construct(string $payload, int $threshold = 1024)
12
    {
13 1
        $this->payload = $payload;
14 1
        $this->threshold = $threshold;
15 1
    }
16
17 1
    public function truncate(): string
18
    {
19 1
        $size = \mb_strlen($this->payload);
20
21 1
        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 1
        return $this->payload;
28
    }
29
}
30