Completed
Pull Request — master (#90)
by
unknown
01:57
created

App   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 39
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
        'active',
20
    ];
21
22
    protected $guarded = [
23
        'key',
24
        'secret',
25
    ];
26
27
    protected $casts = [
28
        'enable_client_messages' => 'bool',
29
        'enable_statistics' => 'bool',
30
    ];
31
32
    public function getTable()
33
    {
34
        return config('websockets.database.tables.apps');
35
    }
36
37
    protected static function boot()
38
    {
39
        parent::boot();
40
41
        static::creating(function (App $app) {
42
            $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...
43
            $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...
44
        });
45
    }
46
}
47