Passed
Push — master ( d14e7d...cb0a20 )
by Mariano
02:08
created

BodyHelper::getBodyObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
1
<?php
2
3
namespace Mcustiel\Phiremock\Common\Utils;
4
5
use Mcustiel\Phiremock\Domain\BinaryInfo;
6
use Mcustiel\Phiremock\Domain\Http\BinaryBody;
7
use Mcustiel\Phiremock\Domain\Http\Body;
8
9
class BodyHelper
10
{
11 2
    public static function getBodyObject(string $body): Body
12
    {
13 2
        if (!self::isBinaryBody($body)) {
14 2
            return new Body($body);
15
        }
16
17
        return new BinaryBody(self::decodeNetworkSafeBinaryBody($body));
18
    }
19
20
    private static function decodeNetworkSafeBinaryBody(string $body): string
21
    {
22
        return base64_decode(substr($body, BinaryInfo::BINARY_BODY_PREFIX_LENGTH), true);
23
    }
24
25 2
    private static function isBinaryBody(string $body): bool
26
    {
27 2
        return BinaryInfo::BINARY_BODY_PREFIX === substr($body, 0, BinaryInfo::BINARY_BODY_PREFIX_LENGTH);
28
    }
29
}
30