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

InteractsWithSchema::getColumnNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
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