Completed
Push — master ( 5c6350...61c78a )
by Nicolas
14:48 queued 11:44
created

EloquentTagRepository   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 12
ccs 2
cts 2
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A allForNamespace() 0 4 1
1
<?php
2
3
namespace Modules\Tag\Repositories\Eloquent;
4
5
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
6
use Modules\Tag\Repositories\TagRepository;
7
8
class EloquentTagRepository extends EloquentBaseRepository implements TagRepository
9
{
10
    /**
11
     * Get all the tags in the given namespace
12
     * @param string $namespace
13
     * @return \Illuminate\Database\Eloquent\Collection
14
     */
15 1
    public function allForNamespace($namespace)
16
    {
17 1
        return $this->model->with('translations')->where('namespace', $namespace)->get();
0 ignored issues
show
Bug introduced by Nicolas Widart
The method where does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

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