Conditions | 7 |
Paths | 8 |
Total Lines | 56 |
Code Lines | 25 |
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 |
||
48 | public function validateStep(Step $step) |
||
49 | { |
||
50 | /* |
||
51 | * The first step is always valid. |
||
52 | */ |
||
53 | $firstStep = $this->formObject->getConfiguration()->getSteps()->getFirstStep(); |
||
54 | |||
55 | if ($step === $firstStep) { |
||
56 | \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(111, '111'); |
||
57 | return null; |
||
58 | } |
||
59 | |||
60 | /* |
||
61 | * If there is no form instance, and the request is not in the first |
||
62 | * step, obviously the user should not be there. |
||
63 | */ |
||
64 | if (false === $this->formObject->hasForm()) { |
||
65 | \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(222, '222'); |
||
66 | return $firstStep; |
||
67 | } |
||
68 | |||
69 | /* |
||
70 | * @todo |
||
71 | */ |
||
72 | $stepsToTest = []; |
||
73 | $stepToRedirect = $firstStep; |
||
74 | // \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($step, '$step??'); |
||
75 | |||
76 | while ($step->hasPreviousStep()) { |
||
77 | $step = $step->getPreviousStep(); |
||
78 | $stepsToTest[] = $step; |
||
79 | } |
||
80 | |||
81 | \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($stepsToTest, '$stepsToTest'); |
||
82 | |||
83 | foreach ($stepsToTest as $step) { |
||
84 | $result = $this->getStepValidationResult($step); |
||
85 | |||
86 | if ($result->hasErrors()) { |
||
87 | $stepToRedirect = $step; |
||
88 | } |
||
89 | } |
||
90 | |||
91 | \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($stepToRedirect, '$lastStepWithErrors 333'); |
||
92 | return $stepToRedirect; |
||
93 | |||
94 | |||
95 | $key = 'core.step'; |
||
|
|||
96 | $metadata = $this->formObject->getFormMetadata()->getMetadata(); |
||
97 | |||
98 | if ($metadata->has(self::METADATA_STEP_KEY)) { |
||
99 | // @todo |
||
100 | } else { |
||
101 | $metadata->set($key, 1); |
||
102 | } |
||
103 | } |
||
104 | |||
129 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.