Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#678)
by Stefano
10:59
created

Base64Encoder::encodeUrlSafe()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Util;
6
7
final class Base64Encoder
8
{
9 107
    public static function encodeUrlSafe(string $value, bool $padding = false): string
10
    {
11 107
        $result = \base64_encode($value);
12 107
        $result = \str_replace(['+', '/'], ['-', '_'], $result);
13
14 107
        if (!$padding) {
15 101
            $result = \str_replace('=', '', $result);
16
        }
17
18 107
        return $result;
19
    }
20
21 68
    public static function decodeUrlSafe(string $value, bool $strict = true): string
22
    {
23 68
        $value = \str_replace(['-', '_'], ['+', '/'], $value);
24
25 68
        if (0 === \strrpos($value, '=', -1) && 0 !== \strlen($value) % 4) {
26
            $value = \str_pad($value, (\strlen($value) + 3) & ~3, '=');
27
        }
28
29 68
        $result = \base64_decode($value, $strict);
30
31 68
        if (false === $result) {
32 1
            throw new \InvalidArgumentException(\sprintf('The "%s" value failed to be decoded from base64 format.', $value));
33
        }
34
35 67
        return $result;
36
    }
37
}
38