Skip to content

Commit d17f9a8

Browse files
authored
Merge pull request #26 from jozefrebjak/develop
fix: 🐛 is_int -> is_numeric in Visit Entity
2 parents 1788601 + 080041f commit d17f9a8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Entities/Visit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function setIpAddress($ipAddress): void
5252
*/
5353
public function getIpAddress(): ?string
5454
{
55-
if (is_int($this->attributes['ip_address'])) {
55+
if (is_numeric($this->attributes['ip_address'])) {
5656
return long2ip($this->attributes['ip_address']);
5757
}
5858

tests/EntityTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,20 @@ public function ipAddressProvider(): array
3737
[null, null, null],
3838
];
3939
}
40+
41+
public function testIpAddressHandlesStrings(): void
42+
{
43+
$visit = new Visit();
44+
$visit->setAttributes([
45+
'ip_address' => '2130706433',
46+
]);
47+
48+
$result = $visit->getIpAddress();
49+
$this->assertSame('127.0.0.1', $result);
50+
51+
$visit->setAttributes([
52+
'ip_address' => 'foo',
53+
]);
54+
$this->assertNull($visit->getIpAddress());
55+
}
4056
}

0 commit comments

Comments
 (0)