AbstractionLayer   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 65
ccs 24
cts 28
cp 0.8571
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getModel() 0 4 1
A getSchemaManager() 0 6 1
A getTableColumns() 0 8 1
A getTableColumn() 0 10 2
A getModelAttributes() 0 11 2
A getTableForeignKeys() 0 8 1
1
<?php
2
3
namespace Ablunier\Laravel\Database\Dbal\Eloquent;
4
5
use Ablunier\Laravel\Database\Contracts\Dbal\AbstractionLayer as AbstractionLayerContract;
6
use Illuminate\Database\Eloquent\Model as EloquentModel;
7
use Schema;
8
9
class AbstractionLayer implements AbstractionLayerContract
10
{
11
    /**
12
     * @var EloquentModel
13
     */
14
    protected $model;
15
16
    public function __construct(EloquentModel $model)
17 9
    {
18
        $this->model = $model;
19 9
    }
20 9
21
    public function getModel()
22 1
    {
23
        return $this->model;
24 1
    }
25
26
    protected function getSchemaManager()
27 4
    {
28
        $connection = Schema::getConnection();
29 4
30
        return $connection->getDoctrineSchemaManager();
31 4
    }
32
33
    public function getTableColumns()
34 4
    {
35
        $sm = $this->getSchemaManager();
36 4
37
        $columns = $sm->listTableColumns($this->model->getTable());
38 4
39
        return $columns;
40 4
    }
41
42
    public function getTableColumn($name)
43 2
    {
44
        $columns = $this->getTableColumns();
45 2
46
        if (!array_key_exists($name, $columns)) {
47 2
            throw new \Exception('Column '.$name.' not found on '.$this->model->getTable());
48 1
        }
49
50
        return $columns[$name];
51 1
    }
52
53
    public function getModelAttributes()
54 1
    {
55
        $columns = $this->getTableColumns();
56 1
57
        $attributes = [];
58 1
        foreach ($columns as $fieldName => $field) {
59 1
            $attributes[] = $fieldName;
60 1
        }
61 1
62
        return $attributes;
63 1
    }
64
65
    public function getTableForeignKeys()
66
    {
67
        $sm = $this->getSchemaManager();
68
69
        $foreignKeys = $sm->listTableForeignKeys($this->model->getTable());
70
71
        return $foreignKeys;
72
    }
73
}
74