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

Inspector::getProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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