private function findIncludies(Tokens $tokens)
{
static $includyTokenKinds = array(T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE);
$includies = array();
foreach ($tokens->findGivenKind($includyTokenKinds) as $includyTokens) {
foreach ($includyTokens as $index => $token) {
$includy = array('begin' => $index, 'braces' => null, 'end' => $tokens->getNextTokenOfKind($index, array(';', array(T_CLOSE_TAG))));
$nextTokenIndex = $tokens->getNextMeaningfulToken($index);
$nextToken = $tokens[$nextTokenIndex];
if ($nextToken->equals('(')) {
// Don't remove braces when the statement is wrapped.
// Include is also legal as function parameter or condition statement but requires being wrapped then.
$braceCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextTokenIndex);
if ($tokens[$tokens->getNextMeaningfulToken($braceCloseIndex)]->equalsAny(array(';', array(T_CLOSE_TAG)))) {
$includy['braces'] = array('open' => $nextTokenIndex, 'close' => $braceCloseIndex);
}
}
$includies[] = $includy;
}
}
return $includies;
}