Total Complexity | 42 |
Total Lines | 298 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Donor often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Donor, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | class Donor extends \EBloodBank\Models\Donor implements \Doctrine\ORM\Proxy\Proxy |
||
9 | { |
||
10 | /** |
||
11 | * @var \Closure the callback responsible for loading properties in the proxy object. This callback is called with |
||
12 | * three parameters, being respectively the proxy object to be initialized, the method that triggered the |
||
13 | * initialization process and an array of ordered parameters that were passed to that method. |
||
14 | * |
||
15 | * @see \Doctrine\Common\Persistence\Proxy::__setInitializer |
||
16 | */ |
||
17 | public $__initializer__; |
||
18 | |||
19 | /** |
||
20 | * @var \Closure the callback responsible of loading properties that need to be copied in the cloned object |
||
21 | * |
||
22 | * @see \Doctrine\Common\Persistence\Proxy::__setCloner |
||
23 | */ |
||
24 | public $__cloner__; |
||
25 | |||
26 | /** |
||
27 | * @var boolean flag indicating if this object was already initialized |
||
28 | * |
||
29 | * @see \Doctrine\Common\Persistence\Proxy::__isInitialized |
||
30 | */ |
||
31 | public $__isInitialized__ = false; |
||
32 | |||
33 | /** |
||
34 | * @var array properties to be lazy loaded, with keys being the property |
||
35 | * names and values being their default values |
||
36 | * |
||
37 | * @see \Doctrine\Common\Persistence\Proxy::__getLazyProperties |
||
38 | */ |
||
39 | public static $lazyPropertiesDefaults = []; |
||
40 | |||
41 | |||
42 | |||
43 | /** |
||
44 | * @param \Closure $initializer |
||
45 | * @param \Closure $cloner |
||
46 | */ |
||
47 | public function __construct($initializer = null, $cloner = null) |
||
48 | { |
||
49 | |||
50 | $this->__initializer__ = $initializer; |
||
51 | $this->__cloner__ = $cloner; |
||
52 | } |
||
53 | |||
54 | |||
55 | |||
56 | |||
57 | |||
58 | |||
59 | |||
60 | /** |
||
61 | * |
||
62 | * @return array |
||
63 | */ |
||
64 | public function __sleep() |
||
65 | { |
||
66 | if ($this->__isInitialized__) { |
||
67 | return ['__isInitialized__', 'id', 'name', 'gender', 'birthdate', 'blood_group', 'district', 'created_at', 'created_by', 'status', 'meta']; |
||
68 | } |
||
69 | |||
70 | return ['__isInitialized__', 'id', 'name', 'gender', 'birthdate', 'blood_group', 'district', 'created_at', 'created_by', 'status', 'meta']; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * |
||
75 | */ |
||
76 | public function __wakeup() |
||
77 | { |
||
78 | if ( ! $this->__isInitialized__) { |
||
79 | $this->__initializer__ = function (Donor $proxy) { |
||
80 | $proxy->__setInitializer(null); |
||
81 | $proxy->__setCloner(null); |
||
82 | |||
83 | $existingProperties = get_object_vars($proxy); |
||
84 | |||
85 | foreach ($proxy->__getLazyProperties() as $property => $defaultValue) { |
||
86 | if ( ! array_key_exists($property, $existingProperties)) { |
||
87 | $proxy->$property = $defaultValue; |
||
88 | } |
||
89 | } |
||
90 | }; |
||
91 | |||
92 | } |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * |
||
97 | */ |
||
98 | public function __clone() |
||
99 | { |
||
100 | $this->__cloner__ && $this->__cloner__->__invoke($this, '__clone', []); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Forces initialization of the proxy |
||
105 | */ |
||
106 | public function __load() |
||
107 | { |
||
108 | $this->__initializer__ && $this->__initializer__->__invoke($this, '__load', []); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * {@inheritDoc} |
||
113 | * @internal generated method: use only when explicitly handling proxy specific loading logic |
||
114 | */ |
||
115 | public function __isInitialized() |
||
116 | { |
||
117 | return $this->__isInitialized__; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * {@inheritDoc} |
||
122 | * @internal generated method: use only when explicitly handling proxy specific loading logic |
||
123 | */ |
||
124 | public function __setInitialized($initialized) |
||
125 | { |
||
126 | $this->__isInitialized__ = $initialized; |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * {@inheritDoc} |
||
131 | * @internal generated method: use only when explicitly handling proxy specific loading logic |
||
132 | */ |
||
133 | public function __setInitializer(\Closure $initializer = null) |
||
134 | { |
||
135 | $this->__initializer__ = $initializer; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * {@inheritDoc} |
||
140 | * @internal generated method: use only when explicitly handling proxy specific loading logic |
||
141 | */ |
||
142 | public function __getInitializer() |
||
143 | { |
||
144 | return $this->__initializer__; |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * {@inheritDoc} |
||
149 | * @internal generated method: use only when explicitly handling proxy specific loading logic |
||
150 | */ |
||
151 | public function __setCloner(\Closure $cloner = null) |
||
152 | { |
||
153 | $this->__cloner__ = $cloner; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * {@inheritDoc} |
||
158 | * @internal generated method: use only when explicitly handling proxy specific cloning logic |
||
159 | */ |
||
160 | public function __getCloner() |
||
161 | { |
||
162 | return $this->__cloner__; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * {@inheritDoc} |
||
167 | * @internal generated method: use only when explicitly handling proxy specific loading logic |
||
168 | * @static |
||
169 | */ |
||
170 | public function __getLazyProperties() |
||
171 | { |
||
172 | return self::$lazyPropertiesDefaults; |
||
173 | } |
||
174 | |||
175 | |||
176 | /** |
||
177 | * {@inheritDoc} |
||
178 | */ |
||
179 | public function isExists() |
||
180 | { |
||
181 | |||
182 | $this->__initializer__ && $this->__initializer__->__invoke($this, 'isExists', []); |
||
183 | |||
184 | return parent::isExists(); |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * {@inheritDoc} |
||
189 | */ |
||
190 | public function isPending() |
||
191 | { |
||
192 | |||
193 | $this->__initializer__ && $this->__initializer__->__invoke($this, 'isPending', []); |
||
194 | |||
195 | return parent::isPending(); |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * {@inheritDoc} |
||
200 | */ |
||
201 | public function isApproved() |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * {@inheritDoc} |
||
211 | */ |
||
212 | public function getGenderTitle() |
||
213 | { |
||
214 | |||
215 | $this->__initializer__ && $this->__initializer__->__invoke($this, 'getGenderTitle', []); |
||
216 | |||
217 | return parent::getGenderTitle(); |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * {@inheritDoc} |
||
222 | */ |
||
223 | public function getAge($format = '%y') |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * {@inheritDoc} |
||
233 | */ |
||
234 | public function doActionOnPrePersist() |
||
235 | { |
||
236 | |||
237 | $this->__initializer__ && $this->__initializer__->__invoke($this, 'doActionOnPrePersist', []); |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * {@inheritDoc} |
||
244 | */ |
||
245 | public function get($key) |
||
246 | { |
||
247 | |||
248 | $this->__initializer__ && $this->__initializer__->__invoke($this, 'get', [$key]); |
||
249 | |||
250 | return parent::get($key); |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * {@inheritDoc} |
||
255 | */ |
||
256 | public function display($key, $format = 'html') |
||
257 | { |
||
258 | |||
259 | $this->__initializer__ && $this->__initializer__->__invoke($this, 'display', [$key, $format]); |
||
260 | |||
261 | return parent::display($key, $format); |
||
262 | } |
||
263 | |||
264 | /** |
||
265 | * {@inheritDoc} |
||
266 | */ |
||
267 | public function set($key, $value, $sanitize = false, $validate = true) |
||
268 | { |
||
269 | |||
270 | $this->__initializer__ && $this->__initializer__->__invoke($this, 'set', [$key, $value, $sanitize, $validate]); |
||
271 | |||
272 | return parent::set($key, $value, $sanitize, $validate); |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * {@inheritDoc} |
||
277 | */ |
||
278 | public function getMeta(string $key, $fallback = '') |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * {@inheritDoc} |
||
288 | */ |
||
289 | public function setMeta(string $key, $value, $sanitize = false, $validate = true) |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * {@inheritDoc} |
||
299 | */ |
||
300 | public function deleteMeta(string $key) |
||
306 | } |
||
307 | |||
309 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.