| Conditions | 25 | 
| Paths | 74 | 
| Total Lines | 128 | 
| Code Lines | 81 | 
| Lines | 66 | 
| Ratio | 51.56 % | 
| Changes | 3 | ||
| 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  | 
            ||
| 327 | public function getIndexMetadata()  | 
            ||
| 328 |     { | 
            ||
| 329 |         if (null !== $this->indexMetadata) { | 
            ||
| 330 | return $this->indexMetadata;  | 
            ||
| 331 | }  | 
            ||
| 332 | $metadata = $this->getModuleOptions()->getWorkflowEntryToObjectMetadata();  | 
            ||
| 333 | |||
| 334 | $index = [];  | 
            ||
| 335 |         foreach ($metadata as $metadataItem) { | 
            ||
| 336 | View Code Duplication |             if (!array_key_exists(static::WORKFLOW_MANAGER_NAME, $metadataItem) && !array_key_exists(static::WORKFLOW_MANAGER_ALIAS, $metadataItem)) { | 
            |
| 
                                                                                                    
                        
                         | 
                |||
| 337 | $errMsg = sprintf(  | 
            ||
| 338 | 'You must specify the %s or %s',  | 
            ||
| 339 | static::WORKFLOW_MANAGER_NAME,  | 
            ||
| 340 | static::WORKFLOW_MANAGER_ALIAS  | 
            ||
| 341 | );  | 
            ||
| 342 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 343 | }  | 
            ||
| 344 | |||
| 345 | View Code Duplication |             if (array_key_exists(static::WORKFLOW_MANAGER_NAME, $metadataItem) && array_key_exists(static::WORKFLOW_MANAGER_ALIAS, $metadataItem)) { | 
            |
| 346 | $errMsg = sprintf(  | 
            ||
| 347 | 'You can not specify both %s and %s',  | 
            ||
| 348 | static::WORKFLOW_MANAGER_NAME,  | 
            ||
| 349 | static::WORKFLOW_MANAGER_ALIAS  | 
            ||
| 350 | );  | 
            ||
| 351 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 352 | }  | 
            ||
| 353 | |||
| 354 | View Code Duplication |             if (!array_key_exists(static::WORKFLOW_NAME, $metadataItem)) { | 
            |
| 355 |                 $errMsg = sprintf('there is no option %s', static::WORKFLOW_NAME); | 
            ||
| 356 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 357 | }  | 
            ||
| 358 | $workflowName = $metadataItem[static::WORKFLOW_NAME];  | 
            ||
| 359 | |||
| 360 | View Code Duplication |             if (!array_key_exists(static::ROUTER_NAME, $metadataItem)) { | 
            |
| 361 |                 $errMsg = sprintf('there is no option %s', static::ROUTER_NAME); | 
            ||
| 362 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 363 | }  | 
            ||
| 364 | $routerName = $metadataItem[static::ROUTER_NAME];  | 
            ||
| 365 | |||
| 366 | $prefix = '';  | 
            ||
| 367 | View Code Duplication |             if (array_key_exists(static::WORKFLOW_MANAGER_NAME, $metadataItem)) { | 
            |
| 368 | $prefix = 'name_' . $metadataItem[static::WORKFLOW_MANAGER_NAME] . '_';  | 
            ||
| 369 | }  | 
            ||
| 370 | |||
| 371 | View Code Duplication |             if (array_key_exists(static::WORKFLOW_MANAGER_ALIAS, $metadataItem)) { | 
            |
| 372 | $prefix = 'alias_' . $metadataItem[static::WORKFLOW_MANAGER_ALIAS] . '_';  | 
            ||
| 373 | }  | 
            ||
| 374 | |||
| 375 | $uniqueKey = $prefix . $workflowName . '_' . $routerName;  | 
            ||
| 376 | |||
| 377 |             if (array_key_exists($uniqueKey, $index)) { | 
            ||
| 378 |                 $errMsg = sprintf('Index contains duplicate keys %s', $uniqueKey); | 
            ||
| 379 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 380 | }  | 
            ||
| 381 | |||
| 382 | $index[$uniqueKey] = [];  | 
            ||
| 383 | |||
| 384 | |||
| 385 | View Code Duplication |             if (!array_key_exists(static::MAP, $metadataItem)) { | 
            |
| 386 |                 $errMsg = sprintf('there is no option %s', static::MAP); | 
            ||
| 387 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 388 | }  | 
            ||
| 389 | View Code Duplication |             if (!is_array($metadataItem[static::MAP])) { | 
            |
| 390 |                 $errMsg = sprintf('option %s is not array', static::MAP); | 
            ||
| 391 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 392 | }  | 
            ||
| 393 | $map = $metadataItem[static::MAP];  | 
            ||
| 394 | |||
| 395 |             foreach ($map as $mapItem) { | 
            ||
| 396 | View Code Duplication |                 if (!array_key_exists(static::ENTITY_CLASS_NAME, $mapItem)) { | 
            |
| 397 |                     $errMsg = sprintf('there is no option %s', static::ENTITY_CLASS_NAME); | 
            ||
| 398 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 399 | }  | 
            ||
| 400 | $entityClassName = $mapItem[static::ENTITY_CLASS_NAME];  | 
            ||
| 401 | |||
| 402 | View Code Duplication |                 if (array_key_exists($entityClassName, $index[$uniqueKey])) { | 
            |
| 403 |                     $errMsg = sprintf('Metadata for entities already exist %s', $mapItem[static::ENTITY_CLASS_NAME]); | 
            ||
| 404 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 405 | }  | 
            ||
| 406 | $index[$uniqueKey][$entityClassName] = [];  | 
            ||
| 407 | |||
| 408 | View Code Duplication |                 if (!array_key_exists(static::IDENTIFIERS_MAP, $mapItem)) { | 
            |
| 409 |                     $errMsg = sprintf('there is no option %s', static::IDENTIFIERS_MAP); | 
            ||
| 410 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 411 | }  | 
            ||
| 412 | View Code Duplication |                 if (!is_array($mapItem[static::IDENTIFIERS_MAP])) { | 
            |
| 413 |                     $errMsg = sprintf('option %s is not array', static::IDENTIFIERS_MAP); | 
            ||
| 414 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 415 | }  | 
            ||
| 416 | |||
| 417 | $identifiersMap = $mapItem[static::IDENTIFIERS_MAP];  | 
            ||
| 418 | |||
| 419 |                 foreach ($identifiersMap as $identifierItem) { | 
            ||
| 420 | View Code Duplication |                     if (!array_key_exists(static::PROPERTY_NAME, $identifierItem)) { | 
            |
| 421 |                         $errMsg = sprintf('there is no option %s', static::PROPERTY_NAME); | 
            ||
| 422 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 423 | }  | 
            ||
| 424 | $propertyName = $identifierItem[static::PROPERTY_NAME];  | 
            ||
| 425 | |||
| 426 | View Code Duplication |                     if (array_key_exists($propertyName, $index[$uniqueKey][$entityClassName])) { | 
            |
| 427 |                         $errMsg = sprintf('Metadata for property already exist %s', $propertyName); | 
            ||
| 428 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 429 | }  | 
            ||
| 430 | $index[$uniqueKey][$entityClassName][$propertyName] = [];  | 
            ||
| 431 | |||
| 432 | $modeOriginal = array_key_exists(static::MODE, $identifierItem) ? $identifierItem[static::MODE] : static ::MODE_ROUTER_PARAM;  | 
            ||
| 433 | $mode = strtolower($modeOriginal);  | 
            ||
| 434 | |||
| 435 |                     if (!array_key_exists($mode, $this->accessMode)) { | 
            ||
| 436 |                         $errMsg = sprintf('Invalid value for the "mode" %s', $mode); | 
            ||
| 437 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 438 | }  | 
            ||
| 439 | $index[$uniqueKey][$entityClassName][$propertyName][static::MODE] = $mode;  | 
            ||
| 440 | |||
| 441 | View Code Duplication |                     if (!array_key_exists(static::PARAM_NAME, $identifierItem)) { | 
            |
| 442 |                         $errMsg = sprintf('there is no option %s', static::PARAM_NAME); | 
            ||
| 443 | throw new Exception\InvalidWorkflowEntryToObjectMetadataException($errMsg);  | 
            ||
| 444 | }  | 
            ||
| 445 | $paramName = $identifierItem[static::PARAM_NAME];  | 
            ||
| 446 | $index[$uniqueKey][$entityClassName][$propertyName][static::PARAM_NAME] = $paramName;  | 
            ||
| 447 | }  | 
            ||
| 448 | }  | 
            ||
| 449 | }  | 
            ||
| 450 | |||
| 451 | $this->indexMetadata = $index;  | 
            ||
| 452 | |||
| 453 | return $this->indexMetadata;  | 
            ||
| 454 | }  | 
            ||
| 455 | |||
| 562 | 
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.