Skip to content

Instantly share code, notes, and snippets.

@maks-rafalko
Created October 14, 2017 22:51
Show Gist options
  • Save maks-rafalko/596a938db74e4d2b423e0ab6ac43df95 to your computer and use it in GitHub Desktop.
Save maks-rafalko/596a938db74e4d2b423e0ab6ac43df95 to your computer and use it in GitHub Desktop.
<?php
class Addition extends MutatorAbstract
{
public static function getMutation(array &$tokens, $index)
{
$tokens[$index] = '-';
}
public static function mutates(array &$tokens, $index)
{
$t = $tokens[$index];
if (!is_array($t) && $t == '+') {
$tokenCount = count($tokens);
for ($i = $index + 1; $i < $tokenCount; $i++) {
// check for short array syntax
if (!is_array($tokens[$i]) && $tokens[$i][0] == '[') {
return false;
}
// check for long array syntax
if (is_array($tokens[$i]) && $tokens[$i][0] == T_ARRAY && $tokens[$i][1] == 'array') {
return false;
}
// if we're at the end of the array
// and we didn't see any array, we
// can probably mutate this addition
if (!is_array($tokens[$i]) && $tokens[$i] == ';') {
return true;
}
}
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment