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

BodyHelper::decodeNetworkSafeBinaryBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

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 0
cts 2
cp 0
crap 2
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