2019-05-21 05:14:41 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Test\Config\Plugin\Hook;
|
|
|
|
|
|
|
|
use Psalm\Plugin\Hook\StringInterpreterInterface;
|
|
|
|
use Psalm\Type\Atomic\TLiteralString;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function stripos;
|
2019-05-21 05:14:41 +02:00
|
|
|
|
|
|
|
class SqlStringProvider implements StringInterpreterInterface
|
|
|
|
{
|
|
|
|
public static function getTypeFromValue(string $value) : ?TLiteralString
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|