| Conditions | 19 | 
| Paths | 904 | 
| Total Lines | 137 | 
| Code Lines | 97 | 
| Lines | 44 | 
| Ratio | 32.12 % | 
| 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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php  | 
            ||
| 237 | public function generateDao($fields, $namespace, $className, $daoClassName, $moduleName, $targetDirectory, $moduleSingular, $modulePlural)  | 
            ||
| 238 |     { | 
            ||
| 239 |         //        if (class_exists($namespace."\\".$className)) { | 
            ||
| 240 | // $class = PhpClass::fromReflection(new \ReflectionClass($namespace."\\".$daoClassName));  | 
            ||
| 241 | //        } else { | 
            ||
| 242 | $class = PhpClass::create();  | 
            ||
| 243 | // }  | 
            ||
| 244 | |||
| 245 | $class->setName($daoClassName)  | 
            ||
| 246 | ->setNamespace($namespace)  | 
            ||
| 247 |             ->setParentClassName('\\Wabel\\Zoho\\CRM\\AbstractZohoDao'); | 
            ||
| 248 | |||
| 249 | $usedIdentifiers = [];  | 
            ||
| 250 | |||
| 251 |         foreach ($fields as $key => $fieldCategory) { | 
            ||
| 252 |             foreach ($fieldCategory as $name => $field) { | 
            ||
| 253 | $type = $field['type'];  | 
            ||
| 254 | |||
| 255 | View Code Duplication |                 switch ($type) { | 
            |
| 256 | case 'DateTime':  | 
            ||
| 257 | case 'Date':  | 
            ||
| 258 | $phpType = '\\DateTime';  | 
            ||
| 259 | break;  | 
            ||
| 260 | case 'Boolean':  | 
            ||
| 261 | $phpType = 'bool';  | 
            ||
| 262 | break;  | 
            ||
| 263 | case 'Integer':  | 
            ||
| 264 | $phpType = 'int';  | 
            ||
| 265 | break;  | 
            ||
| 266 | default:  | 
            ||
| 267 | $phpType = 'string';  | 
            ||
| 268 | break;  | 
            ||
| 269 | }  | 
            ||
| 270 | |||
| 271 | $fields[$key][$name]['phpType'] = $phpType;  | 
            ||
| 272 | $identifier = $this->getUniqueIdentifier($name, $usedIdentifiers);  | 
            ||
| 273 | $usedIdentifiers[$identifier] = true;  | 
            ||
| 274 | $fields[$key][$name]['getter'] = 'get'.ucfirst($identifier);  | 
            ||
| 275 | $fields[$key][$name]['setter'] = 'set'.ucfirst($identifier);  | 
            ||
| 276 | $fields[$key][$name]['name'] = $identifier;  | 
            ||
| 277 | |||
| 278 | |||
| 279 | //Detect Special Fields from Zoho - Using API, you cannot create or update these system-generated fields:  | 
            ||
| 280 | //@Todo: Manage these fields. The problem comes "MODIFIEDBY" and "Modified By" fields  | 
            ||
| 281 | $specialOwnerFieldsMapping = [  | 
            ||
| 282 | 'Created By' => 'SMCREATORID',  | 
            ||
| 283 | 'Modified By' =>'MODIFIEDBY',  | 
            ||
| 284 | ];  | 
            ||
| 285 | $specialDateFieldsMapping = [  | 
            ||
| 286 | 'Created Time' => 'createdTime',  | 
            ||
| 287 | 'Modified Time' =>'modifiedTime'  | 
            ||
| 288 | ];  | 
            ||
| 289 | $linkedSystemGeneratedFields = [  | 
            ||
| 290 | 'Created By' => 'Created Time',  | 
            ||
| 291 | 'Modified By' =>'Modified Time',  | 
            ||
| 292 | ];  | 
            ||
| 293 | $systemGenerated = false;  | 
            ||
| 294 |                 if(array_key_exists($field['label'],$specialOwnerFieldsMapping)){ | 
            ||
| 295 | $systemGenerated = true;  | 
            ||
| 296 | }  | 
            ||
| 297 |                 if($systemGenerated && isset($linkedSystemGeneratedFields[$field['label']])){ | 
            ||
| 298 | $dateSpecialField = false;  | 
            ||
| 299 |                     if (isset($specialDateFieldsMapping[$linkedSystemGeneratedFields[$field['label']]])) { | 
            ||
| 300 | $name = $specialDateFieldsMapping[$linkedSystemGeneratedFields[$field['label']]];  | 
            ||
| 301 | $generateId = true;  | 
            ||
| 302 | $dateSpecialField = true;  | 
            ||
| 303 | }  | 
            ||
| 304 | View Code Duplication |                     if ($generateId && $dateSpecialField) { | 
            |
| 305 | $fields[$key][$name]['req'] = false;  | 
            ||
| 306 | $fields[$key][$name]['type'] = 'Date';  | 
            ||
| 307 | $fields[$key][$name]['isreadonly'] = false;  | 
            ||
| 308 | $fields[$key][$name]['maxlength'] = 20;  | 
            ||
| 309 | $fields[$key][$name]['label'] = $name;  | 
            ||
| 310 | $fields[$key][$name]['dv'] = $name;  | 
            ||
| 311 | $fields[$key][$name]['customfield'] = true;  | 
            ||
| 312 | $fields[$key][$name]['phpType'] = '\\DateTime';  | 
            ||
| 313 | $fields[$key][$name]['getter'] = 'get'.ucfirst(self::camelCase($name));  | 
            ||
| 314 | $fields[$key][$name]['setter'] = 'set'.ucfirst(self::camelCase($name));  | 
            ||
| 315 | $fields[$key][$name]['name'] = self::camelCase($name);  | 
            ||
| 316 | }  | 
            ||
| 317 | }  | 
            ||
| 318 |                 if ($type === 'Lookup') { | 
            ||
| 319 | $generateId = false;  | 
            ||
| 320 | |||
| 321 |                     if ($field['customfield']) { | 
            ||
| 322 | $name .= '_ID';  | 
            ||
| 323 | $generateId = true;  | 
            ||
| 324 |                     } elseif ($field['label'] === $moduleSingular.' Owner') { | 
            ||
| 325 | // Check if this is a "owner" field.  | 
            ||
| 326 | $name = 'SMOWNERID';  | 
            ||
| 327 | $generateId = true;  | 
            ||
| 328 |                     } else { | 
            ||
| 329 | $mapping = [  | 
            ||
| 330 | 'Account Name' => 'ACCOUNTID',  | 
            ||
| 331 | 'Contact Name' => 'CONTACTID',  | 
            ||
| 332 | 'Parent Account' => 'PARENTACCOUNTID',  | 
            ||
| 333 | 'Campaign Source' => 'CAMPAIGNID',  | 
            ||
| 334 | ];  | 
            ||
| 335 |                         if (isset($mapping[$field['label']])) { | 
            ||
| 336 | $name = $mapping[$field['label']];  | 
            ||
| 337 | $generateId = true;  | 
            ||
| 338 | }  | 
            ||
| 339 | }  | 
            ||
| 340 | View Code Duplication |                     if ($generateId) { | 
            |
| 341 | $fields[$key][$name]['req'] = false;  | 
            ||
| 342 | $fields[$key][$name]['type'] = 'Lookup ID';  | 
            ||
| 343 | $fields[$key][$name]['isreadonly'] = true;  | 
            ||
| 344 | $fields[$key][$name]['maxlength'] = 100;  | 
            ||
| 345 | $fields[$key][$name]['label'] = $name;  | 
            ||
| 346 | $fields[$key][$name]['dv'] = $name;  | 
            ||
| 347 | $fields[$key][$name]['customfield'] = true;  | 
            ||
| 348 | $fields[$key][$name]['phpType'] = $phpType;  | 
            ||
| 349 | $fields[$key][$name]['getter'] = 'get'.ucfirst(self::camelCase($name));  | 
            ||
| 350 | $fields[$key][$name]['setter'] = 'set'.ucfirst(self::camelCase($name));  | 
            ||
| 351 | $fields[$key][$name]['name'] = self::camelCase($name);  | 
            ||
| 352 | }  | 
            ||
| 353 | }  | 
            ||
| 354 | }  | 
            ||
| 355 | }  | 
            ||
| 356 | |||
| 357 |         $class->setMethod(PhpMethod::create('getModule')->setBody('return '.var_export($moduleName, true).';')); | 
            ||
| 358 | |||
| 359 |         $class->setMethod(PhpMethod::create('getSingularModuleName')->setBody('return '.var_export($moduleSingular, true).';')); | 
            ||
| 360 | |||
| 361 |         $class->setMethod(PhpMethod::create('getPluralModuleName')->setBody('return '.var_export($modulePlural, true).';')); | 
            ||
| 362 | |||
| 363 |         $class->setMethod(PhpMethod::create('getFields')->setBody('return '.var_export($fields, true).';')); | 
            ||
| 364 | |||
| 365 |         $class->setMethod(PhpMethod::create('getBeanClassName')->setBody('return '.var_export($namespace.'\\'.$className, true).';')); | 
            ||
| 366 | |||
| 367 | $generator = new CodeFileGenerator();  | 
            ||
| 368 | $code = $generator->generate($class);  | 
            ||
| 369 | |||
| 370 | View Code Duplication |         if (!file_put_contents(rtrim($targetDirectory, '/').'/'.$daoClassName.'.php', $code)) { | 
            |
| 371 |             throw new ZohoCRMException("An error occurred while creating the DAO $daoClassName. Please verify the target directory exists or the rights of the file."); | 
            ||
| 372 | }  | 
            ||
| 373 | }  | 
            ||
| 374 | |||
| 444 | 
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.