1 | <?php |
||
14 | abstract class LazyResource extends Model |
||
15 | { |
||
16 | /** |
||
17 | * This class is a ghost object that lazy loads the full record only when needed. |
||
18 | * If $initialized is false, it means we haven't yet loaded the full record. |
||
19 | * We can still have incomplete data from a search response. |
||
20 | */ |
||
21 | protected $initialized = false; |
||
22 | |||
23 | /** |
||
24 | * @var array Query string parameters |
||
25 | */ |
||
26 | protected $params = []; |
||
27 | |||
28 | /** |
||
29 | * Set request query string parameters. |
||
30 | * |
||
31 | * @param $params array |
||
32 | * |
||
33 | * @return $this |
||
34 | */ |
||
35 | public function setParams($params) |
||
41 | |||
42 | /** |
||
43 | * Get the request query string parameters. |
||
44 | * |
||
45 | * @return array |
||
46 | */ |
||
47 | public function getParams() |
||
51 | |||
52 | /** |
||
53 | * Check if we have the full representation of our data object. |
||
54 | * |
||
55 | * @param \stdClass $data |
||
56 | * |
||
57 | * @return bool |
||
58 | */ |
||
59 | abstract protected function isInitialized($data); |
||
60 | |||
61 | /** |
||
62 | * Load data onto this object. Chainable method. |
||
63 | * |
||
64 | * @param \stdClass|QuiteSimpleXMLElement $data |
||
65 | * |
||
66 | * @return $this |
||
67 | */ |
||
68 | public function init($data = null) |
||
89 | |||
90 | /** |
||
91 | * Get and return the model data. |
||
92 | * |
||
93 | * @return object |
||
94 | */ |
||
95 | protected function fetchData() |
||
99 | |||
100 | /** |
||
101 | * Called when data is available on the object. |
||
102 | * The resource classes can use this method to process the data. |
||
103 | * |
||
104 | * @param mixed $data |
||
105 | */ |
||
106 | protected function onData($data) |
||
109 | |||
110 | /** |
||
111 | * Get the raw data object. |
||
112 | */ |
||
113 | public function getData() |
||
117 | |||
118 | /** |
||
119 | * Check if the object exists. |
||
120 | */ |
||
121 | public function exists() |
||
130 | |||
131 | /** |
||
132 | * Generate the base URL for this resource. |
||
133 | * |
||
134 | * @return string |
||
135 | */ |
||
136 | abstract protected function urlBase(); |
||
137 | |||
138 | /** |
||
139 | * Build a relative URL for a resource. |
||
140 | * |
||
141 | * @param string $path |
||
142 | * @param array $query |
||
143 | * |
||
144 | * @return string |
||
145 | */ |
||
146 | protected function url($path = '', $query = []) |
||
158 | } |
||
159 |
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 theid
property of an instance of theAccount
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.