Skip to content

Commit

Permalink
Add functions to check if FQDN is absolute or relative
Browse files Browse the repository at this point in the history
  • Loading branch information
ben221199 committed Feb 22, 2025
1 parent 8560dea commit 880b8e1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Fields/FQDN.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ public function getValue(): array{
return $this->value;
}

/**
* @return bool
*/
public function isAbsolute(): bool{
return $this->value[count($this->value)-1]==='';
}

/**
* @return bool
*/
public function isRelative(): bool{
return !$this->isAbsolute();
}

/**
* @return string
*/
Expand Down
22 changes: 22 additions & 0 deletions tests/Fields/FQDNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ public function testGetValue(): void{
self::assertSame(['www','example','com',''],(new FQDN('www','example','com',''))->getValue());
}

/**
* @return void
* @throws DNSFieldException
*/
public function testIsAbsolute(){
self::assertFalse((new FQDN('example','com'))->isAbsolute());
self::assertTrue((new FQDN('example','com',''))->isAbsolute());
self::assertFalse((new FQDN('www','example','com'))->isAbsolute());
self::assertTrue((new FQDN('www','example','com',''))->isAbsolute());
}

/**
* @return void
* @throws DNSFieldException
*/
public function testIsRelative(){
self::assertTrue((new FQDN('example','com'))->isRelative());
self::assertFalse((new FQDN('example','com',''))->isRelative());
self::assertTrue((new FQDN('www','example','com'))->isRelative());
self::assertFalse((new FQDN('www','example','com',''))->isRelative());
}

/**
* @return void
* @throws DNSFieldException
Expand Down

0 comments on commit 880b8e1

Please sign in to comment.