Updatable   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A update() 0 8 2
1
<?php
2
3
namespace Laravel\DataTables\Traits;
4
5
use Arr;
6
use Illuminate\Database\Eloquent\Model;
7
8
trait Updatable
9
{
10
    /**
11
     * Allow Entity Updating.
12
     *
13
     * @var bool
14
     */
15
    public $allowUpdating = false;
16
17
    /**
18
     * @param Model $model
19
     * @param array $data
20
     * @return Model
21
     */
22
    public function update(Model $model, array $data = []): ?Model
23
    {
24
        if (! $this->allowUpdating) {
25
            return null;
26
        }
27
28
        return tap($model, function ($model) use ($data) {
29
            $model->update(Arr::only($data, $this->getUpdatableColumns()));
0 ignored issues
show
Bug introduced by
It seems like getUpdatableColumns() 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
            $model->update(Arr::only($data, $this->/** @scrutinizer ignore-call */ getUpdatableColumns()));
Loading history...
30
        });
31
    }
32
}
33