Completed
Push — master ( edcf20...3ec6c0 )
by Marcel
03:05 queued 01:22
created

src/Server/WebSocketServerFactory.php (1 issue)

assigning incompatible types to properties.

Bug Documentation Major

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Server;
4
5
use Ratchet\Http\Router;
6
use React\Socket\Server;
7
use Ratchet\Server\IoServer;
8
use React\Socket\SecureServer;
9
use React\EventLoop\LoopInterface;
10
use React\EventLoop\Factory as LoopFactory;
11
use Symfony\Component\Routing\RequestContext;
12
use Symfony\Component\Routing\RouteCollection;
13
use Symfony\Component\Routing\Matcher\UrlMatcher;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger;
16
17
class WebSocketServerFactory
18
{
19
    /** @var string */
20
    protected $host = '127.0.0.1';
21
22
    /** @var int */
23
    protected $port = 8080;
24
25
    /** @var \React\EventLoop\LoopInterface */
26
    protected $loop;
27
28
    /** @var \Symfony\Component\Routing\RouteCollection */
29
    protected $routes;
30
31
    /** @var Symfony\Component\Console\Output\OutputInterface */
32
    protected $consoleOutput;
33
34
    public function __construct()
35
    {
36
        $this->loop = LoopFactory::create();
37
    }
38
39
    public function useRoutes(RouteCollection $routes)
40
    {
41
        $this->routes = $routes;
42
43
        return $this;
44
    }
45
46
    public function setHost(string $host)
47
    {
48
        $this->host = $host;
49
50
        return $this;
51
    }
52
53
    public function setPort(string $port)
54
    {
55
        $this->port = $port;
56
57
        return $this;
58
    }
59
60
    public function setLoop(LoopInterface $loop)
61
    {
62
        $this->loop = $loop;
63
64
        return $this;
65
    }
66
67
    public function setConsoleOutput(OutputInterface $consoleOutput)
68
    {
69
        $this->consoleOutput = $consoleOutput;
0 ignored issues
show
Documentation Bug introduced by
It seems like $consoleOutput of type object<Symfony\Component...Output\OutputInterface> is incompatible with the declared type object<BeyondCode\Larave...Output\OutputInterface> of property $consoleOutput.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
70
71
        return $this;
72
    }
73
74
    public function createServer(): IoServer
75
    {
76
        $socket = new Server("{$this->host}:{$this->port}", $this->loop);
77
78
        if (config('websockets.ssl.local_cert')) {
79
            $socket = new SecureServer($socket, $this->loop, config('websockets.ssl'));
80
        }
81
82
        $urlMatcher = new UrlMatcher($this->routes, new RequestContext);
83
84
        $router = new Router($urlMatcher);
85
86
        $app = new OriginCheck($router, config('websockets.allowed_origins', []));
87
88
        $httpServer = new HttpServer($app, config('websockets.max_request_size_in_kb') * 1024);
89
90
        if (HttpLogger::isEnabled()) {
91
            $httpServer = HttpLogger::decorate($httpServer);
92
        }
93
94
        return new IoServer($httpServer, $socket, $this->loop);
95
    }
96
}
97