Test Failed
Push — feature-laravel-5.4 ( dbda8c...02b5b6 )
by Kirill
03:30
created

Docs   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A category() 0 4 1
A getNav() 0 7 1
1
<?php
2
/**
3
 * This file is part of laravel.su package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace App\Models;
10
11
use Illuminate\Database\Eloquent\Model;
12
use Illuminate\Database\Eloquent\Relations\BelongsTo;
13
use Illuminate\Support\Collection;
14
15
/**
16
 * Class Docs.
17
 */
18
class Docs extends Model
19
{
20
    /**
21
     * @var string
22
     */
23
    protected $table = 'docs';
24
25
    /**
26
     * @var array
27
     */
28
    protected $fillable = [
29
        'title',
30
        'content_source',
31
        'priority',
32
        // Github
33
        'github_org',
34
        'github_repo',
35
        'github_branch',
36
        'github_file',
37
        'github_hash',
38
    ];
39
40
    /**
41
     * @var array
42
     */
43
    protected $casts = [
44
        'nav' => 'collection'
45
    ];
46
47
    /**
48
     * @return BelongsTo
49
     */
50
    public function category(): BelongsTo
51
    {
52
        return $this->belongsTo(DocsCategory::class);
53
    }
54
55
    /**
56
     * @param array ...$level
57
     * @return Collection
58
     */
59
    public function getNav(...$level): Collection
60
    {
61
        return $this->nav->whereIn('level', $level)
0 ignored issues
show
Documentation introduced by
The property nav does not exist on object<App\Models\Docs>. 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...
62
            ->map(function (array $data) {
63
                return (object) $data;
64
            });
65
    }
66
}
67