Skip to content

Commit

Permalink
PHP 7 (#317)
Browse files Browse the repository at this point in the history
* require PHP 7

* declare(strict_types=1);

* type hints

* minor cs fixes

* minor improvements
  • Loading branch information
othillo committed Oct 24, 2017
1 parent df69c8d commit 5c3cc30
Show file tree
Hide file tree
Showing 130 changed files with 505 additions and 227 deletions.
1 change: 1 addition & 0 deletions .php_cs
Expand Up @@ -6,5 +6,6 @@ $finder = PhpCsFixer\Finder::create()
return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'declare_strict_types' => true,
])
->setFinder($finder);
5 changes: 2 additions & 3 deletions .travis.yml
Expand Up @@ -9,9 +9,8 @@ cache:

matrix:
include:
- php: 5.5
- php: 5.6
- php: 7
- php: 7.0
- php: 7.1
- php: hhvm
fast_finish: true
allow_failures:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -6,7 +6,7 @@
"require": {
"beberlei/assert": "~2.0",
"broadway/uuid-generator": "~0.4.0",
"php": ">=5.5.9"
"php": "^7.0"
},
"authors": [
{
Expand Down
6 changes: 4 additions & 2 deletions examples/auditing/log-command-status.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/../bootstrap.php';

/*
Expand Down Expand Up @@ -58,8 +60,8 @@ class ExampleFailureCommand extends BaseCommand
$commandAuditLogger = new Broadway\Auditing\CommandLogger($logger, $commandSerializer);

// register the command logger with the event dispatcher of the command bus
$eventDispatcher->addListener("broadway.command_handling.command_success", [$commandAuditLogger, "onCommandHandlingSuccess"]);
$eventDispatcher->addListener("broadway.command_handling.command_failure", [$commandAuditLogger, "onCommandHandlingFailure"]);
$eventDispatcher->addListener('broadway.command_handling.command_success', [$commandAuditLogger, 'onCommandHandlingSuccess']);
$eventDispatcher->addListener('broadway.command_handling.command_failure', [$commandAuditLogger, 'onCommandHandlingFailure']);

echo "Dispatching the command that will succeed.\n";
$command = new ExampleCommand('Hi from command!');
Expand Down
2 changes: 2 additions & 0 deletions examples/bootstrap.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

if (file_exists($file = __DIR__ . '/../vendor/autoload.php')) {
$loader = require_once $file;
} else {
Expand Down
2 changes: 2 additions & 0 deletions examples/command-handling/command-handling.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/../bootstrap.php';

/**
Expand Down
2 changes: 2 additions & 0 deletions examples/event-dispatcher/event-dispatcher.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/../bootstrap.php';

$eventDispatcher = new Broadway\EventDispatcher\CallableEventDispatcher();
Expand Down
2 changes: 2 additions & 0 deletions examples/event-handling/event-handling.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/../bootstrap.php';

// An event listener implements the handle method
Expand Down
2 changes: 2 additions & 0 deletions examples/event-sourced-child-entity/Parts.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/../bootstrap.php';

/**
Expand Down
2 changes: 2 additions & 0 deletions examples/event-sourced-child-entity/PartsTest.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/Parts.php';

/**
Expand Down
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/Invites.php';

/**
Expand Down
2 changes: 2 additions & 0 deletions examples/event-sourced-domain-with-tests/Invites.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/../bootstrap.php';

/**
Expand Down
2 changes: 2 additions & 0 deletions examples/event-sourced-domain-with-tests/InvitesTest.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/Invites.php';

/**.
Expand Down
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/../bootstrap.php';

/**
Expand Down
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/JobSeekers.php';

/**
Expand Down
2 changes: 2 additions & 0 deletions examples/serializer/serializer.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/../bootstrap.php';

class SerializeMe implements Broadway\Serializer\Serializable
Expand Down
4 changes: 3 additions & 1 deletion src/Broadway/Auditing/CommandLogger.php
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\Auditing;

use Exception;
Expand Down Expand Up @@ -64,7 +66,7 @@ public function onCommandHandlingFailure($command, Exception $exception)
$this->logger->info(json_encode($messageData));
}

private function getCommandData($command)
private function getCommandData($command): array
{
return [
'class' => get_class($command),
Expand Down
4 changes: 3 additions & 1 deletion src/Broadway/Auditing/CommandSerializer.php
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\Auditing;

/**
Expand All @@ -21,5 +23,5 @@ interface CommandSerializer
*
* @return array
*/
public function serialize($command);
public function serialize($command): array;
}
4 changes: 3 additions & 1 deletion src/Broadway/Auditing/NullByteCommandSerializer.php
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\Auditing;

/**
Expand All @@ -22,7 +24,7 @@ final class NullByteCommandSerializer implements CommandSerializer
/**
* {@inheritDoc}
*/
public function serialize($command)
public function serialize($command): array
{
$serializedCommand = [];
foreach ((array) $command as $key => $value) {
Expand Down
2 changes: 2 additions & 0 deletions src/Broadway/CommandHandling/ClosureCommandHandler.php
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the broadway/broadway package.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Broadway/CommandHandling/CommandBus.php
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\CommandHandling;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Broadway/CommandHandling/CommandHandler.php
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\CommandHandling;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Broadway/CommandHandling/EventDispatchingCommandBus.php
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\CommandHandling;

use Broadway\EventDispatcher\EventDispatcher;
Expand Down
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the broadway/broadway package.
*
Expand Down
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\CommandHandling\Exception;

use InvalidArgumentException;
Expand Down
2 changes: 2 additions & 0 deletions src/Broadway/CommandHandling/SimpleCommandBus.php
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\CommandHandling;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Broadway/CommandHandling/SimpleCommandHandler.php
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\CommandHandling;

use Broadway\CommandHandling\Exception\CommandNotAnObjectException;
Expand Down Expand Up @@ -37,7 +39,7 @@ public function handle($command)
$this->$method($command);
}

private function getHandleMethod($command)
private function getHandleMethod($command): string
{
if (! is_object($command)) {
throw new CommandNotAnObjectException();
Expand Down
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\CommandHandling\Testing;

use Broadway\CommandHandling\CommandHandler;
Expand Down Expand Up @@ -37,7 +39,7 @@ public function setUp()
/**
* @return Scenario
*/
protected function createScenario()
protected function createScenario(): Scenario
{
$eventStore = new TraceableEventStore(new InMemoryEventStore());
$eventBus = new SimpleEventBus();
Expand All @@ -54,5 +56,5 @@ protected function createScenario()
*
* @return CommandHandler
*/
abstract protected function createCommandHandler(EventStore $eventStore, EventBus $eventBus);
abstract protected function createCommandHandler(EventStore $eventStore, EventBus $eventBus): CommandHandler;
}
15 changes: 9 additions & 6 deletions src/Broadway/CommandHandling/Testing/Scenario.php
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\CommandHandling\Testing;

use Broadway\CommandHandling\CommandHandler;
Expand Down Expand Up @@ -43,14 +45,15 @@ public function __construct(
$this->testCase = $testCase;
$this->eventStore = $eventStore;
$this->commandHandler = $commandHandler;
$this->aggregateId = 1;
$this->aggregateId = '1';
}

/**
* @param string $aggregateId
* @param string $aggregateId
*
* @return Scenario
*/
public function withAggregateId($aggregateId)
public function withAggregateId(string $aggregateId): Scenario
{
$this->aggregateId = $aggregateId;

Expand All @@ -62,7 +65,7 @@ public function withAggregateId($aggregateId)
*
* @return Scenario
*/
public function given(array $events = null)
public function given(array $events = null): Scenario
{
if ($events === null) {
return $this;
Expand All @@ -85,7 +88,7 @@ public function given(array $events = null)
*
* @return Scenario
*/
public function when($command)
public function when($command): Scenario
{
$this->eventStore->trace();

Expand All @@ -99,7 +102,7 @@ public function when($command)
*
* @return Scenario
*/
public function then(array $events)
public function then(array $events): Scenario
{
$this->testCase->assertEquals($events, $this->eventStore->getEvents());

Expand Down
4 changes: 3 additions & 1 deletion src/Broadway/CommandHandling/Testing/TraceableCommandBus.php
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\CommandHandling\Testing;

use Broadway\CommandHandling\CommandBus;
Expand Down Expand Up @@ -46,7 +48,7 @@ public function dispatch($command)
/**
* @return array
*/
public function getRecordedCommands()
public function getRecordedCommands(): array
{
return $this->commands;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Broadway/Domain/AggregateRoot.php
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Broadway\Domain;

/**
Expand All @@ -19,10 +21,10 @@ interface AggregateRoot
/**
* @return DomainEventStream
*/
public function getUncommittedEvents();
public function getUncommittedEvents(): DomainEventStream;

/**
* @return string
*/
public function getAggregateRootId();
public function getAggregateRootId(): string;
}

0 comments on commit 5c3cc30

Please sign in to comment.