HexadecimalIPv4AddressConverter::convert()   A
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
nc 1
nop 0
dl 0
loc 13
rs 9.9
c 2
b 0
f 0
1
<?php
2
3
namespace Acamposm\IPv4AddressConverter\Converters;
4
5
use Acamposm\IPv4AddressConverter\Enums\IPAddressFormatEnum as IPAddressFormat;
6
use Acamposm\IPv4AddressConverter\Traits\MutableIPv4AddressTrait as MutableIPv4Address;
7
8
class HexadecimalIPv4AddressConverter extends BaseAddressConverter
9
{
10
    use MutableIPv4Address;
11
12
    /**
13
     * Performs the conversion from the input format to Hexadecimal string.
14
     *
15
     * @return int|string
16
     */
17
    public function convert(): int | string
18
    {
19
        return match ($this->inputFormat) {
20
            IPAddressFormat::BINARY => $this->withDotNotation
21
                ? $this->fromBinaryToDottedHex($this->address)
22
                : $this->fromBinaryToHex($this->address),
23
            IPAddressFormat::DECIMAL => $this->withDotNotation
24
                ? $this->fromDecimalToDottedHex($this->address)
25
                : $this->fromDecimalToHex($this->address),
26
            IPAddressFormat::LONG => $this->withDotNotation ?
27
                $this->fromLongToDottedHex($this->address) :
0 ignored issues
show
Bug introduced by
It seems like $this->address can also be of type string; however, parameter $address of Acamposm\IPv4AddressConv...::fromLongToDottedHex() does only seem to accept integer, 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
                $this->fromLongToDottedHex(/** @scrutinizer ignore-type */ $this->address) :
Loading history...
28
                $this->fromLongToHex($this->address),
0 ignored issues
show
Bug introduced by
It seems like $this->address can also be of type string; however, parameter $address of Acamposm\IPv4AddressConv...verter::fromLongToHex() does only seem to accept integer, 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

28
                $this->fromLongToHex(/** @scrutinizer ignore-type */ $this->address),
Loading history...
29
            default => '',
30
        };
31
    }
32
}
33