Completed
Push — develop ( 939885...8732ab )
by Evan
03:00
created

Type   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A objectAliases() 0 9 1
A getAliasedObject() 0 4 1
A __get() 0 8 2
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
    use ObjectAliases;
14
15
    /**
16
     * The type object
17
     * @var object
18
     */
19
    protected $object;
20
21
    /**
22
     * @return array
23
     */
24
    protected function objectAliases()
25
    {
26
        return [
27
            'id'   => 'name',
28
            'slug' => 'name',
29
            'one'  => 'labels.singular_name',
30
            'many' => 'labels.name',
31
        ];
32
    }
33
34
    /**
35
     * @return object
36
     */
37
    protected function getAliasedObject()
38
    {
39
        return $this->object;
40
    }
41
42
    /**
43
     * Magic Getter.
44
     *
45
     * @param  string $property  Accessed property name
46
     *
47
     * @return mixed
48
     */
49
    public function __get($property)
50
    {
51
        if (! is_null($aliased = $this->aliasGet($property))) {
52
            return $aliased;
53
        }
54
55
        return data_get($this->object, $property);
56
    }
57
58
    /**
59
     * Magic Isset Check.
60
     *
61
     * @param  string  $property Queried property name
62
     *
63
     * @return boolean
64
     */
65
    public function __isset($property)
66
    {
67
        return ! is_null($this->__get($property));
68
    }
69
}
70