Failed Conditions
Push — refactor/improve-static-analys... ( 8da3ef...a7b39f )
by Bas
09:53
created

InteractsWithPivotTable   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 6
c 1
b 0
f 0
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A formatAttachRecord() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Eloquent\Relations\Concerns;
6
7
trait InteractsWithPivotTable
8
{
9
    /**
10
     * Create a full attachment record payload.
11
     *
12
     * @param  int  $key
13
     * @param  mixed  $value
14
     * @param  array  $attributes
15
     * @param  bool  $hasTimestamps
16
     * @return array
17
     */
18
    protected function formatAttachRecord($key, $value, $attributes, $hasTimestamps)
19
    {
20
        [$id, $attributes] = $this->extractAttachIdAndAttributes($key, $value, $attributes);
21
22
        /**
23
         * When attaching multiple models with pivot data PHP will cast a numeric-string array key to an integer
24
         * By setting the type here we recast it to the keyType set on the model.
25
         */
26
        settype($id, $this->related->getKeyType());
27
28
        return array_merge(
29
            $this->baseAttachRecord($id, $hasTimestamps),
0 ignored issues
show
Bug introduced by
It seems like baseAttachRecord() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
            $this->/** @scrutinizer ignore-call */ 
30
                   baseAttachRecord($id, $hasTimestamps),
Loading history...
30
            $this->castAttributes($attributes)
0 ignored issues
show
Bug introduced by
It seems like castAttributes() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
            $this->/** @scrutinizer ignore-call */ 
31
                   castAttributes($attributes)
Loading history...
31
        );
32
    }
33
}
34