User   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A snippets() 0 4 1
A votes() 0 4 1
A votedFor() 0 4 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Notifications\Notifiable;
6
use Illuminate\Foundation\Auth\User as Authenticatable;
7
8
class User extends Authenticatable
9
{
10
    use Notifiable;
11
12
    /**
13
     * The attributes that are mass assignable.
14
     *
15
     * @var array
16
     */
17
    protected $fillable = [
18
        'name', 'username', 'email', 'password',
19
    ];
20
21
    /**
22
     * The attributes that should be hidden for arrays.
23
     *
24
     * @var array
25
     */
26
    protected $hidden = [
27
        'password', 'remember_token',
28
    ];
29
30
    /**
31
     * The field to be used for route model binding.
32
     *
33
     * @return string
34
     */
35
    public function getRouteKeyName()
36
    {
37
        return 'username';
38
    }
39
40
    /**
41
     * A user may have multiple snippets.
42
     *
43
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
44
     */
45
    public function snippets()
46
    {
47
        return $this->hasMany(Snippet::class);
48
    }
49
50
    /**
51
     * A user may have multiple votes.
52
     *
53
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
54
     */
55
    public function votes()
56
    {
57
        return $this->belongsToMany(Snippet::class, 'snippets_votes')->withTimestamps();
58
    }
59
60
    /**
61
     * Determine if a user voted for a given snippet.
62
     *
63
     * @param  Snippet $snippet
64
     * @return bool
65
     */
66
    public function votedFor(Snippet $snippet)
67
    {
68
        return $snippet->votes->contains('user_id', $this->id);
0 ignored issues
show
Documentation introduced by
The property votes does not exist on object<App\Snippet>. 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...
Documentation introduced by
The property id does not exist on object<App\User>. 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...
69
    }
70
}
71