Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(formatter): add ABN formatter function #8

Merged
merged 1 commit into from
Sep 26, 2023
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
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);
}
}
Loading