InteractsWithSchema   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 58.33%

Importance

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

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
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