Snippet   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 52
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A votes() 0 4 1
A forks() 0 4 1
A originalSnippet() 0 4 1
A user() 0 4 1
A isAFork() 0 4 1
1
<?php
2
3
namespace App;
4
5
class Snippet extends Model
6
{
7
    /**
8
     * A snippet may have multiple forks.
9
     *
10
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
11
     */
12
    public function forks()
13
    {
14
        return $this->hasMany(self::class, 'forked_id');
15
    }
16
17
    /**
18
     * A snippet may be forked from another snippet.
19
     *
20
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
21
     */
22
    public function originalSnippet()
23
    {
24
        return $this->belongsTo(self::class, 'forked_id');
25
    }
26
27
    /**
28
     * A snippet is owned by a user.
29
     *
30
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
31
     */
32
    public function user()
33
    {
34
        return $this->belongsTo(User::class);
35
    }
36
37
    /**
38
     * Determine if the current snippet is a fork.
39
     *
40
     * @return bool
41
     */
42
    public function isAFork()
43
    {
44
        return (bool) $this->forked_id;
0 ignored issues
show
Documentation introduced by
The property forked_id 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...
45
    }
46
47
    /**
48
     * A snippet may have multiple votes.
49
     *
50
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
51
     */
52
    public function votes()
53
    {
54
        return $this->hasMany(SnippetVote::class);
55
    }
56
}
57