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.
Completed
Branch php72 (a7f01e)
by Joni
04:53
created

IPv6Address::_octets()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\GeneralName;
6
7
class IPv6Address extends IPAddress
8
{
9
    /**
10
     * Initialize from octets.
11
     *
12
     * @param string $octets
13
     *
14
     * @throws \InvalidArgumentException
15
     *
16
     * @return self
17
     */
18 11
    public static function fromOctets(string $octets): self
19
    {
20 11
        $mask = null;
21 11
        $words = unpack('n*', $octets);
22 11
        switch (count($words)) {
0 ignored issues
show
Bug introduced by
It seems like $words can also be of type false; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
        switch (count(/** @scrutinizer ignore-type */ $words)) {
Loading history...
23 11
            case 8:
24 9
                $ip = self::_wordsToIPv6String($words);
0 ignored issues
show
Bug introduced by
It seems like $words can also be of type false; however, parameter $words of Sop\X509\GeneralName\IPv...s::_wordsToIPv6String() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

24
                $ip = self::_wordsToIPv6String(/** @scrutinizer ignore-type */ $words);
Loading history...
25 9
                break;
26 2
            case 16:
27 1
                $ip = self::_wordsToIPv6String(array_slice($words, 0, 8));
0 ignored issues
show
Bug introduced by
It seems like $words can also be of type false; however, parameter $array of array_slice() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
                $ip = self::_wordsToIPv6String(array_slice(/** @scrutinizer ignore-type */ $words, 0, 8));
Loading history...
28 1
                $mask = self::_wordsToIPv6String(array_slice($words, 8, 8));
29 1
                break;
30
            default:
31 1
                throw new \UnexpectedValueException('Invalid IPv6 octet length.');
32
        }
33 10
        return new self($ip, $mask);
34
    }
35
36
    /**
37
     * Convert an array of 16 bit words to an IPv6 string representation.
38
     *
39
     * @param int[] $words
40
     *
41
     * @return string
42
     */
43 10
    protected static function _wordsToIPv6String(array $words): string
44
    {
45 10
        $groups = array_map(
46
            function ($word) {
47 10
                return sprintf('%04x', $word);
48 10
            }, $words);
49 10
        return implode(':', $groups);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 16
    protected function _octets(): string
56
    {
57 16
        $words = array_map('hexdec', explode(':', $this->_ip));
58 16
        if (isset($this->_mask)) {
59 1
            $words = array_merge($words,
60 1
                array_map('hexdec', explode(':', $this->_mask)));
61
        }
62 16
        return pack('n*', ...$words);
63
    }
64
}
65