| Conditions | 29 |
| Paths | 66 |
| Total Lines | 83 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 76 | public function revertEntityToTimestamp(AbstractDBElement $element, \DateTime $timestamp, array $reverted_elements = []) |
||
| 77 | { |
||
| 78 | if (!$element instanceof TimeStampableInterface) { |
||
| 79 | throw new \InvalidArgumentException('$element must have a Timestamp!'); |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($timestamp > new \DateTime('now')) { |
||
| 83 | throw new \InvalidArgumentException('You can not travel to the future (yet)...'); |
||
| 84 | } |
||
| 85 | |||
| 86 | //Skip this process if already were reverted... |
||
| 87 | if (in_array($element, $reverted_elements)) { |
||
| 88 | return; |
||
| 89 | } |
||
| 90 | $reverted_elements[] = $element; |
||
| 91 | |||
| 92 | $history = $this->repo->getTimetravelDataForElement($element, $timestamp); |
||
| 93 | |||
| 94 | /* |
||
| 95 | if (!$this->repo->getElementExistedAtTimestamp($element, $timestamp)) { |
||
| 96 | $element = null; |
||
| 97 | return; |
||
| 98 | }*/ |
||
| 99 | |||
| 100 | foreach ($history as $logEntry) { |
||
| 101 | if ($logEntry instanceof ElementEditedLogEntry) { |
||
| 102 | $this->applyEntry($element, $logEntry); |
||
| 103 | } |
||
| 104 | if ($logEntry instanceof CollectionElementDeleted) { |
||
| 105 | //Undelete element and add it to collection again |
||
| 106 | $undeleted = $this->undeleteEntity( |
||
| 107 | $logEntry->getDeletedElementClass(), |
||
| 108 | $logEntry->getDeletedElementID() |
||
| 109 | ); |
||
| 110 | if ($this->repo->getElementExistedAtTimestamp($undeleted, $timestamp)) { |
||
| 111 | $this->revertEntityToTimestamp($undeleted, $timestamp, $reverted_elements); |
||
| 112 | $collection = $this->getField($element, $logEntry->getCollectionName()); |
||
| 113 | if ($collection instanceof Collection) { |
||
| 114 | $collection->add($undeleted); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | // Revert any of the associated elements |
||
| 121 | $metadata = $this->em->getClassMetadata(get_class($element)); |
||
| 122 | $associations = $metadata->getAssociationMappings(); |
||
|
|
|||
| 123 | foreach ($associations as $field => $mapping) { |
||
| 124 | if ( |
||
| 125 | ($element instanceof AbstractStructuralDBElement && ($field === 'parts' || $field === 'children')) |
||
| 126 | || ($element instanceof AttachmentType && $field === 'attachments') |
||
| 127 | ) { |
||
| 128 | continue; |
||
| 129 | } |
||
| 130 | |||
| 131 | |||
| 132 | //Revert many to one association (one element in property) |
||
| 133 | if ( |
||
| 134 | $mapping['type'] === ClassMetadata::MANY_TO_ONE |
||
| 135 | || $mapping['type'] === ClassMetadata::ONE_TO_ONE |
||
| 136 | ) { |
||
| 137 | $target_element = $this->getField($element, $field); |
||
| 138 | if ($target_element !== null && $element->getLastModified() > $timestamp) { |
||
| 139 | $this->revertEntityToTimestamp($target_element, $timestamp, $reverted_elements); |
||
| 140 | } |
||
| 141 | } elseif ( //Revert *_TO_MANY associations (collection properties) |
||
| 142 | ($mapping['type'] === ClassMetadata::MANY_TO_MANY |
||
| 143 | || $mapping['type'] === ClassMetadata::ONE_TO_MANY) |
||
| 144 | && $mapping['isOwningSide'] === false |
||
| 145 | ) { |
||
| 146 | $target_elements = $this->getField($element, $field); |
||
| 147 | if ($target_elements === null || count($target_elements) > 10) { |
||
| 148 | continue; |
||
| 149 | } |
||
| 150 | foreach ($target_elements as $target_element) { |
||
| 151 | if ($target_element !== null && $element->getLastModified() >= $timestamp) { |
||
| 152 | //Remove the element from collection, if it did not existed at $timestamp |
||
| 153 | if (!$this->repo->getElementExistedAtTimestamp($target_element, $timestamp)) { |
||
| 154 | if ($target_elements instanceof Collection) { |
||
| 155 | $target_elements->removeElement($target_element); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | $this->revertEntityToTimestamp($target_element, $timestamp, $reverted_elements); |
||
| 159 | } |
||
| 217 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.