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:56
created

Base64Encoder   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 18
c 1
b 0
f 0
dl 0
loc 45
ccs 21
cts 21
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A decode() 0 9 2
A decodeUrlSafe() 0 15 4
A encodeUrlSafe() 0 10 2
A encode() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Util;
6
7
final class Base64Encoder
8
{
9 101
    public static function encode(string $value): string
10
    {
11 101
        return \base64_encode($value);
12
    }
13
14 62
    public static function decode(string $value, bool $strict = true): string
15
    {
16 62
        $result = \base64_decode($value, $strict);
17
18 62
        if (false === $result) {
19 1
            throw new \InvalidArgumentException(\sprintf('The "%s" value failed to be decoded from base64 format.', $value));
20
        }
21
22 61
        return $result;
23
    }
24
25 22
    public static function encodeUrlSafe(string $value, bool $padding = false): string
26
    {
27 22
        $result = \base64_encode($value);
28 22
        $result = \str_replace(['+', '/'], ['-', '_'], $result);
29
30 22
        if (!$padding) {
31 16
            $result = \str_replace('=', '', $result);
32
        }
33
34 22
        return $result;
35
    }
36
37 24
    public static function decodeUrlSafe(string $value, bool $strict = true): string
38
    {
39 24
        $value = \str_replace(['-', '_'], ['+', '/'], $value);
40
41 24
        if (0 === \substr_compare($value, '=', -1) && 0 !== \strlen($value) % 4) {
42 1
            $value = \str_pad($value, (\strlen($value) + 3) & ~3, '=');
43
        }
44
45 24
        $result = \base64_decode($value, $strict);
46
47 24
        if (false === $result) {
48 1
            throw new \InvalidArgumentException(\sprintf('The "%s" value failed to be decoded from base64 format.', $value));
49
        }
50
51 23
        return $result;
52
    }
53
}
54