| Conditions | 10 |
| Paths | 5 |
| Total Lines | 68 |
| Code Lines | 24 |
| 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 |
||
| 113 | public function propagate(FlowInterface $flow) |
||
| 114 | { |
||
| 115 | $InterrupterFlowId = $flow->getId(); |
||
| 116 | // evacuate border cases |
||
| 117 | if ( |
||
| 118 | // no target = InterrupterInterface::TARGET_SELF |
||
| 119 | !$this->flowTarget || |
||
| 120 | ( |
||
| 121 | // asked to stop right here |
||
| 122 | $this->flowTarget === InterrupterInterface::TARGET_SELF || |
||
| 123 | $this->flowTarget === $InterrupterFlowId || |
||
| 124 | ( |
||
| 125 | // target root when this Flow is root already |
||
| 126 | $this->flowTarget === InterrupterInterface::TARGET_TOP && |
||
| 127 | !$flow->hasParent() |
||
| 128 | ) |
||
| 129 | ) |
||
| 130 | ) { |
||
| 131 | // if anything had to be done, it was done first hand already |
||
| 132 | // just make sure we propagate the eventual nodeTarget |
||
| 133 | return $flow->setInterruptNodeId($this->nodeTarget); |
||
| 134 | } |
||
| 135 | |||
| 136 | if (!$this->type) { |
||
| 137 | throw new NodalFlowException('No interrupt type set', 1, null, [ |
||
| 138 | 'InterrupterFlowId' => $InterrupterFlowId, |
||
| 139 | ]); |
||
| 140 | } |
||
| 141 | |||
| 142 | do { |
||
| 143 | // keep this for later |
||
| 144 | $lastFlowId = $flow->getId(); |
||
| 145 | if ($this->flowTarget === $lastFlowId) { |
||
| 146 | // interrupting $flow |
||
| 147 | return $flow->setInterruptNodeId($this->nodeTarget)->interruptFlow($this->type); |
||
| 148 | } |
||
| 149 | |||
| 150 | // by not bubbling the FlowInterrupt we make sure that each |
||
| 151 | // eventual upstream Flow will only interrupt themselves, the |
||
| 152 | // actual management is performed by this Flow which first |
||
| 153 | // received the interrupt signal |
||
| 154 | // also set interruptNodeId to true in order to make sure |
||
| 155 | // we do not match any nodes in this flow (as it is not the target) |
||
| 156 | $flow->setInterruptNodeId(true)->interruptFlow($this->type); |
||
| 157 | } while ($flow = $flow->getParent()); |
||
| 158 | |||
| 159 | // Here the target was either InterrupterInterface::TARGET_TOP or |
||
| 160 | // anything else that did not match any of the Flow ancestor's |
||
| 161 | // ids. |
||
| 162 | // `$lastFlowId` is the root Flow id, which may as well be this |
||
| 163 | // very Flow. |
||
| 164 | // This implies that the only legit value for `$interruptAt` is |
||
| 165 | // `InterrupterInterface::TARGET_TOP` since : |
||
| 166 | // - `$interruptAt` matching this Flow id is caught above |
||
| 167 | // when triggering `isReached` the first time |
||
| 168 | // - `$interruptAt` being null is also caught above |
||
| 169 | // - `$interruptAt` matching `InterrupterInterface::TARGET_TOP` |
||
| 170 | // with this having no parent is also caught above |
||
| 171 | if ($this->flowTarget !== InterrupterInterface::TARGET_TOP) { |
||
| 172 | throw new NodalFlowException('Interruption target missed', 1, null, [ |
||
| 173 | 'interruptAt' => $this->flowTarget, |
||
| 174 | 'InterrupterFlowId' => $InterrupterFlowId, |
||
| 175 | 'lastFlowId' => $lastFlowId, |
||
| 176 | ]); |
||
| 177 | } |
||
| 178 | |||
| 179 | return $flow; |
||
| 180 | } |
||
| 181 | |||
| 192 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.