Completed
Push — master ( 564642...5e89f3 )
by Marcel
9s
created

StatisticsUpdated   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A broadcastWith() 0 10 1
A broadcastOn() 0 6 1
A broadcastAs() 0 4 1
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Statistics\Events;
4
5
use Illuminate\Queue\SerializesModels;
6
use Illuminate\Broadcasting\PrivateChannel;
7
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
8
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
9
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
10
11
class StatisticsUpdated implements ShouldBroadcast
12
{
13
    use SerializesModels;
14
15
    /** @var \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry */
16
    protected $webSocketsStatisticsEntry;
17
18
    public function __construct(WebSocketsStatisticsEntry $webSocketsStatisticsEntry)
19
    {
20
        $this->webSocketsStatisticsEntry = $webSocketsStatisticsEntry;
21
    }
22
23
    public function broadcastWith()
24
    {
25
        return [
26
            'time' => (string) $this->webSocketsStatisticsEntry->created_at,
0 ignored issues
show
Documentation introduced by Marcel Pociot
The property created_at does not exist on object<BeyondCode\Larave...SocketsStatisticsEntry>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
27
            'app_id' => $this->webSocketsStatisticsEntry->app_id,
0 ignored issues
show
Documentation introduced by Marcel Pociot
The property app_id does not exist on object<BeyondCode\Larave...SocketsStatisticsEntry>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
28
            'peak_connection_count' => $this->webSocketsStatisticsEntry->peak_connection_count,
0 ignored issues
show
Bug introduced by Marcel Pociot
The property peak_connection_count does not seem to exist. Did you mean connection?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
29
            'websocket_message_count' => $this->webSocketsStatisticsEntry->websocket_message_count,
0 ignored issues
show
Documentation introduced by Marcel Pociot
The property websocket_message_count does not exist on object<BeyondCode\Larave...SocketsStatisticsEntry>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
30
            'api_message_count' => $this->webSocketsStatisticsEntry->api_message_count,
0 ignored issues
show
Documentation introduced by Marcel Pociot
The property api_message_count does not exist on object<BeyondCode\Larave...SocketsStatisticsEntry>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
31
        ];
32
    }
33
34
    public function broadcastOn()
35
    {
36
        $channelName = str_after(DashboardLogger::LOG_CHANNEL_PREFIX.'statistics', 'private-');
37
38
        return new PrivateChannel($channelName);
39
    }
40
41
    public function broadcastAs()
42
    {
43
        return 'statistics-updated';
44
    }
45
}
46