merakiframework /
route
| 1 | <?php |
||
| 2 | declare(strict_types=1); |
||
| 3 | |||
| 4 | namespace Meraki\Route; |
||
| 5 | |||
| 6 | use Meraki\Route\Collector; |
||
|
0 ignored issues
–
show
|
|||
| 7 | use Psr\Http\Message\ServerRequestInterface as ServerRequest; |
||
| 8 | use Meraki\Route\Rule; |
||
| 9 | use Meraki\Route\Exception\RequestTargetNotMatched; |
||
| 10 | use Meraki\Route\Exception\MethodNotMatched; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Cycles through a route group yielding any route rules that match the request. |
||
| 14 | */ |
||
| 15 | final class Matcher |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var Collection [$rules description] |
||
| 19 | */ |
||
| 20 | private $rules; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * [__construct description] |
||
| 24 | * |
||
| 25 | * @param Collection $rules [description] |
||
| 26 | */ |
||
| 27 | public function __construct(Collection $rules) |
||
| 28 | { |
||
| 29 | $this->rules = $rules; |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * [match description] |
||
| 34 | * |
||
| 35 | * @param ServerRequest $request [description] |
||
| 36 | * @return MatchResult [description] |
||
| 37 | */ |
||
| 38 | public function match(ServerRequest $request): MatchResult |
||
| 39 | { |
||
| 40 | $matchedRules = []; |
||
| 41 | $allowedMethods = []; |
||
| 42 | |||
| 43 | // check for rules that matches the request-target |
||
| 44 | foreach ($this->rules as $rule) { |
||
| 45 | if ($rule->getPattern()->matches($request->getRequestTarget())) { |
||
| 46 | $matchedRules[] = $rule; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | // else, 404 |
||
| 51 | if (empty($matchedRules)) { |
||
| 52 | return MatchResult::requestTargetNotMatched($request); |
||
| 53 | } |
||
| 54 | |||
| 55 | // make sure rule matches method used and build 'allowed methods' in case of 405 |
||
| 56 | foreach ($matchedRules as $matchedRule) { |
||
| 57 | $allowedMethods[] = $matchedRule->getMethod(); |
||
| 58 | |||
| 59 | if ($matchedRule->matchesMethod($request->getMethod())) { |
||
| 60 | return MatchResult::matched($request, $matchedRule); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | return MatchResult::methodNotMatched($request, $allowedMethods); |
||
| 65 | } |
||
| 66 | } |
||
| 67 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths