Completed
Push — 5.1 ( c7eca6...1f8916 )
by Jarek
05:49
created

JoinerFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A make() 0 9 2
1
<?php
2
3
namespace Sofa\Eloquence\Relations;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
7
use Sofa\Eloquence\Contracts\Relations\JoinerFactory as FactoryContract;
8
9
class JoinerFactory implements FactoryContract
10
{
11
    /**
12
     * Create new joiner instance.
13
     *
14
     * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query
15
     * @param  \Illuminate\Database\Eloquent\Model $model
16
     * @return \Sofa\Eloquence\Relations\Joiner
17
     */
18
    public static function make($query, Model $model = null)
19
    {
20
        if ($query instanceof EloquentBuilder) {
21
            $model = $query->getModel();
22
            $query = $query->getQuery();
23
        }
24
25
        return new Joiner($query, $model);
0 ignored issues
show
Bug introduced by
It seems like $model defined by parameter $model on line 18 can be null; however, Sofa\Eloquence\Relations\Joiner::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
26
    }
27
}
28