Passed
Push — master ( 372072...37634a )
by Ricardo
52s queued 12s
created

Chronos::refresh()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0438

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 17
ccs 7
cts 9
cp 0.7778
rs 9.9666
cc 2
nc 2
nop 0
crap 2.0438
1
<?php
2
3
namespace Cino\LaravelChronos\Eloquent;
4
5
use Cino\LaravelChronos\Eloquent\Concerns\ChronosRelations;
6
use Cino\LaravelChronos\Eloquent\Concerns\ChronosTimestamps;
7
use Cino\LaravelChronos\Eloquent\Relations\Pivot;
8
use Illuminate\Database\Eloquent\Model as BaseModel;
9
use Illuminate\Support\Collection;
10
11
/**
12
 * @mixin \Illuminate\Database\Eloquent\Model
13
 */
14
trait Chronos
15
{
16
    use ChronosRelations;
17
    use ChronosTimestamps;
18
19
    /**
20
     * Create a new pivot model instance.
21
     *
22
     * @param \Illuminate\Database\Eloquent\Model $parent
23
     * @param array $attributes
24
     * @param string $table
25
     * @param bool $exists
26
     * @param string|null $using
27
     * @return \Cino\LaravelChronos\Eloquent\Relations\Pivot
28
     */
29 1
    public function newPivot(BaseModel $parent, array $attributes, $table, $exists, $using = null)
30
    {
31 1
        return $using ? $using::fromRawAttributes($parent, $attributes, $table, $exists)
32 1
            : Pivot::fromAttributes($parent, $attributes, $table, $exists);
33
    }
34
35
    /**
36
     * Reload the current model instance with fresh attributes from the database.
37
     *
38
     * @return \Illuminate\Database\Eloquent\Model
39
     */
40 1
    public function refresh()
41
    {
42 1
        if (!$this->exists) {
43
            return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Cino\LaravelChronos\Eloquent\Chronos which is incompatible with the documented return type Illuminate\Database\Eloquent\Model.
Loading history...
44
        }
45
46 1
        $this->setRawAttributes(
0 ignored issues
show
Bug introduced by
It seems like setRawAttributes() 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

46
        $this->/** @scrutinizer ignore-call */ 
47
               setRawAttributes(
Loading history...
47 1
            static::newQueryWithoutScopes()->findOrFail($this->getKey())->attributes
0 ignored issues
show
Bug introduced by
It seems like getKey() 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

47
            static::newQueryWithoutScopes()->findOrFail($this->/** @scrutinizer ignore-call */ getKey())->attributes
Loading history...
48
        );
49
50
        $this->load(Collection::make($this->relations)->reject(function ($relation) {
0 ignored issues
show
Bug introduced by
It seems like load() 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

50
        $this->/** @scrutinizer ignore-call */ 
51
               load(Collection::make($this->relations)->reject(function ($relation) {
Loading history...
51
            return $relation instanceof Pivot;
52 1
        })->keys()->all());
53
54 1
        $this->syncOriginal();
0 ignored issues
show
Bug introduced by
It seems like syncOriginal() 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

54
        $this->/** @scrutinizer ignore-call */ 
55
               syncOriginal();
Loading history...
55
56 1
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Cino\LaravelChronos\Eloquent\Chronos which is incompatible with the documented return type Illuminate\Database\Eloquent\Model.
Loading history...
57
    }
58
}
59