Completed
Pull Request — master (#20)
by Evan
02:36
created

Type::object()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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
{
0 ignored issues
show
introduced by
Opening brace of a class must be on the same line as the definition
Loading history...
13
    /**
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
14
     * The type object
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
15
     * @var object
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
16
     */
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
17
    protected $object;
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
18
19
    /**
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
20
     * Type object property aliases
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
21
     * @var array
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
22
     */
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
23
    protected $objectAliases = [
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
24
        'id'   => 'name',
0 ignored issues
show
introduced by
8 spaces found, expected 2 tabs
Loading history...
introduced by
Double space found
Loading history...
25
        'slug' => 'name',
0 ignored issues
show
introduced by
8 spaces found, expected 2 tabs
Loading history...
26
        'one'  => 'labels.singular_name',
0 ignored issues
show
introduced by
8 spaces found, expected 2 tabs
Loading history...
introduced by
Double space found
Loading history...
27
        'many' => 'labels.name',
0 ignored issues
show
introduced by
8 spaces found, expected 2 tabs
Loading history...
28
    ];
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
29
30
    /**
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
31
     * Get the type object.
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
32
     *
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
33
     * @return object
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
34
     */
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
35
    public function object()
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
36
    {
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
introduced by
Opening brace of a function must be on the same line as the definition
Loading history...
37
        return $this->object;
0 ignored issues
show
introduced by
8 spaces found, expected 2 tabs
Loading history...
38
    }
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
39
40
    /**
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
41
     * Magic Getter.
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
42
     *
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
43
     * @param  string $property  Accessed property name
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
44
     *
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
45
     * @return mixed
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
46
     */
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
47
    public function __get($property)
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
48
    {
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
introduced by
Opening brace of a function must be on the same line as the definition
Loading history...
49
        if (isset($this->object->$property)) {
0 ignored issues
show
introduced by
8 spaces found, expected 2 tabs
Loading history...
50
            return $this->object->$property;
0 ignored issues
show
introduced by
12 spaces found, expected 3 tabs
Loading history...
51
        }
0 ignored issues
show
introduced by
8 spaces found, expected 2 tabs
Loading history...
52
53
        if (! array_key_exists($property, $this->objectAliases)) {
0 ignored issues
show
introduced by
8 spaces found, expected 2 tabs
Loading history...
introduced by
No whitespace should be between cast and variable.
Loading history...
54
            return null;
0 ignored issues
show
introduced by
12 spaces found, expected 3 tabs
Loading history...
55
        }
0 ignored issues
show
introduced by
8 spaces found, expected 2 tabs
Loading history...
56
57
        return data_get($this->object, $this->objectAliases[$property]);
0 ignored issues
show
introduced by
8 spaces found, expected 2 tabs
Loading history...
58
    }
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
59
60
    /**
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
61
     * Magic Isset Check.
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
62
     *
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
63
     * @param  string  $property Queried property name
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
64
     *
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
65
     * @return boolean
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
introduced by
boolean => bool
Loading history...
66
     */
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
67
    public function __isset($property)
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
68
    {
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
introduced by
Opening brace of a function must be on the same line as the definition
Loading history...
69
        return ! is_null($this->__get($property));
0 ignored issues
show
introduced by
8 spaces found, expected 2 tabs
Loading history...
introduced by
No whitespace should be between cast and variable.
Loading history...
introduced by
is_null() found, should be strict === null check.
Loading history...
70
    }
0 ignored issues
show
introduced by
4 spaces found, expected 1 tabs
Loading history...
71
}
0 ignored issues
show
introduced by
Closing brace of a class must have a new line between itself and the last content.
Loading history...
72