Completed
Push — master ( a19a47...15bbc5 )
by Arjay
15:59
created

WidgetEloquentRepository::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Yajra\CMS\Repositories\Widget;
4
5
use Yajra\CMS\Entities\Widget;
6
use Yajra\CMS\Repositories\RepositoryAbstract;
7
8
class WidgetEloquentRepository extends RepositoryAbstract implements WidgetRepository
9
{
10
    /**
11
     * Get all widgets.
12
     *
13
     * @return \Illuminate\Database\Eloquent\Collection|static[]
14
     */
15
    public function all()
16
    {
17
        return $this->getModel()->query()->get();
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...
18
    }
19
20
    /**
21
     * Get repository model.
22
     *
23
     * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder
24
     */
25
    public function getModel()
26
    {
27
        return new Widget;
28
    }
29
30
    /**
31
     * Get all published widgets.
32
     *
33
     * @return \Illuminate\Database\Eloquent\Collection|static[]
34
     */
35
    public function getPublished()
36
    {
37
        return $this->getModel()->query()->published()->get();
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...
38
    }
39
}