Skip to content

Commit b695b92

Browse files
committed
Resolve Psalm error
1 parent 5bb9ec9 commit b695b92

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

src/Parser/SQLParser.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
namespace Vimeo\MysqlEngine\Parser;
33

44
use Vimeo\MysqlEngine\TokenType;
5-
use Vimeo\MysqlEngine\Query\{
6-
SelectQuery,
5+
use Vimeo\MysqlEngine\Query\{SelectQuery,
76
DeleteQuery,
7+
ShowIndexQuery,
88
TruncateQuery,
99
InsertQuery,
1010
UpdateQuery,
1111
DropTableQuery,
12-
ShowTablesQuery
13-
};
12+
ShowTablesQuery};
1413

1514
final class SQLParser
1615
{
@@ -142,10 +141,11 @@ final class SQLParser
142141
'TABLES' => true,
143142
];
144143

144+
/** @var array<SelectQuery|InsertQuery|UpdateQuery|TruncateQuery|DeleteQuery|DropTableQuery|ShowTablesQuery|ShowIndexQuery> */
145145
private static $cache = [];
146146

147147
/**
148-
* @return SelectQuery|InsertQuery|UpdateQuery|TruncateQuery|DeleteQuery|DropTableQuery|ShowTablesQuery
148+
* @return SelectQuery|InsertQuery|UpdateQuery|TruncateQuery|DeleteQuery|DropTableQuery|ShowTablesQuery|ShowIndexQuery
149149
*/
150150
public static function parse(string $sql)
151151
{
@@ -157,7 +157,7 @@ public static function parse(string $sql)
157157
}
158158

159159
/**
160-
* @return SelectQuery|InsertQuery|UpdateQuery|TruncateQuery|DeleteQuery|DropTableQuery|ShowTablesQuery
160+
* @return SelectQuery|InsertQuery|UpdateQuery|TruncateQuery|DeleteQuery|DropTableQuery|ShowTablesQuery|ShowIndexQuery
161161
*/
162162
private static function parseImpl(string $sql)
163163
{

src/Parser/ShowParser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private function parseShowIndex(): ShowIndexQuery
8888
}
8989
$this->pointer++;
9090
$token = $this->tokens[$this->pointer];
91-
if ($token === null || $token->type !== TokenType::IDENTIFIER) {
91+
if ($token->type !== TokenType::IDENTIFIER) {
9292
throw new ParserException("Expected table name after FROM");
9393
}
9494

src/Processor/ShowIndexProcessor.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Vimeo\MysqlEngine\FakePdoInterface;
88
use Vimeo\MysqlEngine\Query\ShowIndexQuery;
99
use Vimeo\MysqlEngine\Schema\Column;
10+
use function PHPUnit\Framework\assertIsArray;
1011

1112
class ShowIndexProcessor extends Processor
1213
{
@@ -20,15 +21,18 @@ public static function process(
2021
$database,
2122
$table
2223
);
24+
if (!$table_definition) {
25+
return new QueryResult([], []);
26+
}
2327
$columns = [
2428
'Table' => new Column\Varchar(255),
2529
'Non_unique' => new Column\TinyInt(true, 1),
2630
'Key_name' => new Column\Varchar(255),
27-
'Seq_in_index' => new Column\intColumn(true, 4),
31+
'Seq_in_index' => new Column\IntColumn(true, 4),
2832
'Column_name' => new Column\Varchar(255),
2933
'Collation' => new Column\Char(1),
30-
'Cardinality' => new Column\intColumn(true, 4),
31-
'Sub_part' => new Column\intColumn(true, 4),
34+
'Cardinality' => new Column\IntColumn(true, 4),
35+
'Sub_part' => new Column\IntColumn(true, 4),
3236
'Packed' => new Column\TinyInt(true, 1),
3337
'Null' => new Column\Varchar(3),
3438
'Index_type' => new Column\Varchar(5),
@@ -42,7 +46,7 @@ public static function process(
4246
'Table' => $table_definition->name,
4347
'Non_unique' => $index->type === 'INDEX' ? 1 : 0,
4448
'Key_name' => $name,
45-
'Seq_in_index' => $i + 1,
49+
'Seq_in_index' => 1 + (int) $i,
4650
'Column_name' => $column,
4751
// because Index does not have "direction" (in the $cols of CreateIndex)
4852
'Collation' => null,

src/Query/ShowIndexQuery.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace Vimeo\MysqlEngine\Query;
33

4+
use Vimeo\MysqlEngine\Query\Expression\Expression;
5+
46
final class ShowIndexQuery
57
{
68
/**

src/Schema/Index.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ class Index
99
public $type;
1010

1111
/**
12-
* @var array
12+
* @var array<string>
1313
*/
1414
public $columns;
1515

1616
/**
1717
* @param 'INDEX'|'UNIQUE'|'PRIMARY'|'FULLTEXT'|'SPATIAL' $type
18+
* @param array<string> $columns
1819
*/
1920
public function __construct(
2021
string $type,

0 commit comments

Comments
 (0)