GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

EloquentUuidTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUuidColumn() 0 4 2
A bootEloquentUuidTrait() 0 7 1
A scopeOnUuid() 0 7 1
1
<?php
2
3
namespace juniorb2ss\EloquentUuid;
4
5
use juniorb2ss\EloquentUuid\Uuid;
6
7
trait EloquentUuidTrait
8
{
9
    /**
10
     * Return uuidKey
11
     *
12
     * @return string
13
     */
14
    public function getUuidColumn()
15
    {
16
        return (property_exists($this, 'uuidKey') ? $this->uuidKey : 'uuid');
0 ignored issues
show
Bug introduced by
The property uuidKey does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17
    }
18
19
    /**
20
     * Boot the Uuid trait for the model.
21
     *
22
     * @return void
23
     */
24
    public static function bootEloquentUuidTrait()
25
    {
26
        static::creating(function ($model) {
27
            $uuid = (string) Uuid::generate();
28
            $model->{$model->getUuidColumn()} = $uuid;
29
        });
30
    }
31
32
    /**
33
     * Scope a query on uuid.
34
     *
35
     * @param \Illuminate\Database\Eloquent\Builder $query
36
     * @return \Illuminate\Database\Eloquent\Builder
37
     */
38
    public function scopeOnUuid($query, $uuid)
39
    {
40
        return $query->where(
41
            $this->getUuidColumn(),
42
            $uuid
43
        );
44
    }
45
}
46