| Conditions | 5 |
| Paths | 16 |
| Total Lines | 303 |
| Code Lines | 192 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 23 | public function load(ObjectManager $manager): void |
||
| 24 | { |
||
| 25 | $sequenceRule = (new SequenceRule()) |
||
| 26 | ->setDescription( |
||
| 27 | 'If user completes 70% of an entity or group of items, he will be able to access another entity or group of items' |
||
| 28 | ) |
||
| 29 | ; |
||
| 30 | $manager->persist($sequenceRule); |
||
| 31 | |||
| 32 | $sequenceCondition1 = (new SequenceCondition()) |
||
| 33 | ->setDescription('<= 100%') |
||
| 34 | ->setMathOperation('<=') |
||
| 35 | ->setParam('100.0') |
||
| 36 | ->setActTrue('2') |
||
| 37 | ->setActFalse('0') |
||
| 38 | ; |
||
| 39 | $manager->persist($sequenceCondition1); |
||
| 40 | |||
| 41 | $sequenceCondition2 = (new SequenceCondition()) |
||
| 42 | ->setDescription('>= 70%') |
||
| 43 | ->setMathOperation('>=') |
||
| 44 | ->setParam('70.0') |
||
| 45 | ->setActTrue('0') |
||
| 46 | ->setActFalse('') |
||
| 47 | ; |
||
| 48 | $manager->persist($sequenceCondition2); |
||
| 49 | |||
| 50 | $sequenceRuleCondition1 = (new SequenceRuleCondition()) |
||
| 51 | ->setCondition($sequenceCondition1) |
||
| 52 | ->setRule($sequenceRule) |
||
| 53 | ; |
||
| 54 | $manager->persist($sequenceRuleCondition1); |
||
| 55 | |||
| 56 | $sequenceRuleCondition2 = (new SequenceRuleCondition()) |
||
| 57 | ->setCondition($sequenceCondition2) |
||
| 58 | ->setRule($sequenceRule) |
||
| 59 | ; |
||
| 60 | $manager->persist($sequenceRuleCondition2); |
||
| 61 | |||
| 62 | $list = [ |
||
| 63 | [ |
||
| 64 | 'description' => 'Add completed item', |
||
| 65 | 'formula' => 'v#2 + $complete_items;', |
||
| 66 | 'assign' => 2, |
||
| 67 | 'met_type' => 'add', |
||
| 68 | 'act_false' => '', |
||
| 69 | ], |
||
| 70 | [ |
||
| 71 | 'description' => 'Update progress by division', |
||
| 72 | 'formula' => 'v#2 / v#3 * 100;', |
||
| 73 | 'assign' => 1, |
||
| 74 | 'met_type' => 'div', |
||
| 75 | 'act_false' => '', |
||
| 76 | ], |
||
| 77 | [ |
||
| 78 | 'description' => 'Add completed item', |
||
| 79 | 'formula' => 'v#2 + $complete_items;', |
||
| 80 | 'assign' => 2, |
||
| 81 | 'met_type' => 'add', |
||
| 82 | 'act_false' => '', |
||
| 83 | ], |
||
| 84 | [ |
||
| 85 | 'description' => 'Update items count', |
||
| 86 | 'formula' => '$total_items;', |
||
| 87 | 'assign' => 3, |
||
| 88 | 'met_type' => 'update', |
||
| 89 | 'act_false' => '', |
||
| 90 | ], |
||
| 91 | [ |
||
| 92 | 'description' => 'Enable success', |
||
| 93 | 'formula' => '1;', |
||
| 94 | 'assign' => 4, |
||
| 95 | 'met_type' => 'success', |
||
| 96 | 'act_false' => '', |
||
| 97 | ], |
||
| 98 | [ |
||
| 99 | 'description' => 'Store success date', |
||
| 100 | 'formula' => '(empty(v#5))? api_get_utc_datetime() : v#5;', |
||
| 101 | 'assign' => 5, |
||
| 102 | 'met_type' => 'success', |
||
| 103 | 'act_false' => '', |
||
| 104 | ], |
||
| 105 | [ |
||
| 106 | 'description' => 'Enable availability', |
||
| 107 | 'formula' => '1;', |
||
| 108 | 'assign' => 6, |
||
| 109 | 'met_type' => 'pre', |
||
| 110 | 'act_false' => '', |
||
| 111 | ], |
||
| 112 | [ |
||
| 113 | 'description' => 'Store availability start date', |
||
| 114 | 'formula' => '(empty(v#7))? api_get_utc_datetime() : v#7;', |
||
| 115 | 'assign' => 7, |
||
| 116 | 'met_type' => 'pre', |
||
| 117 | 'act_false' => '', |
||
| 118 | ], |
||
| 119 | [ |
||
| 120 | 'description' => 'Store availability end date', |
||
| 121 | 'formula' => '(empty($available_end_date))? api_get_utc_datetime($available_end_date) : "0000-00-00 00:00:00";', |
||
| 122 | 'assign' => 8, |
||
| 123 | 'met_type' => 'pre', |
||
| 124 | 'act_false' => '', |
||
| 125 | ], |
||
| 126 | [ |
||
| 127 | 'description' => 'Increase the items count', |
||
| 128 | 'formula' => 'v#3 + $total_items;', |
||
| 129 | 'assign' => 3, |
||
| 130 | 'met_type' => 'add', |
||
| 131 | 'act_false' => '', |
||
| 132 | ], |
||
| 133 | [ |
||
| 134 | 'description' => 'Update completed items', |
||
| 135 | 'formula' => '$complete_items;', |
||
| 136 | 'assign' => 2, |
||
| 137 | 'met_type' => 'update', |
||
| 138 | 'act_false' => '', |
||
| 139 | ], |
||
| 140 | [ |
||
| 141 | 'description' => 'Update progress', |
||
| 142 | 'formula' => '$complete_items / $total_items * 100;', |
||
| 143 | 'assign' => 1, |
||
| 144 | 'met_type' => 'update', |
||
| 145 | 'act_false' => '', |
||
| 146 | ], |
||
| 147 | ]; |
||
| 148 | $methods = []; |
||
| 149 | foreach ($list as $key => $item) { |
||
| 150 | $sequenceMethod = (new SequenceMethod()) |
||
| 151 | ->setDescription($item['description']) |
||
| 152 | ->setFormula($item['formula']) |
||
| 153 | ->setAssign((string) $item['assign']) |
||
| 154 | ->setMetType($item['met_type']) |
||
| 155 | ->setActFalse($item['act_false']) |
||
| 156 | ; |
||
| 157 | $manager->persist($sequenceMethod); |
||
| 158 | |||
| 159 | $methods[] = $sequenceMethod; |
||
| 160 | |||
| 161 | $sequenceRuleMethod = (new SequenceRuleMethod()) |
||
| 162 | ->setRule($sequenceRule) |
||
| 163 | ->setMethod($sequenceMethod) |
||
| 164 | ->setMethodOrder((string) ($key + 1)) |
||
| 165 | ; |
||
| 166 | $manager->persist($sequenceRuleMethod); |
||
| 167 | } |
||
| 168 | |||
| 169 | $list = [ |
||
| 170 | [ |
||
| 171 | 'name' => 'Percentile progress', |
||
| 172 | 'description' => 'advance', |
||
| 173 | 'default_val' => '0.0', |
||
| 174 | ], |
||
| 175 | [ |
||
| 176 | 'name' => 'Completed items', |
||
| 177 | 'description' => 'complete_items', |
||
| 178 | 'default_val' => '0', |
||
| 179 | ], |
||
| 180 | [ |
||
| 181 | 'name' => 'Items count', |
||
| 182 | 'description' => 'total_items', |
||
| 183 | 'default_val' => '0', |
||
| 184 | ], |
||
| 185 | [ |
||
| 186 | 'name' => 'Completed', |
||
| 187 | 'description' => 'success', |
||
| 188 | 'default_val' => '0', |
||
| 189 | ], |
||
| 190 | [ |
||
| 191 | 'name' => 'Completion date', |
||
| 192 | 'description' => 'success_date', |
||
| 193 | 'default_val' => '0000-00-00 00:00:00', |
||
| 194 | ], |
||
| 195 | [ |
||
| 196 | 'name' => 'Available', |
||
| 197 | 'description' => 'available', |
||
| 198 | 'default_val' => '0', |
||
| 199 | ], |
||
| 200 | [ |
||
| 201 | 'name' => 'Availability start date', |
||
| 202 | 'description' => 'available_start_date', |
||
| 203 | 'default_val' => '0000-00-00 00:00:00', |
||
| 204 | ], |
||
| 205 | [ |
||
| 206 | 'name' => 'Availability end date', |
||
| 207 | 'description' => 'available_end_date', |
||
| 208 | 'default_val' => '0000-00-00 00:00:00', |
||
| 209 | ], |
||
| 210 | ]; |
||
| 211 | |||
| 212 | $variables = []; |
||
| 213 | foreach ($list as $item) { |
||
| 214 | $sequenceVariable = (new SequenceVariable()) |
||
| 215 | ->setName($item['name']) |
||
| 216 | ->setDescription($item['description']) |
||
| 217 | ->setDefaultValue($item['default_val']) |
||
| 218 | ; |
||
| 219 | $manager->persist($sequenceVariable); |
||
| 220 | $variables[] = $sequenceVariable; |
||
| 221 | } |
||
| 222 | |||
| 223 | $list = [ |
||
| 224 | [ |
||
| 225 | 'method' => 1, |
||
| 226 | 'variable' => 2, |
||
| 227 | ], |
||
| 228 | [ |
||
| 229 | 'method' => 2, |
||
| 230 | 'variable' => 2, |
||
| 231 | ], |
||
| 232 | [ |
||
| 233 | 'method' => 2, |
||
| 234 | 'variable' => 3, |
||
| 235 | ], |
||
| 236 | [ |
||
| 237 | 'method' => 2, |
||
| 238 | 'variable' => 1, |
||
| 239 | ], |
||
| 240 | [ |
||
| 241 | 'method' => 3, |
||
| 242 | 'variable' => 3, |
||
| 243 | ], |
||
| 244 | [ |
||
| 245 | 'method' => 4, |
||
| 246 | 'variable' => 4, |
||
| 247 | ], |
||
| 248 | [ |
||
| 249 | 'method' => 5, |
||
| 250 | 'variable' => 5, |
||
| 251 | ], |
||
| 252 | [ |
||
| 253 | 'method' => 6, |
||
| 254 | 'variable' => 6, |
||
| 255 | ], |
||
| 256 | [ |
||
| 257 | 'method' => 7, |
||
| 258 | 'variable' => 7, |
||
| 259 | ], |
||
| 260 | [ |
||
| 261 | 'method' => 8, |
||
| 262 | 'variable' => 8, |
||
| 263 | ], |
||
| 264 | [ |
||
| 265 | 'method' => 9, |
||
| 266 | 'variable' => 3, |
||
| 267 | ], |
||
| 268 | [ |
||
| 269 | 'method' => 10, |
||
| 270 | 'variable' => 2, |
||
| 271 | ], |
||
| 272 | [ |
||
| 273 | 'method' => 11, |
||
| 274 | 'variable' => 1, |
||
| 275 | ], |
||
| 276 | ]; |
||
| 277 | |||
| 278 | foreach ($list as $item) { |
||
| 279 | $sequenceFormula = (new SequenceFormula()) |
||
| 280 | ->setMethod($methods[$item['method'] - 1]) |
||
| 281 | ->setVariable($variables[$item['variable'] - 1]) |
||
| 282 | ; |
||
| 283 | $manager->persist($sequenceFormula); |
||
| 284 | } |
||
| 285 | |||
| 286 | $sequenceValid = (new SequenceValid()) |
||
| 287 | ->setVariable($variables[0]) |
||
| 288 | ->setCondition($sequenceCondition1) |
||
| 289 | ; |
||
| 290 | $manager->persist($sequenceValid); |
||
| 291 | |||
| 292 | $sequenceValid = (new SequenceValid()) |
||
| 293 | ->setVariable($variables[0]) |
||
| 294 | ->setCondition($sequenceCondition2) |
||
| 295 | ; |
||
| 296 | $manager->persist($sequenceValid); |
||
| 297 | |||
| 298 | $list = [ |
||
| 299 | [ |
||
| 300 | 'name' => 'Lp', |
||
| 301 | 'description' => 'Learning Path', |
||
| 302 | 'entity_table' => 'c_lp', |
||
| 303 | ], |
||
| 304 | [ |
||
| 305 | 'name' => 'Quiz', |
||
| 306 | 'description' => 'Quiz and Tests', |
||
| 307 | 'entity_table' => 'c_quiz', |
||
| 308 | ], |
||
| 309 | [ |
||
| 310 | 'name' => 'LpItem', |
||
| 311 | 'description' => 'Items of a Learning Path', |
||
| 312 | 'entity_table' => 'c_lp_item', |
||
| 313 | ], |
||
| 314 | ]; |
||
| 315 | |||
| 316 | foreach ($list as $item) { |
||
| 317 | $sequenceType = (new SequenceTypeEntity()) |
||
| 318 | ->setName($item['name']) |
||
| 319 | ->setDescription($item['description']) |
||
| 320 | ->setEntityTable($item['entity_table']) |
||
| 321 | ; |
||
| 322 | $manager->persist($sequenceType); |
||
| 323 | } |
||
| 324 | |||
| 325 | $manager->flush(); |
||
| 326 | } |
||
| 328 |