-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(formatter): add ABN formatter function (#8)
Function takes an ABN string and returns it with spaces. e.g. `AbnFormatter::format('30616935623') -> '30 616 935 623'`
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hyra\AbnLookup; | ||
|
||
final class AbnFormatter | ||
{ | ||
public static function format(string $abn): string | ||
{ | ||
return \sprintf( | ||
'%s %s %s %s', | ||
\mb_substr($abn, 0, 2), | ||
\mb_substr($abn, 2, 3), | ||
\mb_substr($abn, 5, 3), | ||
\mb_substr($abn, 8, 3) | ||
); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hyra\Tests\AbnLookup\Unit; | ||
|
||
use Hyra\AbnLookup\AbnFormatter; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AbnFormatterTest extends TestCase | ||
{ | ||
public function testFormatter(): void | ||
{ | ||
$abn = '30616935623'; | ||
$formattedAbn = '30 616 935 623'; | ||
|
||
$result = AbnFormatter::format($abn); | ||
|
||
static::assertSame($result, $formattedAbn); | ||
} | ||
} |