Conditions | 15 |
Paths | 136 |
Total Lines | 70 |
Code Lines | 42 |
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 |
||
88 | protected function execute(Input $input, Output $output): int |
||
89 | { |
||
90 | $this->deployer->input = $input; |
||
91 | $this->deployer->output = $output; |
||
92 | $this->deployer['log'] = $input->getOption('log'); |
||
93 | $this->telemetry([ |
||
94 | 'project_hash' => empty($this->deployer->config['repository']) ? null : sha1($this->deployer->config['repository']), |
||
95 | 'hosts_count' => $this->deployer->hosts->count(), |
||
96 | 'recipes' => $this->deployer->config->get('recipes', []), |
||
97 | ]); |
||
98 | |||
99 | $hosts = $this->selectHosts($input, $output); |
||
100 | $this->applyOverrides($hosts, $input->getOption('option')); |
||
101 | |||
102 | // Save selected_hosts for selectedHosts() func. |
||
103 | $hostsAliases = []; |
||
104 | foreach ($hosts as $host) { |
||
105 | $hostsAliases[] = $host->getAlias(); |
||
106 | } |
||
107 | // Save selected_hosts per each host, and not globally. Otherwise it will |
||
108 | // not be accessible for workers. |
||
109 | foreach ($hosts as $host) { |
||
110 | $host->set('selected_hosts', $hostsAliases); |
||
111 | } |
||
112 | |||
113 | $plan = $input->getOption('plan') ? new Planner($output, $hosts) : null; |
||
114 | |||
115 | $this->deployer->scriptManager->setHooksEnabled(!$input->getOption('no-hooks')); |
||
116 | $startFrom = $input->getOption('start-from'); |
||
117 | if ($startFrom && !$this->deployer->tasks->has($startFrom)) { |
||
118 | throw new Exception("Task $startFrom does not exist."); |
||
119 | } |
||
120 | $skippedTasks = []; |
||
121 | $tasks = $this->deployer->scriptManager->getTasks($this->getName(), $startFrom, $skippedTasks); |
||
122 | |||
123 | if (empty($tasks)) { |
||
124 | throw new Exception('No task will be executed, because the selected hosts do not meet the conditions of the tasks'); |
||
125 | } |
||
126 | |||
127 | if (!$plan) { |
||
128 | $this->checkUpdates(); |
||
129 | if (!empty($skippedTasks)) { |
||
130 | foreach ($skippedTasks as $taskName) { |
||
131 | $output->writeln("<fg=yellow;options=bold>skip</> $taskName"); |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | $exitCode = $this->deployer->master->run($tasks, $hosts, $plan); |
||
136 | |||
137 | if ($plan) { |
||
138 | $plan->render(); |
||
139 | return 0; |
||
140 | } |
||
141 | |||
142 | if ($exitCode === 0) { |
||
143 | $this->showBanner(); |
||
144 | return 0; |
||
145 | } |
||
146 | if ($exitCode === GracefulShutdownException::EXIT_CODE) { |
||
147 | return 1; |
||
148 | } |
||
149 | |||
150 | // Check if we have tasks to execute on failure. |
||
151 | if ($this->deployer['fail']->has($this->getName())) { |
||
152 | $taskName = $this->deployer['fail']->get($this->getName()); |
||
153 | $tasks = $this->deployer->scriptManager->getTasks($taskName); |
||
154 | $this->deployer->master->run($tasks, $hosts); |
||
155 | } |
||
156 | |||
157 | return $exitCode; |
||
158 | } |
||
198 |