• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nepada / phpstan-message-bus / 11637313686

01 Nov 2024 10:35PM UTC coverage: 85.075%. Remained the same
11637313686

Pull #89

github

web-flow
Update nepada/coding-standard requirement from 7.14.0 to 7.14.1

Updates the requirements on [nepada/coding-standard](https://github.com/nepada/coding-standard) to permit the latest version.
- [Release notes](https://github.com/nepada/coding-standard/releases)
- [Commits](https://github.com/nepada/coding-standard/compare/v7.14.0...v7.14.1)

---
updated-dependencies:
- dependency-name: nepada/coding-standard
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #89: Update nepada/coding-standard requirement from 7.14.0 to 7.14.1

57 of 67 relevant lines covered (85.07%)

1.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.87
/src/MessageBus/CommandBusDynamicMethodThrowTypeExtension.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\PHPStan\MessageBus;
5

6
use Nepada\MessageBus\Commands\Command;
7
use Nepada\MessageBus\Commands\CommandBus;
8
use PhpParser\Node\Expr\MethodCall;
9
use PHPStan\Analyser\Scope;
10
use PHPStan\Reflection\MethodReflection;
11
use PHPStan\Reflection\ReflectionProvider;
12
use PHPStan\Type\DynamicMethodThrowTypeExtension;
13
use PHPStan\Type\Type;
14
use PHPStan\Type\TypeCombinator;
15
use PHPStan\Type\VoidType;
16

17
class CommandBusDynamicMethodThrowTypeExtension implements DynamicMethodThrowTypeExtension
18
{
19

20
    private CommandTypeExtractor $commandTypeExtractor;
21

22
    private CommandHandlerResolver $commandHandlerResolver;
23

24
    private ReflectionProvider $reflectionProvider;
25

26
    public function __construct(CommandTypeExtractor $commandTypeExtractor, CommandHandlerResolver $commandHandlerResolver, ReflectionProvider $reflectionProvider)
27
    {
28
        $this->commandTypeExtractor = $commandTypeExtractor;
1✔
29
        $this->commandHandlerResolver = $commandHandlerResolver;
1✔
30
        $this->reflectionProvider = $reflectionProvider;
1✔
31
    }
32

33
    public function isMethodSupported(MethodReflection $methodReflection): bool
34
    {
35
        if (! is_a($methodReflection->getDeclaringClass()->getName(), CommandBus::class, true)) {
2✔
36
            return false;
×
37
        }
38

39
        return $methodReflection->getName() === 'handle';
2✔
40
    }
41

42
    public function getThrowTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type
43
    {
44
        $throwTypes = [];
2✔
45

46
        $commandBusThrowType = $methodReflection->getThrowType();
2✔
47
        if ($commandBusThrowType !== null && ! $commandBusThrowType instanceof VoidType) {
2✔
48
            $throwTypes[] = $commandBusThrowType;
2✔
49
        }
50

51
        $commandType = $this->commandTypeExtractor->extractCommandType($methodCall, $scope);
2✔
52
        if ($commandType !== null && $commandType !== Command::class) {
2✔
53
            $throwTypes = array_merge(
2✔
54
                $throwTypes,
2✔
55
                $this->getHandlerThrowTypes($commandType, $scope),
2✔
56
            );
2✔
57
        }
58

59
        if (count($throwTypes) === 0) {
2✔
60
            return null;
×
61
        }
62

63
        return TypeCombinator::union(...$throwTypes);
2✔
64
    }
65

66
    /**
67
     * @return Type[]
68
     */
69
    private function getHandlerThrowTypes(string $commandType, Scope $scope): array
70
    {
71
        $throwTypes = [];
2✔
72

73
        foreach ($this->commandHandlerResolver->getHandlerClasses($commandType) as $handlerType) {
2✔
74
            if (! $this->reflectionProvider->hasClass($handlerType)) {
2✔
75
                continue;
×
76
            }
77
            $handlerReflection = $this->reflectionProvider->getClass($handlerType);
2✔
78
            if (! $handlerReflection->hasMethod('__invoke')) {
2✔
79
                continue;
×
80
            }
81
            $handlerThrowType = $handlerReflection->getMethod('__invoke', $scope)->getThrowType();
2✔
82
            if ($handlerThrowType === null || $handlerThrowType instanceof VoidType) {
2✔
83
                continue;
×
84
            }
85
            $throwTypes[] = $handlerThrowType;
2✔
86
        }
87

88
        return $throwTypes;
2✔
89
    }
90

91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc