mirror of
https://github.com/danog/psalm.git
synced 2024-12-13 09:47:29 +01:00
34 lines
898 B
PHP
34 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;
|
|
}
|
|
}
|