Conditions | 12 |
Paths | 162 |
Total Lines | 51 |
Code Lines | 29 |
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 |
||
78 | private function createTreeFromTaskName(string $taskName, string $postfix = '', bool $isLast = false) |
||
79 | { |
||
80 | $task = $this->deployer->tasks->get($taskName); |
||
81 | |||
82 | if (!$task->isEnabled()) { |
||
83 | if (empty($postfix)) { |
||
84 | $postfix = ' // disabled'; |
||
85 | } else { |
||
86 | $postfix .= '; disabled'; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | if ($task->getBefore()) { |
||
91 | $beforePostfix = sprintf(" // before %s", $task->getName()); |
||
92 | |||
93 | foreach ($task->getBefore() as $beforeTask) { |
||
94 | $this->createTreeFromTaskName($beforeTask, $beforePostfix); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | if ($task instanceof GroupTask) { |
||
99 | $isLast = $isLast && empty($task->getAfter()); |
||
100 | |||
101 | $this->addTaskToTree($task->getName() . $postfix, $isLast); |
||
102 | |||
103 | if (!$isLast) { |
||
104 | $this->openGroupDepths[] = $this->depth; |
||
105 | } |
||
106 | |||
107 | $this->depth++; |
||
108 | |||
109 | $taskGroup = $task->getGroup(); |
||
110 | foreach ($taskGroup as $subtask) { |
||
111 | $isLastSubtask = $subtask === end($taskGroup); |
||
112 | $this->createTreeFromTaskName($subtask, '', $isLastSubtask); |
||
113 | } |
||
114 | |||
115 | if (!$isLast) { |
||
116 | array_pop($this->openGroupDepths); |
||
117 | } |
||
118 | |||
119 | $this->depth--; |
||
120 | } else { |
||
121 | $this->addTaskToTree($task->getName() . $postfix, $isLast); |
||
122 | } |
||
123 | |||
124 | if ($task->getAfter()) { |
||
125 | $afterPostfix = sprintf(" // after %s", $task->getName()); |
||
126 | |||
127 | foreach ($task->getAfter() as $afterTask) { |
||
128 | $this->createTreeFromTaskName($afterTask, $afterPostfix); |
||
129 | } |
||
181 |