EloquentJsWasCalled::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace EloquentJs\Query\Events;
4
5
use EloquentJs\Query\Guard\EloquentJsPolicy;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Model;
8
9
class EloquentJsWasCalled
10
{
11
    /**
12
     * @var Builder
13
     */
14
    public $builder;
15
16
    /**
17
     * @var null|string|callable
18
     */
19
    public $rules;
20
21
    /**
22
     * Create a new event instance
23
     *
24
     * @param Builder $builder
25
     * @param null|string|callable $rules
26
     */
27
    public function __construct(Builder $builder, $rules = null)
28
    {
29
        $this->builder = $builder;
30
        $this->rules = $rules;
31
    }
32
33
    /**
34
     * Get the policy registered for this model.
35
     *
36
     * @param Model $model
37
     * @return mixed|null
38
     */
39
    protected function XgetModelPolicy(Model $model)
40
    {
41
        try {
42
            $policy = policy($model);
43
44
            if (is_subclass_of($policy, EloquentJsPolicy::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \EloquentJs\Query\Guard\EloquentJsPolicy::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
45
                return $policy;
46
            }
47
        } catch (\InvalidArgumentException $exception) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
48
49
        return null;
50
    }
51
}
52