Skip to content

Commit

Permalink
Merge 47b6904 into c6d9a0a
Browse files Browse the repository at this point in the history
  • Loading branch information
awd-studio committed May 16, 2020
2 parents c6d9a0a + 47b6904 commit e866a11
Show file tree
Hide file tree
Showing 29 changed files with 257 additions and 374 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: php
php:
- 7.2
- 7.3
- 7.4

sudo: false

Expand All @@ -13,9 +14,7 @@ before_script:

script:
- mkdir -p build/logs
- php vendor/bin/psalm --config=psalm.xml.dist
- php vendor/bin/phpstan analyse --level=7 --configuration=phpstan.neon src
- php vendor/bin/phpunit -c phpunit.xml.dist
- composer test

matrix:
fast_finish: true
Expand Down
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"phpunit/phpunit": "^8.1",
"phpunit/php-code-coverage": "^7.0",
"dg/bypass-finals": "^1.1",
"phpstan/phpstan": "^0.11.8",
"phpstan/phpstan-phpunit": "^0.11.2",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"php-coveralls/php-coveralls": "^2.1",
"vimeo/psalm": "^3.4"
"vimeo/psalm": "^3.4",
"symplify/easy-coding-standard": "^7.3"
},
"autoload": {
"psr-4": {
Expand All @@ -35,11 +36,15 @@
"minimum-stability": "stable",
"scripts": {
"test": [
"@ecs",
"@psalm",
"@stan",
"@unit"
],
"stan": "phpstan analyse --level=7 --configuration=phpstan.neon src tests",
"unit": "phpunit -c phpunit.xml.dist"
"ecs": "vendor/bin/ecs check",
"psalm": "vendor/bin/psalm",
"stan": "vendor/bin/phpstan analyse",
"unit": "vendor/bin/phpunit"
},
"keywords": [
"cqrs",
Expand Down
10 changes: 10 additions & 0 deletions ecs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameters:
paths:
- 'src'

sets:
- 'clean-code'
- 'psr12'
- 'symfony'
- 'php70'
- 'php71'
6 changes: 4 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
parameters:
level: max
paths:
- src
143 changes: 5 additions & 138 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
@@ -1,148 +1,15 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorLevel="2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />

<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->

<DeprecatedMethod errorLevel="info" />
<DeprecatedProperty errorLevel="info" />
<DeprecatedClass errorLevel="info" />
<DeprecatedConstant errorLevel="info" />
<DeprecatedFunction errorLevel="info" />
<DeprecatedInterface errorLevel="info" />
<DeprecatedTrait errorLevel="info" />

<InternalMethod errorLevel="info" />
<InternalProperty errorLevel="info" />
<InternalClass errorLevel="info" />

<MissingClosureReturnType errorLevel="info" />
<MissingReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />
<InvalidDocblock errorLevel="info" />
<MisplacedRequiredParam errorLevel="info" />

<PropertyNotSetInConstructor errorLevel="info" />
<MissingConstructor errorLevel="info" />
<MissingClosureParamType errorLevel="info" />
<MissingParamType errorLevel="info" />

<RedundantCondition errorLevel="info" />

<DocblockTypeContradiction errorLevel="info" />
<RedundantConditionGivenDocblockType errorLevel="info" />

<UnresolvableInclude errorLevel="info" />

<RawObjectIteration errorLevel="info" />

<InvalidStringClass errorLevel="info" />

<!-- level 4 issues - points to possible deficiencies in logic, higher false-positives -->

<MoreSpecificReturnType errorLevel="info" />
<LessSpecificReturnStatement errorLevel="info" />
<TypeCoercion errorLevel="info" />

<PossiblyFalseArgument errorLevel="info" />
<PossiblyFalseIterator errorLevel="info" />
<PossiblyFalseOperand errorLevel="info" />
<PossiblyFalsePropertyAssignmentValue errorLevel="info" />
<PossiblyFalseReference errorLevel="info" />
<PossiblyInvalidArgument errorLevel="info" />
<PossiblyInvalidArrayAccess errorLevel="info" />
<PossiblyInvalidArrayAssignment errorLevel="info" />
<PossiblyInvalidArrayOffset errorLevel="info" />
<PossiblyInvalidCast errorLevel="info" />
<PossiblyInvalidFunctionCall errorLevel="info" />
<PossiblyInvalidIterator errorLevel="info" />
<PossiblyInvalidMethodCall errorLevel="info" />
<PossiblyInvalidOperand errorLevel="info" />
<PossiblyInvalidPropertyAssignment errorLevel="info" />
<PossiblyInvalidPropertyAssignmentValue errorLevel="info" />
<PossiblyInvalidPropertyFetch errorLevel="info" />
<PossiblyNullArgument errorLevel="info" />
<PossiblyNullArrayAccess errorLevel="info" />
<PossiblyNullArrayAssignment errorLevel="info" />
<PossiblyNullArrayOffset errorLevel="info" />
<PossiblyNullFunctionCall errorLevel="info" />
<PossiblyNullIterator errorLevel="info" />
<PossiblyNullOperand errorLevel="info" />
<PossiblyNullPropertyAssignment errorLevel="info" />
<PossiblyNullPropertyAssignmentValue errorLevel="info" />
<PossiblyNullPropertyFetch errorLevel="info" />
<PossiblyNullReference errorLevel="info" />
<PossiblyUndefinedGlobalVariable errorLevel="info" />
<PossiblyUndefinedVariable errorLevel="info" />
<PossiblyUndefinedArrayOffset errorLevel="info" />
<PossiblyUndefinedMethod errorLevel="info" />

<!-- level 5 issues - should be avoided at mosts costs... -->

<ForbiddenCode errorLevel="info" />
<ImplicitToStringCast errorLevel="info" />
<InvalidScalarArgument errorLevel="info" />
<InvalidToString errorLevel="info" />
<InvalidOperand errorLevel="info" />
<NoInterfaceProperties errorLevel="info" />
<TooManyArguments errorLevel="info" />
<TypeDoesNotContainType errorLevel="info" />
<TypeDoesNotContainNull errorLevel="info" />
<MissingDocblockType errorLevel="info" />
<ImplementedReturnTypeMismatch errorLevel="info" />
<ImplementedParamTypeMismatch errorLevel="info" />

<!-- level 6 issues - really bad things -->

<InvalidNullableReturnType errorLevel="info" />
<NullableReturnStatement errorLevel="info" />
<InvalidFalsableReturnType errorLevel="info" />
<FalsableReturnStatement errorLevel="info" />

<MoreSpecificImplementedParamType errorLevel="info" />
<LessSpecificImplementedReturnType errorLevel="info" />

<InvalidReturnStatement errorLevel="info" />
<InvalidReturnType errorLevel="info" />
<UndefinedThisPropertyAssignment errorLevel="info" />
<UndefinedInterfaceMethod errorLevel="info" />

<!-- level 7 issues - even worse -->

<UndefinedThisPropertyAssignment errorLevel="info" />
<UndefinedPropertyAssignment errorLevel="info" />
<UndefinedThisPropertyFetch errorLevel="info" />
<UndefinedPropertyFetch errorLevel="info" />

<InvalidReturnStatement errorLevel="info" />
<InvalidReturnType errorLevel="info" />
<InvalidArgument errorLevel="info" />
<InvalidPropertyAssignmentValue errorLevel="info" />
<InvalidArrayOffset errorLevel="info" />
<InvalidArrayAssignment errorLevel="info" />
<InvalidArrayAccess errorLevel="info" />
<InvalidClone errorLevel="info" />

<!-- level 8 issues - some fatal errors in PHP -->

<ReservedWord errorLevel="info" />
<MethodSignatureMismatch errorLevel="info" />
<OverriddenMethodAccess errorLevel="info" />
<InaccessibleProperty errorLevel="info" />

</issueHandlers>
</psalm>
7 changes: 1 addition & 6 deletions src/ServiceBuses/CommandBus/CommandBus.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<?php

declare(strict_types=1); // strict mode
declare(strict_types=1);

namespace AwdStudio\ServiceBuses\CommandBus;

use AwdStudio\ServiceBuses\Core\Bus\SingleHandlerBus;

final class CommandBus extends SingleHandlerBus implements CommandBusInterface
{

/**
* {@inheritDoc}
*/
public function handle($command): void
{
$this->run($command);
}

}
4 changes: 1 addition & 3 deletions src/ServiceBuses/CommandBus/CommandBusInterface.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php

declare(strict_types=1); // strict mode
declare(strict_types=1);

namespace AwdStudio\ServiceBuses\CommandBus;

interface CommandBusInterface
{

/**
* Handles a command.
*
Expand All @@ -16,5 +15,4 @@ interface CommandBusInterface
* @throws \AwdStudio\ServiceBuses\Exception\WrongMessage
*/
public function handle($command): void;

}
27 changes: 9 additions & 18 deletions src/ServiceBuses/Core/Bus/BusProcessor.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1); // strict mode
declare(strict_types=1);

namespace AwdStudio\ServiceBuses\Core\Bus;

Expand All @@ -10,11 +10,14 @@

abstract class BusProcessor
{

/** @var \AwdStudio\ServiceBuses\Core\Handing\HandlerLocator */
/**
* @var \AwdStudio\ServiceBuses\Core\Handing\HandlerLocator
*/
protected $handlers;

/** @var \AwdStudio\ServiceBuses\Core\Middleware\MiddlewareChain */
/**
* @var \AwdStudio\ServiceBuses\Core\Middleware\MiddlewareChain
*/
protected $middleware;

public function __construct(HandlerLocator $handlers, MiddlewareChain $middleware)
Expand All @@ -28,12 +31,7 @@ public function __construct(HandlerLocator $handlers, MiddlewareChain $middlewar
*
* @param object $message
*
* @return iterable
*
* @psalm-return iterable<int, callable>
*
* @throws \AwdStudio\ServiceBuses\Exception\HandlerNotDefined
* @throws \AwdStudio\ServiceBuses\Exception\WrongMessage
* @return iterable<int, callable>
*/
protected function resolveHandlers($message): iterable
{
Expand All @@ -48,8 +46,6 @@ protected function resolveHandlers($message): iterable
* @param object $message
* @param callable $handler
*
* @psalm-param class-string $messageClass
*
* @return mixed
*/
protected function execute($message, callable $handler)
Expand All @@ -63,16 +59,11 @@ protected function execute($message, callable $handler)
* Checks a command.
*
* @param mixed $command
*
* @throws \AwdStudio\ServiceBuses\Exception\WrongMessage
*/
protected function validateCommand($command): void
{
if (!is_object($command)) {
throw new WrongMessage(
\sprintf('Command must be an object, %s given.', \gettype($command))
);
throw new WrongMessage(\sprintf('Command must be an object, %s given.', \gettype($command)));
}
}

}
4 changes: 1 addition & 3 deletions src/ServiceBuses/Core/Bus/MultipleHandlersBus.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php

declare(strict_types=1); // strict mode
declare(strict_types=1);

namespace AwdStudio\ServiceBuses\Core\Bus;

abstract class MultipleHandlersBus extends BusProcessor
{

/**
* Processes a particular message.
*
Expand All @@ -21,5 +20,4 @@ public function run($message): void
$this->execute($message, $handler);
}
}

}
4 changes: 1 addition & 3 deletions src/ServiceBuses/Core/Bus/SingleHandlerBus.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

declare(strict_types=1); // strict mode
declare(strict_types=1);

namespace AwdStudio\ServiceBuses\Core\Bus;

use AwdStudio\ServiceBuses\Exception\HandlerNotDefined;

abstract class SingleHandlerBus extends BusProcessor
{

/**
* Processes a particular message.
*
Expand Down Expand Up @@ -42,5 +41,4 @@ protected function firstHandler($message): callable

throw new HandlerNotDefined(\sprintf('No handlers defined for "%s"', \get_class($message)));
}

}
Loading

0 comments on commit e866a11

Please sign in to comment.