InteractsWithSchema::getColumnName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 0
cts 1
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Noitran\Repositories\Repositories\Concerns;
6
7
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
8
use Illuminate\Database\Eloquent\Model;
9
10
/**
11
 * Trait InteractsWithSchema.
12
 */
13
trait InteractsWithSchema
14
{
15
    /**
16
     * @param string $column
17
     * @param Model $model
18
     *
19
     * @return string
20
     */
21
    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

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