GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a0e705...a0e705 )
by Dave
43:17 queued 27:40
created

BelongsTo::retrieveRelationValuesFromQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Form\Related\Forms;
4
5
use Illuminate\Support\Collection;
6
use SleepingOwl\Admin\Form\Related\Elements;
7
8
class BelongsTo extends Elements
9
{
10
    protected $limit = 1;
11
12
    protected function proceedSave(\Illuminate\Http\Request $request)
13
    {
14
        $relation = $this->getRelation();
15
16
        // First we need to remove all entities
17
        if (! $this->toRemove->isEmpty()) {
18
            $class = get_class($relation->getRelated());
19
            $class::destroy($this->toRemove->first());
20
        }
21
22
        if ($this->relatedValues->count() === 0) {
23
            return;
24
        }
25
26
        /** @var $relation \Illuminate\Database\Eloquent\Relations\BelongsTo */
27
        $parent = $this->relatedValues->first();
28
        $parent->save();
29
        // Fresh is used to be sure, that we'll have all attributes loaded in model
30
        // (including autogenerated values by database engine)
31
        $child = $relation->associate($parent->fresh());
32
        $child->save();
33
    }
34
35
    protected function prepareRelatedValues(array $data)
36
    {
37
        $elements = $this->flatNamedElements($this->getNewElements());
38
        foreach ($data as $relatedId => $attributes) {
39
            $related = $this->addOrGetRelated($relatedId);
40
41
            foreach ($elements as $element) {
42
                $attribute = $element->getModelAttributeKey();
43
                $value = $element->prepareValue(array_get($attributes, $attribute));
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

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

43
                $value = $element->prepareValue(/** @scrutinizer ignore-deprecated */ array_get($attributes, $attribute));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
44
                $related->setAttribute($attribute, $value);
0 ignored issues
show
Bug introduced by
The method setAttribute() does not exist on SleepingOwl\Admin\Form\Related\Elements. It seems like you code against a sub-type of SleepingOwl\Admin\Form\Related\Elements such as SleepingOwl\Admin\Form\Related\Forms\ManyToMany. ( Ignorable by Annotation )

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

44
                $related->/** @scrutinizer ignore-call */ 
45
                          setAttribute($attribute, $value);
Loading history...
45
                $element->setModel($related);
46
            }
47
        }
48
    }
49
50
    protected function retrieveRelationValuesFromQuery($query): Collection
51
    {
52
        $removeKeys = $this->toRemove->all();
53
        $related = $this->getRelation()->getRelated();
54
55
        return $query->get()->keyBy($related->getKeyName())->forget($removeKeys);
56
    }
57
58
    protected function getModelForElements(): \Illuminate\Database\Eloquent\Model
59
    {
60
        return $this->getEmptyRelation()->getRelated();
61
    }
62
63
    /**
64
     * Returns fresh instance of model for each element in form.
65
     *
66
     * @return \Illuminate\Database\Eloquent\Model
67
     */
68
    protected function getFreshModelForElements(): \Illuminate\Database\Eloquent\Model
69
    {
70
        $class = get_class($this->getEmptyRelation()->getRelated());
71
72
        return new $class();
73
    }
74
}
75