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

33 lines
898 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;
2021-12-04 21:55:53 +01:00
use Psalm\Test\Config\Plugin\Hook\StringProvider\TSqlSelectString;
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) {
2021-12-04 21:55:53 +01:00
return new TSqlSelectString($value);
}
2021-12-03 21:40:18 +01:00
} catch (Throwable $e) {
// fall through
}
}
return null;
}
}