LogLazyLoading::getRelationshipFromMethod()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 2
nop 1
1
<?php namespace Cviebrock\EloquentLogLazyLoading;
2
3
trait LogLazyLoading
4
{
5
6
    /**
7
     * Get a relationship value from a method.
8
     *
9
     * @param  string $method
10
     *
11
     * @return mixed
12
     *
13
     * @throws \LogicException
14
     * @throws \Cviebrock\EloquentLogLazyLoading\LazyLoadingException
15
     */
16
    protected function getRelationshipFromMethod($method)
17
    {
18
        $modelName = static::class;
19
20
        $exception = new LazyLoadingException(
21
            "Attempting to lazy-load relation '$method' on model '$modelName'"
22
        );
23
24
        if (property_exists($this, 'disableLazyLoading') && $this->disableLazyLoading) {
0 ignored issues
show
Bug introduced by
The property disableLazyLoading does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
            throw $exception;
26
        }
27
28
        report($exception);
29
30
        return parent::getRelationshipFromMethod($method);
31
    }
32
}
33