HttpLogger   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 49
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A decorate() 0 6 1
A setApp() 0 6 1
A onOpen() 0 4 1
A onMessage() 0 4 1
A onClose() 0 4 1
A onError() 0 14 2
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Server\Logger;
4
5
use Exception;
6
use Ratchet\ConnectionInterface;
7
use Ratchet\MessageComponentInterface;
8
9
class HttpLogger extends Logger implements MessageComponentInterface
10
{
11
    /** @var \Ratchet\Http\HttpServerInterface */
12
    protected $app;
13
14
    public static function decorate(MessageComponentInterface $app): self
15
    {
16
        $logger = app(self::class);
17
18
        return $logger->setApp($app);
19
    }
20
21
    public function setApp(MessageComponentInterface $app)
22
    {
23
        $this->app = $app;
0 ignored issues
show
Documentation Bug introduced by Marcel Pociot
$app is of type object<Ratchet\MessageComponentInterface>, but the property $app was declared to be of type object<Ratchet\Http\HttpServerInterface>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
24
25
        return $this;
26
    }
27
28
    public function onOpen(ConnectionInterface $connection)
29
    {
30
        $this->app->onOpen($connection);
31
    }
32
33
    public function onMessage(ConnectionInterface $connection, $message)
34
    {
35
        $this->app->onMessage($connection, $message);
36
    }
37
38
    public function onClose(ConnectionInterface $connection)
39
    {
40
        $this->app->onClose($connection);
41
    }
42
43
    public function onError(ConnectionInterface $connection, Exception $exception)
44
    {
45
        $exceptionClass = get_class($exception);
46
47
        $message = "Exception `{$exceptionClass}` thrown: `{$exception->getMessage()}`";
48
49
        if ($this->verbose) {
50
            $message .= $exception->getTraceAsString();
51
        }
52
53
        $this->error($message);
54
55
        $this->app->onError($connection, $exception);
56
    }
57
}
58