SelectMultipleManyToMany::setup()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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