Skip to content

Commit

Permalink
fix cs
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Dec 12, 2024
1 parent 3f8618e commit 6d2faa1
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 7 deletions.
34 changes: 30 additions & 4 deletions baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
<code><![CDATA[$this->frozenDateTime->modify(sprintf('+%s seconds', $seconds))]]></code>
</PossiblyFalsePropertyAssignmentValue>
</file>
<file src="src/CommandBus/Handler/CreateAggregateHandler.php">
<InvalidOperand>
<code><![CDATA[ParameterResolver::resolve($reflectionMethod, $this->container)]]></code>
</InvalidOperand>
</file>
<file src="src/CommandBus/Handler/UpdateAggregateHandler.php">
<InvalidOperand>
<code><![CDATA[ParameterResolver::resolve($reflectionMethod, $this->container)]]></code>
</InvalidOperand>
</file>
<file src="src/Console/DoctrineHelper.php">
<ClassNotFinal>
<code><![CDATA[class DoctrineHelper]]></code>
Expand Down Expand Up @@ -57,9 +67,6 @@
</InvalidReturnType>
</file>
<file src="src/Metadata/AggregateRoot/AttributeAggregateRootMetadataFactory.php">
<DocblockTypeContradiction>
<code><![CDATA[$reflectionType instanceof ReflectionIntersectionType]]></code>
</DocblockTypeContradiction>
<InvalidReturnStatement>
<code><![CDATA[$this->aggregateMetadata[$aggregate]]]></code>
</InvalidReturnStatement>
Expand Down Expand Up @@ -219,6 +226,21 @@
<code><![CDATA[$row['payload']]]></code>
</MixedArgument>
</file>
<file src="tests/Unit/CommandBus/DefaultCommandBusTest.php">
<InvalidPropertyFetch>
<code><![CDATA[$handler->command]]></code>
</InvalidPropertyFetch>
</file>
<file src="tests/Unit/CommandBus/Handler/DefaultHandlerFactoryTest.php">
<ArgumentTypeCoercion>
<code><![CDATA['aggregateClass']]></code>
<code><![CDATA['aggregateClass']]></code>
</ArgumentTypeCoercion>
<UndefinedClass>
<code><![CDATA['aggregateClass']]></code>
<code><![CDATA['aggregateClass']]></code>
</UndefinedClass>
</file>
<file src="tests/Unit/EventBus/DefaultEventBusTest.php">
<MoreSpecificImplementedParamType>
<code><![CDATA[$message]]></code>
Expand All @@ -239,6 +261,11 @@
<code><![CDATA[$event]]></code>
</MissingParamType>
</file>
<file src="tests/Unit/Fixture/ProfileWithHandlers.php">
<MissingParamType>
<code><![CDATA[$command]]></code>
</MissingParamType>
</file>
<file src="tests/Unit/Metadata/Subscriber/AttributeSubscriberMetadataFactoryTest.php">
<MissingParamType>
<code><![CDATA[$message]]></code>
Expand Down Expand Up @@ -371,7 +398,6 @@
</file>
<file src="tests/Unit/Subscription/Engine/SubscriptionManagerTest.php">
<InvalidArgument>
<code><![CDATA[$result]]></code>
<code><![CDATA[$subscriptions]]></code>
<code><![CDATA[$subscriptions]]></code>
</InvalidArgument>
Expand Down
5 changes: 5 additions & 0 deletions src/CommandBus/Handler/CreateAggregateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Patchlevel\EventSourcing\CommandBus\Handler;

use InvalidArgumentException;
use Patchlevel\EventSourcing\Aggregate\AggregateRoot;
use Patchlevel\EventSourcing\Repository\RepositoryManager;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -35,6 +36,10 @@ public function __invoke(object $command): void
],
);

if (!$aggregate instanceof AggregateRoot) {
throw new InvalidArgumentException('create method must return an instance of AggregateRoot');
}

$repository->save($aggregate);
}
}
16 changes: 15 additions & 1 deletion src/CommandBus/Handler/ParameterResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Psr\Container\ContainerInterface;
use ReflectionMethod;
use RuntimeException;
use Symfony\Component\TypeInfo\Type\ObjectType;
use Symfony\Component\TypeInfo\TypeResolver\TypeResolver;

/** @internal */
final class ParameterResolver
Expand All @@ -29,7 +31,19 @@ public static function resolve(ReflectionMethod $method, ContainerInterface|null
$serviceName = $attributes[0]->newInstance()->service;

if ($serviceName === null) {
$serviceName = $parameter->getType()->getName();
$reflectionType = $parameter->getType();

if ($reflectionType === null) {
throw new RuntimeException('missing type hint');
}

$type = TypeResolver::create()->resolve($reflectionType);

if (!$type instanceof ObjectType) {
throw new RuntimeException('type hint must be object');
}

$serviceName = $type->getClassName();
}

if (!$container) {
Expand Down
9 changes: 8 additions & 1 deletion src/CommandBus/Handler/UpdateAggregateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Patchlevel\EventSourcing\CommandBus\Handler;

use InvalidArgumentException;
use Patchlevel\EventSourcing\Aggregate\AggregateRoot;
use Patchlevel\EventSourcing\Aggregate\AggregateRootId;
use Patchlevel\EventSourcing\Attribute\Id;
Expand Down Expand Up @@ -54,7 +55,13 @@ private function aggregateRootId(object $command): AggregateRootId
continue;
}

return $property->getValue($command);
$value = $property->getValue($command);

if (!$value instanceof AggregateRootId) {
throw new InvalidArgumentException('Id property must be an instance of AggregateRootId');
}

return $value;
}

throw new AggregateIdNotFound($command::class);
Expand Down
2 changes: 1 addition & 1 deletion src/CommandBus/ServiceNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use function sprintf;

class ServiceNotFound extends RuntimeException implements NotFoundExceptionInterface
final class ServiceNotFound extends RuntimeException implements NotFoundExceptionInterface
{
public function __construct(string $id)
{
Expand Down

0 comments on commit 6d2faa1

Please sign in to comment.