LogLazyLoading   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRelationshipFromMethod() 0 16 3
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