Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( b39a30...0f42e8 )
by Cristian
09:24
created

Article::sluggable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Backpack\NewsCRUD\app\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Backpack\CRUD\CrudTrait;
7
use Cviebrock\EloquentSluggable\Sluggable;
8
9
class Article extends Model
10
{
11
    use CrudTrait;
12
    use Sluggable;
13
14
    /*
15
    |--------------------------------------------------------------------------
16
    | GLOBAL VARIABLES
17
    |--------------------------------------------------------------------------
18
    */
19
20
    protected $table = 'articles';
21
    protected $primaryKey = 'id';
22
    public $timestamps = true;
23
    // protected $guarded = ['id'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
24
    protected $fillable = ['slug', 'title', 'content', 'image', 'status', 'category_id', 'featured', 'date'];
25
    // protected $hidden = [];
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
26
    // protected $dates = [];
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
27
    protected $casts = [
28
        'featured'  => 'boolean',
29
        'date'      => 'date',
30
    ];
31
32
    /**
33
     * Return the sluggable configuration array for this model.
34
     *
35
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array<string,string>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
36
     */
37
    public function sluggable()
38
    {
39
        return [
40
            'slug' => [
41
                'source' => 'slug_or_title',
42
            ],
43
        ];
44
    }
45
46
    /*
47
    |--------------------------------------------------------------------------
48
    | FUNCTIONS
49
    |--------------------------------------------------------------------------
50
    */
51
52
    /*
53
    |--------------------------------------------------------------------------
54
    | RELATIONS
55
    |--------------------------------------------------------------------------
56
    */
57
58
    public function category()
59
    {
60
        return $this->belongsTo('Backpack\NewsCRUD\app\Models\Category', 'category_id');
61
    }
62
63
    public function tags()
64
    {
65
        return $this->belongsToMany('Backpack\NewsCRUD\app\Models\Tag', 'article_tag');
66
    }
67
68
    /*
69
    |--------------------------------------------------------------------------
70
    | SCOPES
71
    |--------------------------------------------------------------------------
72
    */
73
74
    public function scopePublished($query)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
75
    {
76
        return $query->where('status', 'PUBLISHED')
77
                    ->where('date', '<=', date('Y-m-d'))
78
                    ->orderBy('date', 'DESC');
79
    }
80
81
    /*
82
    |--------------------------------------------------------------------------
83
    | ACCESORS
84
    |--------------------------------------------------------------------------
85
    */
86
87
    // The slug is created automatically from the "title" field if no slug exists.
88
    public function getSlugOrTitleAttribute()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
89
    {
90
        if ($this->slug != '') {
0 ignored issues
show
Documentation introduced by
The property slug does not exist on object<Backpack\NewsCRUD\app\Models\Article>. 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...
91
            return $this->slug;
0 ignored issues
show
Documentation introduced by
The property slug does not exist on object<Backpack\NewsCRUD\app\Models\Article>. 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...
92
        }
93
94
        return $this->title;
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<Backpack\NewsCRUD\app\Models\Article>. 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...
95
    }
96
97
    /*
98
    |--------------------------------------------------------------------------
99
    | MUTATORS
100
    |--------------------------------------------------------------------------
101
    */
102
}
103