Changeset View
Changeset View
Standalone View
Standalone View
src/lint/ArcanistLintMessage.php
Show First 20 Lines • Show All 296 Lines • ▼ Show 20 Lines | for ($ii = 0; $ii < $minimum_length; $ii++) { | ||||
} | } | ||||
$prefix_length++; | $prefix_length++; | ||||
} | } | ||||
// NOTE: The two strings can't be the same because the message won't be | // NOTE: The two strings can't be the same because the message won't be | ||||
// "patchable" if they are, so we don't need a special check for the case | // "patchable" if they are, so we don't need a special check for the case | ||||
// where the entire string is a shared prefix. | // where the entire string is a shared prefix. | ||||
// However, if the two strings are in the form "ABC" and "ABBC", we may | |||||
// find a prefix and a suffix with a combined length greater than the | |||||
// total size of the smaller string if we don't limit the search. | |||||
$max_suffix = ($minimum_length - $prefix_length); | |||||
$suffix_length = 0; | $suffix_length = 0; | ||||
for ($ii = 1; $ii <= $minimum_length; $ii++) { | for ($ii = 1; $ii <= $max_suffix; $ii++) { | ||||
$original_char = $original[$original_length - $ii]; | $original_char = $original[$original_length - $ii]; | ||||
$replacement_char = $replacement[$replacement_length - $ii]; | $replacement_char = $replacement[$replacement_length - $ii]; | ||||
if ($original_char !== $replacement_char) { | if ($original_char !== $replacement_char) { | ||||
break; | break; | ||||
} | } | ||||
$suffix_length++; | $suffix_length++; | ||||
} | } | ||||
if ($suffix_length) { | if ($suffix_length) { | ||||
$original = substr($original, 0, -$suffix_length); | $original = substr($original, 0, -$suffix_length); | ||||
$replacement = substr($replacement, 0, -$suffix_length); | $replacement = substr($replacement, 0, -$suffix_length); | ||||
} | } | ||||
$line = $this->getLine(); | $line = $this->getLine(); | ||||
$char = $this->getChar(); | $char = $this->getChar(); | ||||
if ($prefix_length) { | if ($prefix_length) { | ||||
$prefix = substr($original, 0, $prefix_length); | $prefix = substr($original, 0, $prefix_length); | ||||
$original = substr($original, $prefix_length); | // NOTE: Prior to PHP7, `substr("a", 1)` returned false instead of | ||||
$replacement = substr($replacement, $prefix_length); | // the empty string. Cast these to force the PHP7-ish behavior we | ||||
// expect. | |||||
$original = (string)substr($original, $prefix_length); | |||||
$replacement = (string)substr($replacement, $prefix_length); | |||||
// If we've removed a prefix, we need to push the character and line | // If we've removed a prefix, we need to push the character and line | ||||
// number for the warning forward to account for the characters we threw | // number for the warning forward to account for the characters we threw | ||||
// away. | // away. | ||||
for ($ii = 0; $ii < $prefix_length; $ii++) { | for ($ii = 0; $ii < $prefix_length; $ii++) { | ||||
$char++; | $char++; | ||||
if ($prefix[$ii] == "\n") { | if ($prefix[$ii] == "\n") { | ||||
$line++; | $line++; | ||||
Show All 13 Lines |