Skip to content

Instantly share code, notes, and snippets.

@morganestes
Created October 2, 2013 18:32
Show Gist options
  • Select an option

  • Save morganestes/6798352 to your computer and use it in GitHub Desktop.

Select an option

Save morganestes/6798352 to your computer and use it in GitHub Desktop.
PHPTidy bug report for switches
<?php
// Starting at line 1577 in v2.11
// Remove lines 1577-1593 to get result in switch-modified.php
if (
isset($tokens[$key+1]) and
is_array($tokens[$key+1]) and (
$tokens[$key+1][0] === T_CASE or
$tokens[$key+1][0] === T_DEFAULT or (
isset($tokens[$key+2]) and
is_array($tokens[$key+2]) and (
$tokens[$key+2][0] === T_CASE or
$tokens[$key+2][0] === T_DEFAULT
) and
// T_WHITESPACE without \n first
$tokens[$key+1][0] === T_WHITESPACE and
strpos($tokens[$key+1][1], "\n")===false
)
)
) $indent++;
<?php
switch ($type) {
case 'month':
$months = array(
1 => 'Jan',
2 => 'Feb',
3 => 'Mar',
4 => 'Apr',
5 => 'May',
6 => 'June',
7 => 'July',
8 => 'Aug',
9 => 'Sept',
10 => 'Oct',
11 => 'Nov',
12 => 'Dec',
);
$select .= '<option>Month</option>' . PHP_EOL;
for ($month = 1; $month <= 12; $month ++) {
$month_name = $months[$month];
$month = sprintf("%02s", $month);
$select .= "<option value='$month'>$month &mdash; $month_name</option>" . PHP_EOL;
}
break;
case 'year':
$select .= '<option>Year</option>' . PHP_EOL;
$this_year = date('Y');
for ($year = $this_year; $year <= $this_year + 12; $year++) {
$select .= "<option value='$year'>$year</option>" . PHP_EOL;
}
break;
}
<?php
switch ($type) {
case 'month':
$months = array(
1 => 'Jan',
2 => 'Feb',
3 => 'Mar',
4 => 'Apr',
5 => 'May',
6 => 'June',
7 => 'July',
8 => 'Aug',
9 => 'Sept',
10 => 'Oct',
11 => 'Nov',
12 => 'Dec',
);
$select .= '<option>Month</option>' . PHP_EOL;
for ($month = 1; $month <= 12; $month ++) {
$month_name = $months[$month];
$month = sprintf("%02s", $month);
$select .= "<option value='$month'>$month &mdash; $month_name</option>" . PHP_EOL;
}
break;
case 'year':
$select .= '<option>Year</option>' . PHP_EOL;
$this_year = date('Y');
for ($year = $this_year; $year <= $this_year + 12; $year++) {
$select .= "<option value='$year'>$year</option>" . PHP_EOL;
}
break;
}
<?php
switch ($type) {
case 'month':
$months = array(
1 => 'Jan',
2 => 'Feb',
3 => 'Mar',
4 => 'Apr',
5 => 'May',
6 => 'June',
7 => 'July',
8 => 'Aug',
9 => 'Sept',
10 => 'Oct',
11 => 'Nov',
12 => 'Dec',
);
$select .= '<option>Month</option>' . PHP_EOL;
for ($month = 1; $month <= 12; $month ++) {
$month_name = $months[$month];
$month = sprintf("%02s", $month);
$select .= "<option value='$month'>$month &mdash; $month_name</option>" . PHP_EOL;
}
break;
case 'year':
$select .= '<option>Year</option>' . PHP_EOL;
$this_year = date('Y');
for ($year = $this_year; $year <= $this_year + 12; $year++) {
$select .= "<option value='$year'>$year</option>" . PHP_EOL;
}
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment