Created
October 14, 2017 22:51
-
-
Save maks-rafalko/596a938db74e4d2b423e0ab6ac43df95 to your computer and use it in GitHub Desktop.
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 | |
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