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

IPv4Address::fromOctets()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 16
ccs 13
cts 13
cp 1
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\GeneralName;
6
7
class IPv4Address 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
        $bytes = unpack('C*', $octets);
22 11
        switch (count($bytes)) {
0 ignored issues
show
Bug introduced by
It seems like $bytes 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 */ $bytes)) {
Loading history...
23 11
            case 4:
24 9
                $ip = implode('.', $bytes);
0 ignored issues
show
Bug introduced by
It seems like $bytes can also be of type false; however, parameter $pieces of implode() 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 = implode('.', /** @scrutinizer ignore-type */ $bytes);
Loading history...
25 9
                break;
26 2
            case 8:
27 1
                $ip = implode('.', array_slice($bytes, 0, 4));
0 ignored issues
show
Bug introduced by
It seems like $bytes 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 = implode('.', array_slice(/** @scrutinizer ignore-type */ $bytes, 0, 4));
Loading history...
28 1
                $mask = implode('.', array_slice($bytes, 4, 4));
29 1
                break;
30
            default:
31 1
                throw new \UnexpectedValueException('Invalid IPv4 octet length.');
32
        }
33 10
        return new self($ip, $mask);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 16
    protected function _octets(): string
40
    {
41 16
        $bytes = array_map('intval', explode('.', $this->_ip));
42 16
        if (isset($this->_mask)) {
43 1
            $bytes = array_merge($bytes,
44 1
                array_map('intval', explode('.', $this->_mask)));
45
        }
46 16
        return pack('C*', ...$bytes);
47
    }
48
}
49