angelcamposm /
ipv4-address-converter
| 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 BinaryIPv4AddressConverter 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::DECIMAL => $this->withDotNotation |
||
| 21 | ? $this->fromDecimalToDottedBinary($this->address) |
||
| 22 | : $this->fromDecimalToBinary($this->address), |
||
| 23 | IPAddressFormat::HEXADECIMAL => $this->withDotNotation |
||
| 24 | ? $this->fromHexadecimalToDottedBinary($this->address) |
||
| 25 | : $this->fromHexadecimalToBinary($this->address), |
||
| 26 | IPAddressFormat::LONG => $this->withDotNotation |
||
| 27 | ? $this->fromLongToDottedBinary($this->address) |
||
| 28 | : $this->fromLongToBinary($this->address), |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 29 | default => $this->address, |
||
| 30 | }; |
||
| 31 | } |
||
| 32 | } |
||
| 33 |