BodySummarizer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Swis\Guzzle\Bugsnag;
6
7
use GuzzleHttp\BodySummarizerInterface;
8
use GuzzleHttp\Psr7\Message;
9
use Psr\Http\Message\MessageInterface;
10
use Psr\Http\Message\ResponseInterface;
11
12
final class BodySummarizer implements BodySummarizerInterface
13
{
14
    private int $truncateAt;
15
16 90
    public function __construct(int $truncateAt)
17
    {
18 90
        $this->truncateAt = $truncateAt;
19 45
    }
20
21
    /**
22
     * {@inheritDoc}
23
     */
24 66
    public function summarize(MessageInterface $message): ?string
25
    {
26 66
        if (!$message instanceof ResponseInterface || $message->getStatusCode() < 400) {
27 60
            return null;
28
        }
29
30 6
        return Message::bodySummary($message, $this->truncateAt);
31
    }
32
}
33