Skip to content
Open
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
8 changes: 4 additions & 4 deletions src/ShortUuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class ShortUuid
/**
* @var array
*/
private $alphabet = [
private array $alphabet = [
'2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n',
Expand All @@ -26,7 +26,7 @@ final class ShortUuid
/**
* @var int
*/
private $alphabetLength = 57;
private int $alphabetLength = 57;

/**
* @param array|null $alphabet
Expand All @@ -43,7 +43,7 @@ public function __construct(array $alphabet = null)
*
* @param int|string $node A 48-bit number representing the hardware address
* This number may be represented as an integer or a hexadecimal string.
* @param int $clockSeq A 14-bit number used to help avoid duplicates that
* @param int|null $clockSeq A 14-bit number used to help avoid duplicates that
* could arise when the clock is set backwards in time or if the node ID
* changes.
*
Expand Down Expand Up @@ -160,7 +160,7 @@ private function stringToNum(string $string) : BigInteger
/**
* @param array $alphabet
*/
private function setAlphabet(array $alphabet)
private function setAlphabet(array $alphabet): void
{
$this->alphabet = $alphabet;
$this->alphabetLength = count($alphabet);
Expand Down
17 changes: 9 additions & 8 deletions tests/ShortUuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PascalDeVink\ShortUuid\ShortUuid;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

/**
* @covers \PascalDeVink\ShortUuid\ShortUuid
Expand All @@ -15,7 +16,7 @@ class ShortUuidTest extends TestCase
/**
* @var ShortUuid
*/
private $shortUuid;
private ShortUuid $shortUuid;

public function setUp() : void
{
Expand All @@ -26,13 +27,13 @@ public function setUp() : void
* @test
* @dataProvider uuid_provider
*/
public function it_should_encode_a_given_uuid($uuid, $expectedShortUuid)
public function it_should_encode_a_given_uuid($uuid, $expectedShortUuid): void
{
$shortUuid = $this->shortUuid->encode($uuid);
$this->assertSame($expectedShortUuid, $shortUuid);
}

public function uuid_provider()
public function uuid_provider(): array
{
return [
[Uuid::fromString('4e52c919-513e-4562-9248-7dd612c6c1ca'), 'fpfyRTmt6XeE9ehEKZ5LwF'],
Expand All @@ -44,13 +45,13 @@ public function uuid_provider()
* @test
* @dataProvider shortuuid_provider
*/
public function it_should_decode_a_given_short_uuid($shortUuid, $expectedUuid)
public function it_should_decode_a_given_short_uuid($shortUuid, $expectedUuid): void
{
$uuid = $this->shortUuid->decode($shortUuid);
$this->assertTrue($expectedUuid->equals($uuid));
}

public function shortuuid_provider()
public function shortuuid_provider(): array
{
return [
['fpfyRTmt6XeE9ehEKZ5LwF', Uuid::fromString('4e52c919-513e-4562-9248-7dd612c6c1ca')],
Expand All @@ -61,7 +62,7 @@ public function shortuuid_provider()
/**
* @test
*/
public function it_should_generate_a_short_uuid1()
public function it_should_generate_a_short_uuid1(): void
{
$shortUuid = ShortUuid::uuid1();
$this->assertLessThanOrEqual(22, strlen($shortUuid));
Expand All @@ -71,7 +72,7 @@ public function it_should_generate_a_short_uuid1()
/**
* @test
*/
public function it_should_generate_a_short_uuid4()
public function it_should_generate_a_short_uuid4(): void
{
$shortUuid = ShortUuid::uuid4();
$this->assertLessThanOrEqual(22, strlen($shortUuid));
Expand All @@ -81,7 +82,7 @@ public function it_should_generate_a_short_uuid4()
/**
* @test
*/
public function it_should_generate_a_short_uuid5()
public function it_should_generate_a_short_uuid5(): void
{
$shortUuid = ShortUuid::uuid5(Uuid::NAMESPACE_DNS, 'ticketswap.com');
$this->assertLessThanOrEqual(22, strlen($shortUuid));
Expand Down