1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-14 10:17:33 +01:00
psalm/tests/Config/Plugin/Hook/SqlStringProvider.php
orklah f9fccb2b2d
implement DTO for plugins (#4881)
* implement DTO for plugins

* introduce EventHandler + reintroduce legacy API for plugins
2021-01-06 09:05:53 -05:00

29 lines
820 B
PHP

<?php
namespace Psalm\Test\Config\Plugin\Hook;
use Psalm\Plugin\EventHandler\StringInterpreterInterface;
use Psalm\Plugin\EventHandler\Event\StringInterpreterEvent;
use Psalm\Type\Atomic\TLiteralString;
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 \PhpMyAdmin\SqlParser\Parser($value);
if (!$parser->errors) {
return new StringProvider\TSqlSelectString($value);
}
} catch (\Throwable $e) {
// fall through
}
}
return null;
}
}