MorphToMany::newPivot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Cino\LaravelChronos\Eloquent\Relations;
4
5
use Cino\LaravelChronos\Eloquent\Concerns\ChronosGetPivotClass;
6
use Cino\LaravelChronos\Eloquent\Concerns\ChronosRelations;
7
use Illuminate\Database\Eloquent\Relations\MorphToMany as BaseMorphToMany;
8
9
class MorphToMany extends BaseMorphToMany
10
{
11
    use ChronosGetPivotClass;
12
    use ChronosRelations;
13
14
    /**
15
     * Create a new pivot model instance.
16
     *
17
     * @param array $attributes
18
     * @param bool $exists
19
     * @return \Cino\LaravelChronos\Eloquent\Relations\MorphPivot
20
     */
21 1
    public function newPivot(array $attributes = [], $exists = false)
22
    {
23 1
        $using = $this->using;
24
25 1
        $pivot = $using
26 1
            ? $using::fromRawAttributes($this->parent, $attributes, $this->table, $exists)
27 1
            : MorphPivot::fromAttributes($this->parent, $attributes, $this->table, $exists);
28
29 1
        $pivot->setPivotKeys($this->foreignPivotKey, $this->relatedPivotKey)
30 1
            ->setMorphType($this->morphType)
31 1
            ->setMorphClass($this->morphClass);
32
33 1
        return $pivot;
34
    }
35
}
36