2019-05-21 05:14:41 +02:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2019-05-21 05:14:41 +02:00
|
|
|
namespace Psalm\Test\Config\Plugin\Hook;
|
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
use PhpMyAdmin\SqlParser\Parser;
|
2021-01-06 15:05:53 +01:00
|
|
|
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;
|
2019-05-21 05:14:41 +02:00
|
|
|
use Psalm\Type\Atomic\TLiteralString;
|
2021-12-03 21:40:18 +01:00
|
|
|
use Throwable;
|
2021-06-08 04:55:21 +02:00
|
|
|
|
2019-06-26 22:52:29 +02:00
|
|
|
use function stripos;
|
2019-05-21 05:14:41 +02:00
|
|
|
|
|
|
|
class SqlStringProvider implements StringInterpreterInterface
|
|
|
|
{
|
2021-12-05 18:51:26 +01:00
|
|
|
public static function getTypeFromValue(StringInterpreterEvent $event): ?TLiteralString
|
2019-05-21 05:14:41 +02:00
|
|
|
{
|
2021-01-06 15:05:53 +01:00
|
|
|
$value = $event->getValue();
|
2019-05-21 05:14:41 +02:00
|
|
|
if (stripos($value, 'select ') !== false) {
|
|
|
|
try {
|
2021-12-03 20:11:20 +01:00
|
|
|
$parser = new Parser($value);
|
2019-05-21 05:14:41 +02:00
|
|
|
|
|
|
|
if (!$parser->errors) {
|
2021-12-04 21:55:53 +01:00
|
|
|
return new TSqlSelectString($value);
|
2019-05-21 05:14:41 +02:00
|
|
|
}
|
2021-12-03 21:40:18 +01:00
|
|
|
} catch (Throwable $e) {
|
2019-05-21 05:14:41 +02:00
|
|
|
// fall through
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|