Test Failed
Pull Request — master (#660)
by butschster
09:30
created

AuthorizationMiddleware::process()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 3
nop 2
dl 0
loc 16
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Broadcasting\Middleware;
6
7
use Psr\Http\Message\ResponseFactoryInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\MiddlewareInterface;
11
use Psr\Http\Server\RequestHandlerInterface;
12
use Spiral\Broadcasting\BroadcastInterface;
13
use Spiral\Broadcasting\Config\BroadcastConfig;
14
use Spiral\Broadcasting\GuardInterface;
15
16
final class AuthorizationMiddleware implements MiddlewareInterface
17
{
18
    private ResponseFactoryInterface $responseFactory;
19
    private BroadcastInterface $broadcast;
20
    private ?string $authorizationPath;
21
22
    public function __construct(
23
        BroadcastInterface $broadcast,
24
        ResponseFactoryInterface $responseFactory,
25
        ?string $authorizationPath = null
26
    ) {
27
        $this->responseFactory = $responseFactory;
28
        $this->broadcast = $broadcast;
29
        $this->authorizationPath = $authorizationPath;
30
    }
31
32
    public function process(
33
        ServerRequestInterface $request,
34
        RequestHandlerInterface $handler
35
    ): ResponseInterface {
36
        if ($request->getUri()->getPath() !== $this->authorizationPath) {
37
            return $handler->handle($request);
38
        }
39
40
        if (
41
            !$this->broadcast instanceof GuardInterface
42
            || $this->broadcast->authorize($request)
0 ignored issues
show
Bug introduced by
The method authorize() does not exist on Spiral\Broadcasting\BroadcastInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
            || $this->broadcast->/** @scrutinizer ignore-call */ authorize($request)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
        ) {
44
            return $this->responseFactory->createResponse(200);
45
        }
46
47
        return $this->responseFactory->createResponse(403);
48
    }
49
}
50