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   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 35
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A hasSignature() 0 15 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