mirror of
https://github.com/danog/psalm.git
synced 2024-12-11 16:59:45 +01:00
33 lines
898 B
PHP
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;
|
|
}
|
|
}
|