LongIPv4AddressConverter::convert()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
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 LongIPv4AddressConverter extends BaseAddressConverter
9
{
10
    use MutableIPv4Address;
11
12
    /**
13
     * Performs the conversion from the input format to Binary string.
14
     *
15
     * @return int|string
16
     */
17
    public function convert(): int | string
18
    {
19
        return match ($this->inputFormat) {
20
            IPAddressFormat::BINARY      => $this->fromBinaryToLong($this->address),
21
            IPAddressFormat::DECIMAL     => $this->fromDecimalToLong($this->address),
22
            IPAddressFormat::HEXADECIMAL => $this->fromHexadecimalToLong($this->address),
23
            default                      => $this->address,
24
        };
25
    }
26
}
27