1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 17:52:45 +01:00
psalm/tests/Config/Plugin/Hook/SqlStringProvider.php

27 lines
699 B
PHP
Raw Normal View History

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