Skip to content

Commit

Permalink
feat(formatter): add ABN formatter function (#8)
Browse files Browse the repository at this point in the history
Function takes an ABN string and returns it with spaces.

e.g. `AbnFormatter::format('30616935623') -> '30 616 935 623'`
  • Loading branch information
pm0 authored Sep 26, 2023
1 parent 9a769c6 commit f0ee793
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/AbnFormatter.php
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)
);
}
}
21 changes: 21 additions & 0 deletions tests/Unit/AbnFormatterTest.php
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);
}
}

0 comments on commit f0ee793

Please sign in to comment.