SelectMultipleManyToMany   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getColumn() 0 4 1
A setup() 0 5 1
A persist() 0 10 3
1
<?php
2
3
namespace Anavel\Crud\Abstractor\Eloquent\Relation;
4
5
use Anavel\Crud\Abstractor\Eloquent\Relation\Traits\CheckRelationCompatibility;
6
use Doctrine\DBAL\Schema\Column;
7
use Illuminate\Http\Request;
8
9
class SelectMultipleManyToMany extends SelectMultiple
10
{
11
    use CheckRelationCompatibility;
12
13
    protected $compatibleEloquentRelations = [
14
        'Illuminate\Database\Eloquent\Relations\BelongsToMany',
15
    ];
16
17 6
    public function setup()
18
    {
19 6
        $this->checkRelationCompatibility();
20 6
        $this->checkDisplayConfig();
21 6
    }
22
23
    /**
24
     * @param array|null $relationArray
25
     *
26
     * @return mixed
27
     */
28 1
    public function persist(array $relationArray = null, Request $request)
29
    {
30 1
        if (!empty($relationArray)) {
31 1
            $array = $relationArray[$this->eloquentRelation->getRelated()->getKeyName()];
32 1
            if (in_array('', $array)) {
33
                $array = [];
34
            }
35 1
            $this->eloquentRelation->sync($array);
36 1
        }
37 1
    }
38
39
    /**
40
     * @param \ANavallaSuiza\Laravel\Database\Contracts\Dbal\AbstractionLayer $dbal
41
     *
42
     * @return Column
43
     */
44 1
    protected function getColumn($dbal)
45
    {
46 1
        return $dbal->getTableColumn($this->eloquentRelation->getRelated()->getKeyName());
47
    }
48
}
49