| Conditions | 17 | 
| Paths | 54 | 
| Total Lines | 64 | 
| 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  | 
            ||
| 47 | public function merge(ConflictHandlerInterface $conflictHandler, Index $remoteIndex, Index $localIndex, ?Index $lastLocalIndex, int $options = 0): Index  | 
            ||
| 48 |     { | 
            ||
| 49 |         $this->logger->info(sprintf("Merging indices using %s (Options: %s)", static::class, static::getOptionsDebugString($options))); | 
            ||
| 50 | |||
| 51 | $mergedIndex = new Index();  | 
            ||
| 52 | $lastLocalIndex = $lastLocalIndex ?: new Index();  | 
            ||
| 53 | |||
| 54 | $diff = $localIndex->getDifference($remoteIndex, static::CMP_OPTIONS);  | 
            ||
| 55 | |||
| 56 |         $this->logger->debug(sprintf("Found %d differences between local and remote index", count($diff))); | 
            ||
| 57 | |||
| 58 | foreach ($diff as $cmp)  | 
            ||
| 59 |         { | 
            ||
| 60 | /** @var IndexObjectComparison $cmp */  | 
            ||
| 61 | |||
| 62 | $localObject = $localIndex->getObjectByPath($cmp->getRelativePath());  | 
            ||
| 63 | $lastLocalObject = $lastLocalIndex->getObjectByPath($cmp->getRelativePath());  | 
            ||
| 64 | $remoteObject = $remoteIndex->getObjectByPath($cmp->getRelativePath());  | 
            ||
| 65 | |||
| 66 | $localObjectModified = $this->isLocalObjectModified($localObject, $lastLocalObject, $options);  | 
            ||
| 67 | $remoteObjectModified = $this->isRemoteObjectModified($remoteObject, $lastLocalObject);  | 
            ||
| 68 | |||
| 69 | if ($options & static::INJECT_BLOBID && $localObject !== null && !$localObjectModified)  | 
            ||
| 70 |             { | 
            ||
| 71 | assert($lastLocalObject !== null || $remoteObject !== null);  | 
            ||
| 72 | |||
| 73 | $localObject->setBlobId($lastLocalObject ? $lastLocalObject->getBlobId() : $remoteObject->getBlobId());  | 
            ||
| 74 | }  | 
            ||
| 75 | |||
| 76 | if ($localObjectModified && $remoteObjectModified)  | 
            ||
| 77 |             { | 
            ||
| 78 | $mergedIndex->addObject($this->resolveConflict($conflictHandler, $remoteObject, $localObject, $lastLocalObject));  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 79 | }  | 
            ||
| 80 | elseif ($localObjectModified && $localObject !== null)  | 
            ||
| 81 |             { | 
            ||
| 82 | $mergedIndex->addObject($localObject);  | 
            ||
| 83 | }  | 
            ||
| 84 | elseif ($remoteObjectModified && $remoteObject !== null)  | 
            ||
| 85 |             { | 
            ||
| 86 | $mergedIndex->addObject($remoteObject);  | 
            ||
| 87 | }  | 
            ||
| 88 | }  | 
            ||
| 89 | |||
| 90 | $intersection = $localIndex->getIntersection($remoteIndex, static::CMP_OPTIONS);  | 
            ||
| 91 | |||
| 92 |         $this->logger->debug(sprintf("Found %d similarities between local and remote index", count($intersection))); | 
            ||
| 93 | |||
| 94 | foreach ($intersection as $cmp)  | 
            ||
| 95 |         { | 
            ||
| 96 | /** @var IndexObjectComparison $cmp */  | 
            ||
| 97 | |||
| 98 | // indexObjectB refers to remote object which we want to use to re-use the already existing blobId  | 
            ||
| 99 | $remoteObject = $cmp->getIndexObjectB();  | 
            ||
| 100 | |||
| 101 | $mergedIndex->addObject($remoteObject);  | 
            ||
| 102 | |||
| 103 | if ($options & static::INJECT_BLOBID && $remoteObject->isFile())  | 
            ||
| 104 |             { | 
            ||
| 105 | $cmp->getIndexObjectA()->setBlobId($remoteObject->getBlobId());  | 
            ||
| 106 | }  | 
            ||
| 107 | }  | 
            ||
| 108 | |||
| 109 | return $mergedIndex;  | 
            ||
| 110 | }  | 
            ||
| 111 | |||
| 204 | 
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: