Passed
Branch feature/first-release (f04d1a)
by Andrea Marco
03:05
created

Inspector   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 0
f 0
dl 0
loc 78
ccs 8
cts 10
cp 0.8
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A inspect() 0 3 1
A getRelationships() 0 3 1
A __construct() 0 2 1
A getUseStatements() 0 3 1
A getProperties() 0 3 1
1
<?php
2
3
namespace Cerbero\EloquentInspector;
4
5
use Cerbero\EloquentInspector\Components\Properties;
6
use Cerbero\EloquentInspector\Components\Relationships;
7
use Cerbero\EloquentInspector\Components\UseStatements;
8
9
/**
10
 * The Eloquent inspector.
11
 *
12
 */
13
class Inspector
14
{
15
    /**
16
     * The inspector instances.
17
     *
18
     * @var array
19
     */
20
    protected static $instances = [];
21
22
    /**
23
     * The `use` statements cache.
24
     *
25
     * @var array
26
     */
27
    protected $useStatements;
28
29
    /**
30
     * The properties cache.
31
     *
32
     * @var array
33
     */
34
    protected $properties;
35
36
    /**
37
     * The relationships cache.
38
     *
39
     * @var array
40
     */
41
    protected $relationships;
42
43
    /**
44
     * Instantiate the class.
45
     *
46
     * @param string $model
47
     */
48
    protected function __construct(protected string $model)
49
    {
50
    }
51
52
    /**
53
     * Statically instantiate the class
54
     *
55
     * @param string $model
56
     * @return static
57
     */
58 6
    public static function inspect(string $model): static
59
    {
60 6
        return static::$instances[$model] ??= new static($model);
61
    }
62
63
    /**
64
     * Retrieve the `use` statements
65
     *
66
     * @return array
67
     */
68 2
    public function getUseStatements(): array
69
    {
70 2
        return $this->useStatements ??= UseStatements::of($this->model)->get();
71
    }
72
73
    /**
74
     * Retrieve the properties
75
     *
76
     * @return array
77
     */
78 1
    public function getProperties(): array
79
    {
80 1
        return $this->properties ??= Properties::of($this->model)->get();
81
    }
82
83
    /**
84
     * Retrieve the relationships
85
     *
86
     * @return array
87
     */
88 1
    public function getRelationships(): array
89
    {
90 1
        return $this->relationships ??= Relationships::of($this->model)->get();
91
    }
92
}
93