Test Failed
Push — feature-laravel-5.4 ( 43bafb...e7f3fd )
by Kirill
42:21
created

DocsPage::scopeWhereVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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\Builder;
12
use Illuminate\Support\Collection;
13
use Illuminate\Database\Eloquent\Model;
14
use Illuminate\Database\Eloquent\Relations\BelongsTo;
15
16
/**
17
 * Class DocsPage.
18
 */
19
class DocsPage extends Model
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $table = 'docs_pages';
25
26
    /**
27
     * @var array
28
     */
29
    protected $fillable = [
30
        'identify',
31
        'hash',
32
        'title',
33
        'title',
34
        'content_source',
35
        'priority',
36
        'nav',
37
    ];
38
39
    /**
40
     * @var array
41
     */
42
    protected $casts = [
43
        'nav' => 'collection',
44
    ];
45
46
    /**
47
     * @return BelongsTo
48
     */
49
    public function category(): BelongsTo
50
    {
51
        return $this->belongsTo(DocsCategory::class);
52
    }
53
54
    /**
55
     * @return BelongsTo
56
     */
57
    public function docs(): BelongsTo
58
    {
59
        return $this->belongsTo(Docs::class);
60
    }
61
62
    /**
63
     * @param  array      ...$level
64
     * @return Collection
65
     */
66
    public function getNav(...$level): Collection
67
    {
68
        return $this->nav->whereIn('level', $level)
0 ignored issues
show
Documentation introduced by
The property nav does not exist on object<App\Models\DocsPage>. 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
            ->map(function (array $data) {
70
                return (object) $data;
71
            });
72
    }
73
74
    /**
75
     * @param Builder $builder
76
     * @param string  $version
77
     * @return Builder
78
     */
79
    public static function scopeWhereVersion(Builder $builder, string $version): Builder
80
    {
81
        return $builder->with(['docs' => function (BelongsTo $relation) use ($version) {
82
            return $relation->where('version', $version);
83
        }]);
84
    }
85
}