Created
May 5, 2014 08:31
-
-
Save aik099/431186f3a8fe51a7cdb3 to your computer and use it in GitHub Desktop.
Snippet for PHP_CodeSniffer Sniff Test Line Number Fixing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Example file where you can see these numbers: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php