1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-04 18:48:03 +01:00
psalm/tests/Config/Plugin/Hook/SqlStringProvider.php

32 lines
846 B
PHP
Raw Normal View History

<?php
namespace Psalm\Test\Config\Plugin\Hook;
2021-12-03 20:11:20 +01:00
use PhpMyAdmin\SqlParser\Parser;
use Psalm\Plugin\EventHandler\Event\StringInterpreterEvent;
2021-06-08 04:55:21 +02:00
use Psalm\Plugin\EventHandler\StringInterpreterInterface;
use Psalm\Type\Atomic\TLiteralString;
2021-12-03 21:40:18 +01:00
use Throwable;
2021-06-08 04:55:21 +02:00
use function stripos;
class SqlStringProvider implements StringInterpreterInterface
{
public static function getTypeFromValue(StringInterpreterEvent $event) : ?TLiteralString
{
$value = $event->getValue();
if (stripos($value, 'select ') !== false) {
try {
2021-12-03 20:11:20 +01:00
$parser = new Parser($value);
if (!$parser->errors) {
return new StringProvider\TSqlSelectString($value);
}
2021-12-03 21:40:18 +01:00
} catch (Throwable $e) {
// fall through
}
}
return null;
}
}