2021-03-07 22:25:43 +01:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2021-03-07 22:25:43 +01:00
|
|
|
namespace Rector\DowngradePhp73\Tokenizer;
|
|
|
|
|
2021-06-21 19:24:28 +00:00
|
|
|
use RectorPrefix20210621\Nette\Utils\Strings;
|
2021-03-07 22:25:43 +01:00
|
|
|
use PhpParser\Node;
|
2021-04-13 02:12:48 +02:00
|
|
|
use Rector\Core\ValueObject\Application\File;
|
2021-03-07 22:25:43 +01:00
|
|
|
final class FollowedByCommaAnalyzer
|
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
public function isFollowed(\Rector\Core\ValueObject\Application\File $file, \PhpParser\Node $node) : bool
|
2021-03-07 22:25:43 +01:00
|
|
|
{
|
2021-04-13 02:12:48 +02:00
|
|
|
$oldTokens = $file->getOldTokens();
|
2021-03-07 22:25:43 +01:00
|
|
|
$nextTokenPosition = $node->getEndTokenPos() + 1;
|
|
|
|
while (isset($oldTokens[$nextTokenPosition])) {
|
|
|
|
$currentToken = $oldTokens[$nextTokenPosition];
|
|
|
|
// only space
|
2021-06-21 19:24:28 +00:00
|
|
|
if (\is_array($currentToken) || \RectorPrefix20210621\Nette\Utils\Strings::match($currentToken, '#\\s+#')) {
|
2021-03-07 22:25:43 +01:00
|
|
|
++$nextTokenPosition;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// without comma
|
|
|
|
if ($currentToken === ')') {
|
2021-05-09 20:15:43 +00:00
|
|
|
return \false;
|
2021-03-07 22:25:43 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
return \true;
|
2021-03-07 22:25:43 +01:00
|
|
|
}
|
|
|
|
}
|