Issues (14)

src/HasDynamicColumn.php (3 issues)

Labels
1
<?php
2
3
namespace Halalsoft\LaravelDynamicColumn;
4
5
6
trait HasDynamicColumn
7
{
8
9
    /**
10
     * Boot the MariaDB Dynamic Column  trait.
11
     *
12
     * @return void
13
     */
14
    protected static function bootHasDynamicColumn()
15
    {
16
        static::addGlobalScope(new DynamicScope());
17
        static::saving(
18
            function($model) {
19
                foreach ($model->getCasts() as $column => $cast) {
20
                    if ($cast == 'Halalsoft\LaravelDynamicColumn\Dynamic' || $cast == "Halalsoft\LaravelDynamicColumn\DynamicObject") {
21
                        $model->$column = $model->$column;
22
                    }
23
                }
24
            }
25
        );
26
    }
27
28
29
    protected function newBaseQueryBuilder()
30
    {
31
        $connection = $this->getConnection();
0 ignored issues
show
It seems like getConnection() 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

31
        /** @scrutinizer ignore-call */ 
32
        $connection = $this->getConnection();
Loading history...
32
33
        return new DynamicBuilder(
34
            $connection, $connection->setQueryGrammar(new DynamicGrammar())->getQueryGrammar(),
35
            $connection->getPostProcessor(), $this
0 ignored issues
show
$this of type Halalsoft\LaravelDynamicColumn\HasDynamicColumn is incompatible with the type Illuminate\Database\Eloquent\Model|null expected by parameter $model of Halalsoft\LaravelDynamic...cBuilder::__construct(). ( Ignorable by Annotation )

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

35
            $connection->getPostProcessor(), /** @scrutinizer ignore-type */ $this
Loading history...
36
        );
37
    }
38
39
40
    public function getDynamicColumns()
41
    {
42
        $columns = [];
43
        foreach ($this->getCasts() as $column => $cast) {
0 ignored issues
show
It seems like getCasts() 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

43
        foreach ($this->/** @scrutinizer ignore-call */ getCasts() as $column => $cast) {
Loading history...
44
            if ($cast == "Halalsoft\LaravelDynamicColumn\Dynamic" || $cast == "Halalsoft\LaravelDynamicColumn\DynamicObject") {
45
                $columns[] = $column;
46
            }
47
        }
48
49
        return $columns;
50
    }
51
52
}