EloquentRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPublished() 0 8 1
A getModel() 0 4 1
A findOrFail() 0 4 1
1
<?php
2
3
namespace Yajra\CMS\Repositories\Navigation;
4
5
use Yajra\CMS\Entities\Navigation;
6
use Yajra\CMS\Repositories\RepositoryAbstract;
7
8
class EloquentRepository extends RepositoryAbstract implements Repository
9
{
10
    /**
11
     * Get all published navigation.
12
     *
13
     * @return \Illuminate\Database\Eloquent\Collection|static[]
14
     */
15
    public function getPublished()
16
    {
17
        return $this->getModel()->with([
18
            'menus' => function ($query) {
19
                $query->limitDepth(1)->orderBy('order', 'asc');
20
            }
21
        ])->published()->get();
22
    }
23
24
    /**
25
     * Get repository model.
26
     *
27
     * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder
28
     */
29
    public function getModel()
30
    {
31
        return new Navigation();
32
    }
33
34
    /**
35
     * Find or fail a navigation.
36
     *
37
     * @param int $id
38
     * @return \Yajra\CMS\Entities\Navigation
39
     */
40
    public function findOrFail($id)
41
    {
42
        return $this->getModel()->query()->findOrFail($id);
0 ignored issues
show
Bug introduced by
The method query does only exist in Illuminate\Database\Eloquent\Model, but not in Illuminate\Database\Eloquent\Builder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
43
    }
44
}
45