Completed
Branch develop (2a5993)
by Evan
02:52
created

Type   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 61
rs 10
wmc 5
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A object() 0 4 1
A __get() 0 12 3
A __isset() 0 4 1
1
<?php
2
3
namespace Silk\Type;
4
5
/**
6
 * @property-read int|string $id
7
 * @property-read string     $slug
8
 * @property-read string     $one
9
 * @property-read string     $many
10
 */
11
abstract class Type
12
{
13
    /**
14
     * The type object
15
     * @var object
16
     */
17
    protected $object;
18
19
    /**
20
     * Type object property aliases
21
     * @var array
22
     */
23
    protected $objectAliases = [
24
        'id'   => 'name',
25
        'slug' => 'name',
26
        'one'  => 'labels.singular_name',
27
        'many' => 'labels.name',
28
    ];
29
30
    /**
31
     * Get the type object.
32
     *
33
     * @return object
34
     */
35
    public function object()
36
    {
37
        return $this->object;
38
    }
39
40
    /**
41
     * Magic Getter.
42
     *
43
     * @param  string $property  Accessed property name
44
     *
45
     * @return mixed
46
     */
47
    public function __get($property)
48
    {
49
        if (isset($this->object->$property)) {
50
            return $this->object->$property;
51
        }
52
53
        if (! array_key_exists($property, $this->objectAliases)) {
54
            return null;
55
        }
56
57
        return data_get($this->object, $this->objectAliases[$property]);
58
    }
59
60
    /**
61
     * Magic Isset Check.
62
     *
63
     * @param  string  $property Queried property name
64
     *
65
     * @return boolean
66
     */
67
    public function __isset($property)
68
    {
69
        return ! is_null($this->__get($property));
70
    }
71
}
72