Using braces even for one liners has one big "+1" - many code re-formatters do not align such constructs without the braces.
Second - braces tend to show that this is individual block of code under condition or loop.
As for tabs vs spaces - I personally use tabs and don’t like spaces because many editors treat those space idents, well, as spaces. Navigation through code with arrows becomes tedious. Tabs, on the other hand, almost every IDE or feature-full editor are handled very well and advanced navigation helps very well (usually it’s called something like “Smart tabs” or alike). For example in PHPStorm this advanced fast navigation works only with tabs. Use spaces and it becomes much harder to navigate and edit the code (not writing new code, but there are few caveats too).
I know only one IDE that did transparent space conversion to tab-like navigation - Zend Studio 5.5 and lower. It had a feature "Treat spaces as tabs" and "Tab size [ X ]" made those spaces work like tabs of specified width in editor, but the file was formatted with spaces, where 1 virtual tab was X spaces.
Why not just use common size tab (4 spaces) and use the rule that aligning of the levels, aligned arrays and so on takes 1 tab. Code looks good and everyone can make tab the size they like - be it 2, 6 or 8 spaces.
To illustrate what I mean:
/**
* @param $step
* @return void
*/
final public function actionCheckProxy()
{
if ($this->account->proxy_active && count($this->account->proxyLists)) {
foreach ($this->account->proxyLists as $proxy) {
if ($proxy->active == 'no') {
continue;
}
$options = array(
CURLOPT_URL => 'https://example.com/checkproxy?time='.urlencode(microtime(true)),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_CONNECTTIMEOUT => 15,
CURLOPT_TIMEOUT => 15,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
CURLOPT_HTTPPROXYTUNNEL => false,
CURLOPT_PROXY => $proxy->host,
CURLOPT_PROXYPORT => $proxy->port,
CURLOPT_PROXYAUTH => CURLAUTH_BASIC,
CURLOPT_PROXYUSERPWD => $proxy->user.':'.$proxy->password
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$errno = curl_errno($ch);
$error = curl_error($ch);
curl_close($ch);
unset($ch);
$x = strpos($content, $proxy->host);
if ($errno !== 0) {
Yii::log(
$content.' '.$proxy->host.' '.var_export($x, true).PHP_EOL
.$errno.' - '.$error.PHP_EOL
.print_r(getReadableCurlOptions($options), true),
'error'
);
$proxy->active = 'no';
$proxy->update(array('active'));
$message = sprintf(
'Connectivity check of the proxy has failed for transaction %s.<br>
Proxy '.$proxy->host.' has not responded for account '.$this->account->login.'<br>
Proxy was disabled',
$this->trans->id
);
if ($errno !== 0) {
$message .= '<br>cURL error was recorded: '.$errno.' - '.$error;
}
$emails = Params::multiple('supportnotify');
if (is_array($emails) && count($emails) > 0) {
try {
foreach ($emails as $email) {
$this->_sendMail($email, sprintf($message, $this->trans->id), 'Proxy down alert!','admin_notify');
}
} catch (Exception $e) {
}
}
} else {
$this->proxy = $proxy;
if ($this->current_step != null && isset($this->steps[$this->current_step])) {
}
break;
}
}
}
if ($this->proxy instanceof ProxyList) {
Operations::addEntry($this->trans, 'Using proxy '.$this->proxy->host.' for the requests');
} elseif ($this->account->proxy_active) {
Operations::addEntry($this->trans, 'Proxy use flag is active, but no active proxy available');
} else {
Operations::addEntry($this->trans, 'Proxy usage is disabled');
}
}
All this code has been aligned with 4 spaces tab. Here is an actual screenshot: https://www.file.lu/imageh/0/4/xvu48cj5kkqm.png