Completed
Push — master ( ebdf69...249119 )
by Menno
04:10
created

IdentifiesEloquentModels::getModelClassNameAndId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Codefocus\ManagedCache\Traits;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
trait IdentifiesEloquentModels
8
{
9
    /**
10
     * Return whether the specified class name is an Eloquent Model.
11
     *
12
     * @param mixed $value
13
     *
14
     * @return bool
15
     */
16
    protected function isModel($value): bool
17
    {
18
        return is_object($value) && is_subclass_of($value, Model::class);
19
    }
20
21
    /**
22
     * Returns an array containing the Model class name, and the model id.
23
     * The id is null if $model is a string.
24
     *
25
     * @param Model|string $model
26
     *
27
     * @return array
28
     */
29
    protected function getModelClassNameAndId($model): array
30
    {
31
        if ($this->isModel($model)) {
32
            return [
33
                get_class($model),
0 ignored issues
show
Bug introduced by
It seems like $model can also be of type string; however, parameter $object of get_class() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

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

33
                get_class(/** @scrutinizer ignore-type */ $model),
Loading history...
34
                $model->getKey(),
35
            ];
36
        }
37
38
        return [
39
            $model,
40
            null,
41
        ];
42
    }
43
}
44