1 | <?php |
||
2 | |||
3 | namespace Acamposm\IPv4AddressConverter\Converters; |
||
4 | |||
5 | use Acamposm\IPv4AddressConverter\Enums\IPAddressFormatEnum as IPAddressFormat; |
||
6 | use Acamposm\IPv4AddressConverter\Interfaces\IPv4AddressConverterInterface; |
||
7 | |||
8 | abstract class BaseAddressConverter implements IPv4AddressConverterInterface |
||
9 | { |
||
10 | protected int | string $address; |
||
11 | protected int $inputFormat; |
||
12 | |||
13 | /** |
||
14 | * BaseAddressConverter constructor. |
||
15 | * |
||
16 | * @param false $withDotNotation |
||
17 | */ |
||
18 | public function __construct( |
||
19 | protected $withDotNotation = false, |
||
20 | ) { |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * Set the value of $address from Binary string. |
||
25 | * |
||
26 | * @param string $address |
||
27 | * |
||
28 | * @return BaseAddressConverter |
||
29 | */ |
||
30 | public function fromBinary(string $address): BaseAddressConverter |
||
31 | { |
||
32 | $this->address = $address; |
||
33 | $this->inputFormat = IPAddressFormat::BINARY; |
||
34 | |||
35 | return $this; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Set the value of $address from Decimal string. |
||
40 | * |
||
41 | * @param string $address |
||
42 | * |
||
43 | * @return BaseAddressConverter |
||
44 | */ |
||
45 | public function fromDecimal(string $address): BaseAddressConverter |
||
46 | { |
||
47 | $this->address = $address; |
||
48 | $this->inputFormat = IPAddressFormat::DECIMAL; |
||
49 | |||
50 | return $this; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Set the value of $address from Hexadecimal string. |
||
55 | * |
||
56 | * @param string $address |
||
57 | * |
||
58 | * @return BaseAddressConverter |
||
59 | */ |
||
60 | public function fromHexadecimal(string $address): BaseAddressConverter |
||
61 | { |
||
62 | $this->address = $address; |
||
63 | $this->inputFormat = IPAddressFormat::HEXADECIMAL; |
||
64 | |||
65 | return $this; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Set the value of $address from Long Integer. |
||
70 | * |
||
71 | * @param int $address |
||
72 | * |
||
73 | * @return BaseAddressConverter |
||
74 | */ |
||
75 | public function fromLong(int $address): BaseAddressConverter |
||
76 | { |
||
77 | $this->address = $address; |
||
78 | $this->inputFormat = IPAddressFormat::LONG; |
||
79 | |||
80 | return $this; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Set the output format as dot notation. |
||
85 | * |
||
86 | * @return BaseAddressConverter |
||
87 | */ |
||
88 | public function withDotNotation(): BaseAddressConverter |
||
89 | { |
||
90 | $this->withDotNotation = true; |
||
0 ignored issues
–
show
|
|||
91 | |||
92 | return $this; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @inheritDoc |
||
97 | */ |
||
98 | public function convert(): int | string |
||
99 | { |
||
100 | } |
||
0 ignored issues
–
show
In this branch, the function will implicitly return
null which is incompatible with the type-hinted return integer|string . Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: interface ReturnsInt {
public function returnsIntHinted(): int;
}
class MyClass implements ReturnsInt {
public function returnsIntHinted(): int
{
if (foo()) {
return 123;
}
// here: null is implicitly returned
}
}
![]() |
|||
101 | } |
||
102 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.