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

Type::object()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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