Conditions | 22 |
Paths | 280 |
Total Lines | 74 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
25 | private function element($objectType, $rowid){ |
||
26 | $element = null; |
||
27 | $subelement = null; |
||
28 | |||
29 | if ($objectType != 'supplier_proposal' && $objectType != 'order_supplier' && $objectType != 'invoice_supplier' |
||
30 | && preg_match('/^([^_]+)_([^_]+)/i', $objectType, $regs)) |
||
31 | { |
||
32 | $element = $regs[1]; |
||
33 | $subelement = $regs[2]; |
||
34 | } |
||
35 | |||
36 | $classpath = $element.'/class'; |
||
37 | |||
38 | if ($objectType == 'facture') { |
||
39 | $classpath = 'compta/facture/class'; |
||
40 | } |
||
41 | elseif ($objectType == 'facturerec') { |
||
42 | $classpath = 'compta/facture/class'; |
||
43 | } |
||
44 | elseif ($objectType == 'propal') { |
||
45 | $classpath = 'comm/propal/class'; |
||
46 | } |
||
47 | elseif ($objectType == 'supplier_proposal') { |
||
48 | $classpath = 'supplier_proposal/class'; |
||
49 | } |
||
50 | elseif ($objectType == 'shipping') { |
||
51 | $classpath = 'expedition/class'; $subelement = 'expedition'; |
||
52 | } |
||
53 | elseif ($objectType == 'delivery') { |
||
54 | $classpath = 'livraison/class'; $subelement = 'livraison'; |
||
55 | } |
||
56 | elseif ($objectType == 'invoice_supplier' || $objectType == 'order_supplier') { |
||
57 | $classpath = 'fourn/class'; |
||
58 | } |
||
59 | elseif ($objectType == 'fichinter') { |
||
60 | $classpath = 'fichinter/class'; $subelement = 'fichinter'; |
||
61 | } |
||
62 | elseif ($objectType == 'subscription') { |
||
63 | $classpath = 'adherents/class'; |
||
64 | } |
||
65 | |||
66 | // Set classfile |
||
67 | $classfile = strtolower($subelement); $classname = ucfirst($subelement); |
||
68 | |||
69 | if ($objectType == 'order') { |
||
70 | $classfile = 'commande'; $classname = 'Commande'; |
||
71 | } |
||
72 | elseif ($objectType == 'invoice_supplier') { |
||
73 | $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
||
74 | } |
||
75 | elseif ($objectType == 'order_supplier') { |
||
76 | $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
||
77 | } |
||
78 | elseif ($objectType == 'supplier_proposal') { |
||
79 | $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
||
80 | } |
||
81 | elseif ($objectType == 'facturerec') { |
||
82 | $classfile = 'facture-rec'; $classname = 'FactureRec'; |
||
83 | } |
||
84 | elseif ($objectType == 'subscription') { |
||
85 | $classfile = 'subscription'; $classname = 'Subscription'; |
||
86 | } |
||
87 | |||
88 | dol_include_once('/'.$classpath.'/'.$classfile.'.class.php'); |
||
89 | if (!class_exists($classname)) |
||
90 | { |
||
91 | return null; |
||
92 | } |
||
93 | |||
94 | $object = new $classname($this->db); |
||
95 | $object->fetch($rowid); |
||
96 | |||
97 | return $object; |
||
98 | } |
||
99 | |||
143 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: