Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor improvements + fix travis builds
- Loading branch information
Showing
16 changed files
with
129 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace BenTools\HostnameExtractor\SuffixProvider; | ||
|
||
use function BenTools\Violin\string; | ||
|
||
final class ArraySuffixProvider implements SuffixProviderInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $suffixes; | ||
|
||
/** | ||
* ArraySuffixProvider constructor. | ||
*/ | ||
public function __construct(array $suffixes) | ||
{ | ||
\usort( | ||
$suffixes, | ||
function ($a, $b) { | ||
return \count(string($b)) <=> \count(string($a)); | ||
} | ||
); | ||
$this->suffixes = $suffixes; | ||
} | ||
|
||
public function getSuffixes(): iterable | ||
{ | ||
return $this->suffixes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace BenTools\HostnameExtractor\SuffixProvider; | ||
|
||
/** | ||
* As this class will provide no suffix, substring after last dot may be used to determine hostname's suffix. | ||
*/ | ||
final class NaiveSuffixProvider implements SuffixProviderInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getSuffixes(): iterable | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace BenTools\HostnameExtractor\Tests; | ||
|
||
use BenTools\HostnameExtractor\SuffixProvider\ArraySuffixProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ArraySuffixProviderTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_provides_suffixes_in_the_correct_order() | ||
{ | ||
$suffixes = [ | ||
'.com', | ||
'.co.uk', | ||
'.au', | ||
]; | ||
|
||
$provider = new ArraySuffixProvider($suffixes); | ||
$expected = [ | ||
'.co.uk', | ||
'.com', | ||
'.au', | ||
]; | ||
|
||
$this->assertSame($expected, $provider->getSuffixes()); | ||
} | ||
} |