1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 16:59:45 +01:00
psalm/tests/Config/Plugin/Hook/SqlStringProvider.php
2021-12-04 21:55:53 +01:00

33 lines
898 B
PHP

<?php
namespace Psalm\Test\Config\Plugin\Hook;
use PhpMyAdmin\SqlParser\Parser;
use Psalm\Plugin\EventHandler\Event\StringInterpreterEvent;
use Psalm\Plugin\EventHandler\StringInterpreterInterface;
use Psalm\Test\Config\Plugin\Hook\StringProvider\TSqlSelectString;
use Psalm\Type\Atomic\TLiteralString;
use Throwable;
use function stripos;
class SqlStringProvider implements StringInterpreterInterface
{
public static function getTypeFromValue(StringInterpreterEvent $event) : ?TLiteralString
{
$value = $event->getValue();
if (stripos($value, 'select ') !== false) {
try {
$parser = new Parser($value);
if (!$parser->errors) {
return new TSqlSelectString($value);
}
} catch (Throwable $e) {
// fall through
}
}
return null;
}
}