prooph / message-flow-analyzer

Static code analyzer for message flow in a prooph powered project
BSD 3-Clause "New" or "Revised" License
30 stars 4 forks source link

"Zend\Expressive\Router\RouterInterface" could not be found in the located source #2

Closed oqq closed 6 years ago

oqq commented 6 years ago

After execution of:

$ vendor/bin/prooph-analyzer project:analyze src -vvv

I got the following output:


Using config ./prooph_analyzer.json

[Roave\BetterReflection\Reflector\Exception\IdentifierNotFound]
Roave\BetterReflection\Reflection\ReflectionClass "Zend\Expressive\Router\RouterInterface" could not be found in the located source  

Exception trace:
 () at /Users/***/Projects/***/vendor/roave/better-reflection/src/Reflector/Exception/IdentifierNotFound.php:33
 Roave\BetterReflection\Reflector\Exception\IdentifierNotFound::fromIdentifier() at /Users/***/Projects/***/vendor/roave/better-reflection/src/Reflector/ClassReflector.php:40
 Roave\BetterReflection\Reflector\ClassReflector->reflect() at /Users/***/Projects/***/vendor/roave/better-reflection/src/Reflection/ReflectionClass.php:113
 Roave\BetterReflection\Reflection\ReflectionClass::createFromName() at /Users/***/Projects/***/vendor/prooph/message-flow-analyzer/src/Visitor/MessageHandlerCollector.php:47
 Prooph\MessageFlowAnalyzer\Visitor\MessageHandlerCollector->inspectMethod() at /Users/***/Projects/***/vendor/prooph/message-flow-analyzer/src/Visitor/MessageHandlerCollector.php:26
 Prooph\MessageFlowAnalyzer\Visitor\MessageHandlerCollector->onClassReflection() at /Users/***/Projects/***/vendor/prooph/message-flow-analyzer/src/ProjectTraverser.php:117
 Prooph\MessageFlowAnalyzer\ProjectTraverser->handleFile() at /Users/***/Projects/***/vendor/prooph/message-flow-analyzer/src/ProjectTraverser.php:89
 Prooph\MessageFlowAnalyzer\ProjectTraverser->traverse() at /Users/***/Projects/***/vendor/prooph/message-flow-analyzer/src/Cli/AnalyzeProjectCommand.php:86
 Prooph\MessageFlowAnalyzer\Cli\AnalyzeProjectCommand->execute() at /Users/***/Projects/***/vendor/symfony/console/Command/Command.php:240
 Symfony\Component\Console\Command\Command->run() at /Users/***/Projects/***/vendor/symfony/console/Application.php:858
 Symfony\Component\Console\Application->doRunCommand() at /Users/***/Projects/***/vendor/symfony/console/Application.php:216
 Symfony\Component\Console\Application->doRun() at /Users/***/Projects/***/vendor/symfony/console/Application.php:122
 Symfony\Component\Console\Application->run() at /Users/***/Projects/***/vendor/prooph/message-flow-analyzer/bin/prooph-analyzer:41

project:analyze [-c|--config [CONFIG]] [-o|--output [OUTPUT]] [-f|--format [FORMAT]] [--] [<dir>]

The tested class file has a content like:

<?php

declare(strict_types=1);

namespace Acme\Middleware;

use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Expressive\Router\RouterInterface;

final class SomeMiddleware implements MiddlewareInterface
{
    private $router;

    public function __construct(RouterInterface $router)
    {
        $this->router = $router;
    }

    public function process(ServerRequestInterface $request, DelegateInterface $delegate): ResponseInterface
    {
        // some content 
    }
}
prolic commented 6 years ago

@oqq did you check if this interface really exists in your vendor-dir?

oqq commented 6 years ago

Of course, yes. The file exists and this middleware is accessible in a running application.

codeliner commented 6 years ago

@oqq Not sure what exactly goes wrong here. You could try to figure it out.

One idea would be to use a php test script like this one:

<?php

require 'vendor/autoload.php';

use Roave\BetterReflection\Reflection\ReflectionClass;

$reflectedInterface = ReflectionClass::createFromName('Zend\Expressive\Router\RouterInterface');

like it is tried here: https://github.com/prooph/message-flow-analyzer/blob/master/src/Visitor/MessageHandlerCollector.php#L47

codeliner commented 6 years ago

A workaround would be to use an exclude filter like I did for proophessor-do: https://github.com/prooph/message-flow-analyzer#run-it-against-proophessor-do (see point 5)

But in that case the interface is really not installed so the blacklist filter is the right option to use. In your case the interface seems to be available so the question is why it cannot be autoloaded by BetterReflection to inspect it.

oqq commented 6 years ago

I got same error.. So i will close this issue, go further with tests and will open an issue for the better reflection library.

codeliner commented 6 years ago

ok, let me know the result

oqq commented 6 years ago

Seems to be fixed now. 👍

codeliner commented 6 years ago

oh nice, need to try it