| Conditions | 10 |
| Paths | 20 |
| Total Lines | 49 |
| 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 |
||
| 53 | public function merge(ConflictHandlerInterface $conflictHandler, Index $remoteIndex, Index $localIndex, ?Index $lastLocalIndex, int $options = 0): Index |
||
| 54 | { |
||
| 55 | $this->logger->info(sprintf("Merging indices using %s (Options: %s)", static::class, static::getOptionsDebugString($options))); |
||
| 56 | |||
| 57 | $mergedIndex = new Index(); |
||
| 58 | $lastLocalIndex = $lastLocalIndex ?: new Index(); |
||
| 59 | |||
| 60 | $diff = $localIndex->getDifference($remoteIndex, IndexObject::CMP_IGNORE_BLOBID | IndexObject::CMP_IGNORE_INODE); |
||
| 61 | |||
| 62 | $this->logger->debug(sprintf("Found %d differences between local and remote index", count($diff))); |
||
| 63 | |||
| 64 | foreach ($diff as $cmp) |
||
| 65 | { |
||
| 66 | /** @var IndexObjectComparison $cmp */ |
||
| 67 | |||
| 68 | $localObject = $localIndex->getObjectByPath($cmp->getRelativePath()); |
||
| 69 | $lastLocalObject = $lastLocalIndex->getObjectByPath($cmp->getRelativePath()); |
||
| 70 | $remoteObject = $remoteIndex->getObjectByPath($cmp->getRelativePath()); |
||
| 71 | |||
| 72 | $localObjectModified = $this->isLocalObjectModified($localObject, $lastLocalObject, $options); |
||
| 73 | $remoteObjectModified = $this->isRemoteObjectModified($remoteObject, $lastLocalObject); |
||
| 74 | |||
| 75 | if ($localObjectModified && $remoteObjectModified) |
||
| 76 | { |
||
| 77 | $mergedIndex->addObject($this->resolveConflict($conflictHandler, $remoteObject, $localObject, $lastLocalObject)); |
||
|
|
|||
| 78 | } |
||
| 79 | elseif ($localObjectModified && $localObject !== null) |
||
| 80 | { |
||
| 81 | $mergedIndex->addObject($localObject); |
||
| 82 | } |
||
| 83 | elseif ($remoteObjectModified && $remoteObject !== null) |
||
| 84 | { |
||
| 85 | $mergedIndex->addObject($remoteObject); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | $intersection = $localIndex->getIntersection($remoteIndex, IndexObject::CMP_IGNORE_BLOBID | IndexObject::CMP_IGNORE_INODE); |
||
| 90 | |||
| 91 | $this->logger->debug(sprintf("Found %d similarities between local and remote index", count($intersection))); |
||
| 92 | |||
| 93 | foreach ($intersection as $cmp) |
||
| 94 | { |
||
| 95 | /** @var IndexObjectComparison $cmp */ |
||
| 96 | |||
| 97 | $mergedIndex->addObject($cmp->getIndexObjectA()); |
||
| 98 | } |
||
| 99 | |||
| 100 | return $mergedIndex; |
||
| 101 | } |
||
| 102 | |||
| 195 |
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: