Completed
Pull Request — master (#90)
by
unknown
02:51 queued 54s
created

App   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTable() 0 4 1
A boot() 0 9 1
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Database\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
8
class App extends Model
9
{
10
    use SoftDeletes;
11
12
    protected $fillable = [
13
        'name',
14
        'host',
15
        'key',
16
        'secret',
17
        'enable_client_messages',
18
        'enable_statistics',
19
    ];
20
21
    protected $guarded = [
22
        'key',
23
        'secret',
24
    ];
25
26
    protected $casts = [
27
        'enable_client_messages' => 'bool',
28
        'enable_statistics' => 'bool',
29
    ];
30
31
    public function getTable()
32
    {
33
        return config('websockets.database.tables.apps');
34
    }
35
36
    protected static function boot()
37
    {
38
        parent::boot();
39
40
        static::creating(function (App $app) {
41
            $app->key = str_random(40);
0 ignored issues
show
Documentation introduced by
The property key does not exist on object<BeyondCode\Larave...ts\Database\Models\App>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
42
            $app->secret = str_random(40);
0 ignored issues
show
Documentation introduced by
The property secret does not exist on object<BeyondCode\Larave...ts\Database\Models\App>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
43
        });
44
    }
45
}
46