GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

FileSignatureUtils::hasSignature()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 2
crap 2
1
<?php
2
3
namespace WebservicesNl\Utils;
4
5
/**
6
 * Class FileSignatureUtils
7
 */
8
class FileSignatureUtils
9
{
10
    const PNG = '89504E470D0A1A0A';
11
    const JPG = 'FFD8FFE0';
12
    const PDF = '25504446';
13
    const GIF = '47494638';
14
    const BMP = '424D';
15
    const XML = '3C3F786D6C';
16
17
    /**
18
     * Determine whether the given string contains one of the registered signatures
19
     *
20
     * @param string $string    the string data to check
21
     * @param string $signature the hex signature
22
     *
23
     * @throws \InvalidArgumentException
24
     *
25
     * @return bool
26
     */
27 3
    public static function hasSignature($string, $signature)
28
    {
29 3
        if (ctype_xdigit($signature) === false) {
30 1
            throw new \InvalidArgumentException(sprintf('Invalid HEX signature provided: %s', $signature));
31
        }
32 2
        $signatureChars = str_split($signature, 2);
33 2
        $hexChars = array_map(
34 2
            function ($val) {
35 2
                return strtoupper(bin2hex($val));
36 2
            },
37 2
            str_split(substr($string, 0, count($signatureChars)))
38 2
        );
39
40 2
        return $hexChars === $signatureChars;
41
    }
42
}
43