-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
675cab3
commit 24e7ca5
Showing
10 changed files
with
166 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
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 declare(strict_types=1); | ||
|
||
namespace PrinsFrank\Standards\Name; | ||
|
||
enum NameOrder: int | ||
{ | ||
case Eastern = 0; | ||
case Western = 1; | ||
|
||
/** | ||
* In case of Mononymous names, only supply $given | ||
* Patronymics and Matronymics should be given in $middle or $family depending on country/language. | ||
* | ||
* note: $middle is optional, if supplied/stored in two fields instead of three make sure to supply a $given and a | ||
* $family name, and store any additional names in the $given field | ||
*/ | ||
public function format(?string $given, ?string $middle, ?string $family): string | ||
{ | ||
return implode( | ||
' ', | ||
array_filter( | ||
match ($this) { | ||
self::Eastern => [$family, $middle, $given], | ||
self::Western => [$given, $middle, $family], | ||
}, | ||
fn (string|null $value) => $value !== null | ||
) | ||
); | ||
} | ||
} |
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,59 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PrinsFrank\Standards\Tests\Unit\Name; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use PrinsFrank\Standards\Name\NameOrder; | ||
|
||
#[CoversClass(NameOrder::class)] | ||
class NameOrderTest extends TestCase | ||
{ | ||
public function testFormatPermutations(): void | ||
{ | ||
// Different permutations - three names | ||
static::assertSame('Foo Bar Boop', NameOrder::Western->format('Foo', 'Bar', 'Boop')); | ||
static::assertSame('Boop Bar Foo', NameOrder::Eastern->format('Foo', 'Bar', 'Boop')); | ||
|
||
// Different permutations - Only first and last | ||
static::assertSame('Foo Boop', NameOrder::Western->format('Foo', null, 'Boop')); | ||
static::assertSame('Boop Foo', NameOrder::Eastern->format('Foo', null, 'Boop')); | ||
|
||
// Different permutations - Only first and middle | ||
static::assertSame('Foo Bar', NameOrder::Western->format('Foo', 'Bar', null)); | ||
static::assertSame('Bar Foo', NameOrder::Eastern->format('Foo', 'Bar', null)); | ||
|
||
// Different permutations - Only middle and last | ||
static::assertSame('Bar Boop', NameOrder::Western->format(null, 'Bar', 'Boop')); | ||
static::assertSame('Boop Bar', NameOrder::Eastern->format(null, 'Bar', 'Boop')); | ||
|
||
// Different permutations - Only first | ||
static::assertSame('Foo', NameOrder::Western->format('Foo', null, null)); | ||
static::assertSame('Foo', NameOrder::Eastern->format('Foo', null, null)); | ||
|
||
// Different permutations - Only middle | ||
static::assertSame('Bar', NameOrder::Western->format(null, 'Bar', null)); | ||
static::assertSame('Bar', NameOrder::Eastern->format(null, 'Bar', null)); | ||
|
||
// Different permutations - Only last | ||
static::assertSame('Boop', NameOrder::Western->format(null, null, 'Boop')); | ||
static::assertSame('Boop', NameOrder::Eastern->format(null, null, 'Boop')); | ||
|
||
// Different permutations - None | ||
static::assertSame('', NameOrder::Western->format(null, null, null)); | ||
static::assertSame('', NameOrder::Eastern->format(null, null, null)); | ||
} | ||
|
||
public function testActualNames(): void | ||
{ | ||
// Mononyms | ||
static::assertSame('Teller', NameOrder::Eastern->format('Teller', null, null)); | ||
static::assertSame('Teller', NameOrder::Western->format('Teller', null, null)); | ||
|
||
// Eastern | ||
static::assertSame('Abe Shinzo', NameOrder::Eastern->format('Shinzo', null, 'Abe')); | ||
|
||
// Western | ||
static::assertSame('Frank Prins', NameOrder::Western->format('Frank', null, 'Prins')); | ||
} | ||
} |