Complex classes like FlexiBeeRW 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 FlexiBeeRW, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class FlexiBeeRW extends FlexiBeeRO |
||
17 | { |
||
18 | /** |
||
19 | * Sloupeček obsahující datum vložení záznamu do shopu. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | public $myCreateColumn = 'false'; |
||
24 | |||
25 | /** |
||
26 | * Slopecek obsahujici datum poslení modifikace záznamu do shopu. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | public $myLastModifiedColumn = 'lastUpdate'; |
||
31 | |||
32 | /** |
||
33 | * Last Inserted ID. |
||
34 | * |
||
35 | * @var int |
||
36 | */ |
||
37 | public $lastInsertedID = null; |
||
38 | |||
39 | /** |
||
40 | * Array of fields for next curl POST operation |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | public $postFields = null; |
||
45 | |||
46 | /** |
||
47 | * Transaction processing mode |
||
48 | * |
||
49 | * @link https://www.flexibee.eu/api/dokumentace/ref/tx/ Transakční zpracování |
||
50 | * @var boolean |
||
51 | */ |
||
52 | public $atomic = null; |
||
53 | |||
54 | /** |
||
55 | * Record Copy helper |
||
56 | * |
||
57 | * @var int |
||
58 | */ |
||
59 | private $sourceId = null; |
||
60 | |||
61 | |||
62 | /** |
||
63 | * SetUp Object to be ready for work |
||
64 | * |
||
65 | * @param array $options Object Options (authSessionId,user,password, |
||
66 | * url,company,evidence,companyUrl |
||
67 | * prefix,defaultUrlParams,debug,ver |
||
68 | * detail,offline,atomic,filter,ignore404 |
||
69 | */ |
||
70 | public function setUp($options = array()) |
||
77 | |||
78 | /** |
||
79 | * Save record (if evidence allow to). |
||
80 | * Uloží záznam (pokud to evidence dovoluje) |
||
81 | * |
||
82 | * @param array $data Data to save |
||
83 | * @throws Exception Evidence does not support Import |
||
84 | * |
||
85 | * @return array odpověď |
||
86 | */ |
||
87 | public function insertToFlexiBee($data = null) |
||
96 | |||
97 | /** |
||
98 | * Parse Response array |
||
99 | * |
||
100 | * @param array $responseDecoded |
||
101 | * @param int $responseCode Request Response Code |
||
102 | * |
||
103 | * @return array main data part of response |
||
104 | */ |
||
105 | public function parseResponse($responseDecoded, $responseCode) |
||
129 | |||
130 | /** |
||
131 | * Assign result IDs to its source objects |
||
132 | * |
||
133 | * @param array $candidates FlexiBee insert IDs prepared by extractResultIDs() |
||
134 | */ |
||
135 | public function assignResultIDs($candidates) |
||
158 | |||
159 | /** |
||
160 | * Extract IDs from FlexiBee response Array |
||
161 | * |
||
162 | * @param array $resultInfo FlexiBee response |
||
163 | * |
||
164 | * @return array List of [ 'evidence1'=>[ 'original-id'=>numericID,'original-id2'=>numericID2 ], 'evidence2'=> ... ] |
||
165 | */ |
||
166 | public function extractResultIDs($resultInfo) |
||
181 | |||
182 | /** |
||
183 | * Give you last inserted record ID. |
||
184 | * |
||
185 | * @return int |
||
186 | */ |
||
187 | public function getLastInsertedId() |
||
191 | |||
192 | /** |
||
193 | * Smaže záznam |
||
194 | * Delete record in FlexiBee |
||
195 | * |
||
196 | * @param int|string $id identifikátor záznamu |
||
197 | * |
||
198 | * @return boolean Response code is 200 ? |
||
199 | */ |
||
200 | public function deleteFromFlexiBee($id = null) |
||
210 | |||
211 | /** |
||
212 | * Control for existing column names in evidence and take data |
||
213 | * |
||
214 | * @param array $data Data to keep |
||
215 | * |
||
216 | * @return int number of records taken |
||
217 | */ |
||
218 | public function takeData($data) |
||
247 | |||
248 | /** |
||
249 | * Control data for mandatory columns presence. |
||
250 | * |
||
251 | * @deprecated since version 1.8.7 |
||
252 | * |
||
253 | * @param array $data |
||
254 | * |
||
255 | * @return array List of missing columns. Empty if all is ok |
||
256 | */ |
||
257 | public function controlMandatoryColumns($data = null) |
||
276 | |||
277 | /** |
||
278 | * Control data for readonly columns presence. |
||
279 | * |
||
280 | * @param array $data |
||
281 | * |
||
282 | * @return array List of ReadOnly columns. Empty if all is ok |
||
283 | */ |
||
284 | public function controlReadOnlyColumns($data = null) |
||
303 | |||
304 | /** |
||
305 | * Convert Timestamp to FlexiBee Date format. |
||
306 | * |
||
307 | * @param int $timpestamp |
||
308 | * |
||
309 | * @return string FlexiBee Date or NULL |
||
310 | */ |
||
311 | public static function timestampToFlexiDate($timpestamp = null) |
||
321 | |||
322 | /** |
||
323 | * Convert Timestamp to Flexi DateTime format. |
||
324 | * |
||
325 | * @param int $timpestamp |
||
326 | * |
||
327 | * @return string FlexiBee DateTime or NULL |
||
328 | */ |
||
329 | public static function timestampToFlexiDateTime($timpestamp = null) |
||
339 | |||
340 | /** |
||
341 | * Add Data to evidence Branch |
||
342 | * Přidá data do větve |
||
343 | * |
||
344 | * @thanksto Karel Běl |
||
345 | * |
||
346 | * @see Relations |
||
347 | * |
||
348 | * @param array $data pole dat |
||
349 | * @param string $relationPath path evidence (relation) pro vkládaná data |
||
350 | * @param boolean $removeAll |
||
351 | * |
||
352 | * @return boolean Operation success |
||
353 | */ |
||
354 | public function addArrayToBranch($data, $relationPath = 'polozkyDokladu', |
||
369 | |||
370 | /** |
||
371 | * Vloží do větve data z objektu |
||
372 | * |
||
373 | * @param FlexiBeeRO $object objekt evidence |
||
374 | * @param boolean $removeAll flush older items |
||
375 | */ |
||
376 | public function addObjectToBranch($object, $removeAll = false) |
||
381 | |||
382 | /** |
||
383 | * Přidá uživatelskou vazbu |
||
384 | * |
||
385 | * @see https://www.flexibee.eu/api/dokumentace/ref/uzivatelske-vazby/ |
||
386 | * @param string $vazba |
||
387 | */ |
||
388 | public function vazbaAdd($vazba) |
||
393 | |||
394 | /** |
||
395 | * Smaže uživatelskou vazbu |
||
396 | * |
||
397 | * @see https://www.flexibee.eu/api/dokumentace/ref/uzivatelske-vazby/ |
||
398 | * @param string $vazba |
||
399 | */ |
||
400 | public function vazbaDel($vazba) |
||
406 | |||
407 | /** |
||
408 | * Převede data do Json formátu pro FlexiBee. |
||
409 | * Pokud jsou štítky pole, jsou převedeny na seznam oddělený čárkou. |
||
410 | * Convert data to FlexiBee like Json format. |
||
411 | * Array of Labels is converted to coma separated list |
||
412 | * |
||
413 | * @param array $data |
||
414 | * @param int $options json_encode options like JSON_PRETTY_PRINT etc |
||
415 | * |
||
416 | * @return string |
||
417 | */ |
||
418 | public function getJsonizedData($data = null, $options = 0) |
||
432 | |||
433 | /** |
||
434 | * Get Data Fragment specific for current object |
||
435 | * |
||
436 | * @param array $data |
||
437 | * |
||
438 | * @return array |
||
439 | */ |
||
440 | public function getDataForJSON($data = null) |
||
455 | |||
456 | /** |
||
457 | * Insert current data into FlexiBee and load actual record data back |
||
458 | * |
||
459 | * @param array $data Initial data to save |
||
460 | * |
||
461 | * @return boolean Operation success |
||
462 | */ |
||
463 | public function sync($data = null) |
||
473 | |||
474 | /** |
||
475 | * Make Copy of given record with optional modifiactions |
||
476 | * |
||
477 | * !!!Experimental Feature!!! |
||
478 | * |
||
479 | * @param int $source |
||
480 | * @param array $overrides |
||
481 | * |
||
482 | * @return FlexiBeeRW|null copied record object or null in case of failure |
||
483 | */ |
||
484 | public function copy($source, $overrides = []) |
||
489 | |||
490 | /** |
||
491 | * Perform given action (if availble) on current evidence/record |
||
492 | * @url https://demo.flexibee.eu/devdoc/actions |
||
493 | * |
||
494 | * @param string $action one of evidence actions |
||
495 | * @param string $method ext|int External method call operation in URL. |
||
496 | * Internal add the @action element to request body |
||
497 | * |
||
498 | * @return boolean operation success |
||
499 | */ |
||
500 | public function performAction($action, $method = 'int') |
||
537 | |||
538 | /** |
||
539 | * Add External ID to Current Record |
||
540 | * |
||
541 | * @param string $extId ext:whatever:123 or simplay whatever:123 |
||
542 | * |
||
543 | * @return array Insert result |
||
544 | */ |
||
545 | public function addExternalID($extId) |
||
550 | |||
551 | /** |
||
552 | * Change Value of external id identified by selector. Add new if not exists |
||
553 | * |
||
554 | * @param string $selector ext:$selector:$newValue |
||
555 | * @param string|int $newValue string or number |
||
556 | * @param string|int $forID Other than current record id |
||
557 | * |
||
558 | * @return array operation result |
||
559 | */ |
||
560 | public function changeExternalID($selector, $newValue, $forID = null) |
||
567 | |||
568 | /** |
||
569 | * Send all unsent Documents by eMail |
||
570 | * |
||
571 | * @url https://www.flexibee.eu/api/dokumentace/ref/odesilani-mailem/ |
||
572 | * |
||
573 | * @return int http response code |
||
574 | */ |
||
575 | public function sendUnsent() { |
||
579 | |||
580 | } |
||
581 |
Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.
To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.
The function can be called with either null or an array for the parameter
$needle
but will only accept an array as$haystack
.