Passed
Push — master ( ac21bd...36df2b )
by noitran
03:42
created

InteractsWithSchema   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 42
c 0
b 0
f 0
ccs 0
cts 12
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getColumnName() 0 3 1
A getSchemaName() 0 11 3
A getColumnNames() 0 5 1
1
<?php
2
3
namespace Noitran\Repositories\Repositories\Concerns;
4
5
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
6
use Illuminate\Database\Eloquent\Model;
7
8
/**
9
 * Trait InteractsWithSchema
10
 */
11
trait InteractsWithSchema
12
{
13
    /**
14
     * @param string $column
15
     * @param Model $model
16
     *
17
     * @return string
18
     */
19
    public function getColumnName($column, $model = null): string
0 ignored issues
show
Unused Code introduced by
The parameter $model is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

19
    public function getColumnName($column, /** @scrutinizer ignore-unused */ $model = null): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
20
    {
21
        return $column;
22
    }
23
24
    /**
25
     * @param array $columns
26
     * @param Model $model
27
     *
28
     * @return array
29
     */
30
    public function getColumnNames(array $columns, $model = null): array
31
    {
32
        return array_map(function ($column) use ($model) {
33
            return $this->getColumnName($column, $model);
34
        }, $columns);
35
    }
36
37
    /**
38
     * @param Model $model
39
     *
40
     * @return string
41
     */
42
    public function getSchemaName($model = null): string
43
    {
44
        $model = $model ?? $this->model;
45
46
        if ($model instanceof Model) {
47
            return $model->getTable();
48
        } elseif ($model instanceof EloquentBuilder) {
49
            return $model->getModel()->getTable();
50
        }
51
52
        return $model->from;
53
    }
54
}
55