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

nepada / message-bus / 4581487412

pending completion
4581487412

push

github

GitHub
Update spaze/phpstan-disallowed-calls requirement from 2.11.6 to 2.12.1 (#75)

303 of 315 relevant lines covered (96.19%)

0.96 hits per line

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

88.89
/src/MessageBus/StaticAnalysis/Rules/MethodParameterTypeMatchesRule.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\MessageBus\StaticAnalysis\Rules;
5

6
use Nepada\MessageBus\StaticAnalysis\StaticAnalysisFailedException;
7
use ReflectionParameter;
8

9
final class MethodParameterTypeMatchesRule
10
{
11

12
    private string $parameterType;
13

14
    public function __construct(string $parameterType)
1✔
15
    {
16
        $this->parameterType = $parameterType;
1✔
17
    }
1✔
18

19
    /**
20
     * @param ReflectionParameter $parameter
21
     * @throws StaticAnalysisFailedException
22
     */
23
    public function validate(ReflectionParameter $parameter): void
1✔
24
    {
25
        $parameterType = $parameter->getType();
1✔
26
        if ($parameterType === null) {
1✔
27
            throw $this->createException($parameter);
×
28
        }
29

30
        $parameterTypeName = $parameterType->getName();
1✔
31
        if ($parameterTypeName !== $this->parameterType && ! is_subclass_of($parameterTypeName, $this->parameterType)) {
1✔
32
            throw $this->createException($parameter);
1✔
33
        }
34
    }
1✔
35

36
    private function createException(ReflectionParameter $parameter): StaticAnalysisFailedException
1✔
37
    {
38
        $class = $parameter->getDeclaringClass();
1✔
39
        if ($class === null) {
1✔
40
            throw new \LogicException('Class must be set in this context.');
×
41
        }
42

43
        return StaticAnalysisFailedException::with(
1✔
44
            sprintf('Method parameter "%s" must be of type "%s"', $parameter->getName(), $this->parameterType),
1✔
45
            $class->getName(),
1✔
46
        );
47
    }
48

49
}
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