Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<disableExtensions>
<extension name="random" />
</disableExtensions>
<issueHandlers>
<UndefinedAttributeClass errorLevel="suppress" />
</issueHandlers>
</psalm>
4 changes: 4 additions & 0 deletions src/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final private function __construct(string $address)
/**
* @psalm-pure
*/
#[\NoDiscard]
final public static function v4(string $address): IPv4
{
if (!\filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) {
Expand All @@ -35,6 +36,7 @@ final public static function v4(string $address): IPv4
/**
* @psalm-pure
*/
#[\NoDiscard]
final public static function v6(string $address): IPv6
{
if (!\filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
Expand All @@ -45,6 +47,7 @@ final public static function v6(string $address): IPv6
return new IPv6($address);
}

#[\NoDiscard]
final public function equals(self $self): bool
{
return $this->address === $self->address;
Expand All @@ -53,6 +56,7 @@ final public function equals(self $self): bool
/**
* @return non-empty-string
*/
#[\NoDiscard]
final public function toString(): string
{
return $this->address;
Expand Down
4 changes: 4 additions & 0 deletions src/IPv4.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class IPv4 extends IP
/**
* @psalm-pure
*/
#[\NoDiscard]
public static function of(string $address): self
{
return IP::v4($address);
Expand All @@ -24,6 +25,7 @@ public static function of(string $address): self
/**
* @psalm-pure
*/
#[\NoDiscard]
public static function localhost(): self
{
return self::of('127.0.0.1');
Expand All @@ -34,6 +36,7 @@ public static function localhost(): self
*
* @return Maybe<self>
*/
#[\NoDiscard]
public static function maybe(string $address): Maybe
{
return self::attempt($address)->maybe();
Expand All @@ -44,6 +47,7 @@ public static function maybe(string $address): Maybe
*
* @return Attempt<self>
*/
#[\NoDiscard]
public static function attempt(string $address): Attempt
{
return Attempt::of(static fn() => self::of($address));
Expand Down
4 changes: 4 additions & 0 deletions src/IPv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class IPv6 extends IP
/**
* @psalm-pure
*/
#[\NoDiscard]
public static function of(string $address): self
{
return IP::v6($address);
Expand All @@ -24,6 +25,7 @@ public static function of(string $address): self
/**
* @psalm-pure
*/
#[\NoDiscard]
public static function localhost(): self
{
return self::of('::1');
Expand All @@ -34,6 +36,7 @@ public static function localhost(): self
*
* @return Maybe<self>
*/
#[\NoDiscard]
public static function maybe(string $address): Maybe
{
return self::attempt($address)->maybe();
Expand All @@ -44,6 +47,7 @@ public static function maybe(string $address): Maybe
*
* @return Attempt<self>
*/
#[\NoDiscard]
public static function attempt(string $address): Attempt
{
return Attempt::of(static fn() => self::of($address));
Expand Down
4 changes: 2 additions & 2 deletions tests/IPv4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public function testThrowWhenInvalidFormat()
$this->expectException(\DomainException::class);
$this->expectExceptionMessage('localhost');

IPv4::of('localhost');
$_ = IPv4::of('localhost');
}

public function testThrowWhenOutOfBound()
{
$this->expectException(\DomainException::class);
$this->expectExceptionMessage('256.0.0.1');

IPv4::of('256.0.0.1');
$_ = IPv4::of('256.0.0.1');
}

public function testMaybeReturnNothingForInvalidAddress()
Expand Down
4 changes: 2 additions & 2 deletions tests/IPv6Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public function testThrowWhenInvalidFormat()
$this->expectException(\DomainException::class);
$this->expectExceptionMessage('localhost');

IPv6::of('localhost');
$_ = IPv6::of('localhost');
}

public function testThrowWhenOutOfBound()
{
$this->expectException(\DomainException::class);
$this->expectExceptionMessage('::z');

IPv6::of('::z');
$_ = IPv6::of('::z');
}

public function testMaybeReturnNothingForInvalidAddress()
Expand Down