Skip to content

Commit

Permalink
strict types
Browse files Browse the repository at this point in the history
  • Loading branch information
othillo committed Mar 5, 2020
1 parent f14dbee commit 1f49f8c
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 48 deletions.
2 changes: 1 addition & 1 deletion examples/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

require_once __DIR__.'/bootstrap.php';

function generateAndOutput5(Broadway\UuidGenerator\UuidGeneratorInterface $generator)
function generateAndOutput5(Broadway\UuidGenerator\UuidGeneratorInterface $generator): void
{
for ($i = 0; $i < 5; ++$i) {
echo sprintf("[%d] %s\n", $i, $generator->generate());
Expand Down
4 changes: 2 additions & 2 deletions src/Broadway/UuidGenerator/Converter/BinaryUuidConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ class BinaryUuidConverter implements BinaryUuidConverterInterface
/**
* {@inheritdoc}
*/
public static function fromString($uuid)
public static function fromString(string $uuid): string
{
return Uuid::fromString($uuid)->getBytes();
}

/**
* {@inheritdoc}
*/
public static function fromBytes($bytes)
public static function fromBytes(string $bytes): string
{
return Uuid::fromBytes($bytes)->toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@

interface BinaryUuidConverterInterface
{
/**
* @param string $uuid
*
* @return string
*/
public static function fromString($uuid);
public static function fromString(string $uuid): string;

/**
* @param string $bytes
*
* @return string
*/
public static function fromBytes($bytes);
public static function fromBytes(string $bytes): string;
}
5 changes: 1 addition & 4 deletions src/Broadway/UuidGenerator/Rfc4122/Version4Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
*/
class Version4Generator implements UuidGeneratorInterface
{
/**
* @return string
*/
public function generate()
public function generate(): string
{
return Uuid::uuid4()->toString();
}
Expand Down
10 changes: 2 additions & 8 deletions src/Broadway/UuidGenerator/Testing/MockUuidGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,12 @@ class MockUuidGenerator implements UuidGeneratorInterface
*/
private $uuid;

/**
* @param string $uuid
*/
public function __construct($uuid)
public function __construct(string $uuid)
{
$this->uuid = $uuid;
}

/**
* @return string
*/
public function generate()
public function generate(): string
{
return $this->uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ public function __construct(array $uuids)
$this->uuids = (array) $uuids;
}

/**
* @return string
*/
public function generate()
public function generate(): string
{
if (0 === count($this->uuids)) {
throw new RuntimeException('No more uuids in sequence');
Expand Down
5 changes: 1 addition & 4 deletions src/Broadway/UuidGenerator/UuidGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@
*/
interface UuidGeneratorInterface
{
/**
* @return string
*/
public function generate();
public function generate(): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BinaryUuidConverterTest extends TestCase
/**
* @test
*/
public function it_converts_string_uuid_to_binary_uuid()
public function it_converts_string_uuid_to_binary_uuid(): void
{
$binary = BinaryUuidConverter::fromString('260b70eb-a5b7-4fde-916a-4cc021745c13');

Expand All @@ -30,7 +30,7 @@ public function it_converts_string_uuid_to_binary_uuid()
/**
* @test
*/
public function it_throws_when_converting_invalid_string_uuid_to_binary_uuid()
public function it_throws_when_converting_invalid_string_uuid_to_binary_uuid(): void
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid UUID string: yolo');
Expand All @@ -40,7 +40,7 @@ public function it_throws_when_converting_invalid_string_uuid_to_binary_uuid()
/**
* @test
*/
public function it_converts_binary_uuid_to_string_uuid()
public function it_converts_binary_uuid_to_string_uuid(): void
{
$this->assertEquals(
'260b70eb-a5b7-4fde-916a-4cc021745c13',
Expand All @@ -51,7 +51,7 @@ public function it_converts_binary_uuid_to_string_uuid()
/**
* @test
*/
public function it_throws_when_converting_invalid_binary_uuid_to_string_uuid()
public function it_throws_when_converting_invalid_binary_uuid_to_string_uuid(): void
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('$bytes string should contain 16 characters.');
Expand Down
4 changes: 2 additions & 2 deletions test/Broadway/UuidGenerator/Rfc4122/Version4GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Version4GeneratorTest extends TestCase
/**
* @test
*/
public function it_should_generate_a_string()
public function it_should_generate_a_string(): void
{
$generator = new Version4Generator();
$uuid = $generator->generate();
Expand All @@ -32,7 +32,7 @@ public function it_should_generate_a_string()
/**
* @test
*/
public function it_should_generate_a_version_4_uuid()
public function it_should_generate_a_version_4_uuid(): void
{
$generator = new Version4Generator();
$uuid = $generator->generate();
Expand Down
6 changes: 3 additions & 3 deletions test/Broadway/UuidGenerator/Testing/MockUuidGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MockUuidGeneratorTest extends TestCase
/**
* @test
*/
public function it_generates_a_string()
public function it_generates_a_string(): void
{
$generator = $this->createMockUuidGenerator();
$uuid = $generator->generate();
Expand All @@ -31,7 +31,7 @@ public function it_generates_a_string()
/**
* @test
*/
public function it_generates_the_same_string()
public function it_generates_the_same_string(): void
{
$generator = $this->createMockUuidGenerator();

Expand All @@ -40,7 +40,7 @@ public function it_generates_the_same_string()
}
}

private function createMockUuidGenerator()
private function createMockUuidGenerator(): \Broadway\UuidGenerator\Testing\MockUuidGenerator
{
return new MockUuidGenerator('e2d0c739-53ac-434c-8d7a-03e29b400566');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

class MockUuidSequenceGeneratorTest extends TestCase
{
/**
* @var string[]
*/
private $uuids = [
'e2d0c739-0001-434c-8d7a-03e29b400566',
'e2d0c739-0002-434c-8d7a-03e29b400566',
Expand All @@ -27,7 +30,7 @@ class MockUuidSequenceGeneratorTest extends TestCase
/**
* @test
*/
public function it_generates_a_string()
public function it_generates_a_string(): void
{
$generator = $this->createMockUuidGenerator();
$uuid = $generator->generate();
Expand All @@ -38,7 +41,7 @@ public function it_generates_a_string()
/**
* @test
*/
public function it_generates_the_same_string()
public function it_generates_the_same_string(): void
{
$generator = $this->createMockUuidGenerator();

Expand All @@ -50,7 +53,7 @@ public function it_generates_the_same_string()
/**
* @test
*/
public function it_throws_an_exception_when_pool_is_empty()
public function it_throws_an_exception_when_pool_is_empty(): void
{
$this->expectException('RuntimeException');
$generator = $this->createMockUuidGenerator();
Expand All @@ -60,7 +63,7 @@ public function it_throws_an_exception_when_pool_is_empty()
}
}

private function createMockUuidGenerator()
private function createMockUuidGenerator(): \Broadway\UuidGenerator\Testing\MockUuidSequenceGenerator
{
return new MockUuidSequenceGenerator($this->uuids);
}
Expand Down

0 comments on commit 1f49f8c

Please sign in to comment.