Skip to content

Instantly share code, notes, and snippets.

@aik099
Created May 5, 2014 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aik099/431186f3a8fe51a7cdb3 to your computer and use it in GitHub Desktop.
Save aik099/431186f3a8fe51a7cdb3 to your computer and use it in GitHub Desktop.
Snippet for PHP_CodeSniffer Sniff Test Line Number Fixing
<?php
/**
* Example input code:
*
* 45 => 2,
* 11 => 1,
*
* // Some comment to ignore.
* 100 => 12,
*/
$line_number_modificator = $_GET['line_number_modificator']; // e.g. "+1" or "-12"
$lines = array_map('trim', explode("\n", $_GET['source_text'];
foreach ( $lines as $i => $line ) {
if ( substr($line, 0, 2) == '//' || strlen($line) == 0 ) {
// Skip comments or empty lines.
continue;
}
if ( preg_match('/^([\d]+)(.*)=>(.*)$/', $line, $regs) ) {
$lines[$i] = array_sum(array($regs[1], $line_number_modificator)) . $regs[2] . '=>' . $regs[3];
}
}
echo htmlspecialchars(implode("\n", $lines));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment