Completed
Push — master ( 9a0c85...24d734 )
by Stephen
02:18
created

Profile::__get()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4286
cc 3
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace StarCitizen\Models;
4
use StarCitizen\Accounts\Accounts;
5
6
/**
7
 * Class Profile
8
 *
9
 * @package StarCitizen\Models
10
 */
11
class Profile
12
{
13
    /**
14
     * @var string
15
     */
16
    public $handle;
17
18
    /**
19
     * @var
20
     */
21
    public $citizen_number;
22
23
    /**
24
     * @var
25
     */
26
    public $status;
27
28
    /**
29
     * @var
30
     */
31
    public $moniker;
32
33
    /**
34
     * @var
35
     */
36
    public $avatar;
37
38
    /**
39
     * @var
40
     */
41
    public $enlisted;
42
43
    /**
44
     * @var
45
     */
46
    public $title;
47
48
    /**
49
     * @var
50
     */
51
    public $title_image;
52
53
    /**
54
     * @var
55
     */
56
    public $bio;
57
58
    /**
59
     * @var
60
     */
61
    public $website_link;
62
63
    /**
64
     * @var
65
     */
66
    public $website_title;
67
68
    /**
69
     * @var
70
     */
71
    public $country;
72
73
    /**
74
     * @var
75
     */
76
    public $region;
77
78
    /**
79
     * @var
80
     */
81
    public $fluenc;
82
83
    /**
84
     * @var
85
     */
86
    public $discussion_count;
87
88
    /**
89
     * @var
90
     */
91
    public $post_count;
92
93
    /**
94
     * @var
95
     */
96
    public $last_forum_visit;
97
98
    /**
99
     * @var
100
     */
101
    public $forum_roles;
102
103
    /**
104
     * @var
105
     */
106
    public $organizations;
107
108
    /**
109
     * @var
110
     */
111
    public $date_added;
112
113
    /**
114
     * @var
115
     */
116
    public $last_scrape_date;
117
118
119
    /**
120
     * @var Threads
121
     */
122
    protected $threads;
123
124
    /**
125
     * @var Posts
126
     */
127
    protected $posts;
128
129
    /**
130
     * Profile constructor.
131
     *
132
     * @param $profileData
133
     *
134
     * @return Profile
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
135
     */
136
    public function __construct($profileData)
137
    {
138
        foreach ($profileData as $key => $value) {
139
            $this->$key = $value;
140
        }
141
142
        return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
143
    }
144
145
    /**
146
     * @return bool|Threads|string
147
     */
148
    protected function threads()
149
    {
150
        if ($this->threads === null)
151
            $this->threads = Accounts::findThreads($this->handle);
0 ignored issues
show
Bug introduced by
The method findThreads() cannot be called from this context as it is declared protected in class StarCitizen\Accounts\Accounts.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
Documentation Bug introduced by
It seems like \StarCitizen\Accounts\Ac...dThreads($this->handle) can also be of type boolean or string. However, the property $threads is declared as type object<StarCitizen\Models\Threads>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
152
153
        return $this->threads;
154
    }
155
156
    /**
157
     * @return bool|Posts|string
158
     */
159
    protected function posts()
160
    {
161
        if ($this->posts === null)
162
            $this->posts = Accounts::findPosts($this->handle);
0 ignored issues
show
Bug introduced by
The method findPosts() cannot be called from this context as it is declared protected in class StarCitizen\Accounts\Accounts.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
Documentation Bug introduced by
It seems like \StarCitizen\Accounts\Ac...indPosts($this->handle) can also be of type boolean or string. However, the property $posts is declared as type object<StarCitizen\Models\Posts>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
163
164
        return $this->posts;
165
    }
166
167
    /**
168
     * @param array ...$types
169
     *
170
     * @return $this
171
     */
172
    public function with(...$types) {
173
        foreach ($types as $type) {
174
            if (method_exists($this, strtolower($type)))
175
                call_user_method($type, $this);
176
        }
177
178
        return $this;
179
    }
180
181
    /**
182
     * @param $name
183
     *
184
     * @return mixed|null
185
     */
186
    public function __get($name)
187
    {
188
        if ($name == "posts" || $name == "threads") {
189
            return call_user_method($name, $this);
190
        }
191
192
        return null;
193
    }
194
}