Skip to content

Commit cf3ac4e

Browse files
committed
fix: new phpstan errors
1 parent 6718225 commit cf3ac4e

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

src/Query/Processor.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,27 @@ public function processSelect(Builder $query, $results): array
8181
return $results;
8282
}
8383

84+
/**
85+
* @inheritDoc
86+
*/
87+
public function processTables($results)
88+
{
89+
return array_map(function ($result) {
90+
$result = (object) $result;
91+
92+
return [
93+
'name' => $result->name,
94+
'schema' => $result->schema === '' ? $result->schema : null,
95+
'schema_qualified_name' => $result->schema !== '' ? $result->schema.'.'.$result->name : $result->name,
96+
'size' => isset($result->size) ? (int) $result->size : null,
97+
'comment' => null,
98+
'collation' => null,
99+
'engine' => null,
100+
'parent' => $result->parent,
101+
];
102+
}, $results);
103+
}
104+
84105
/**
85106
* @template TValue of mixed
86107
* @param TValue $value

src/Schema/Builder.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use Closure;
2121
use Colopl\Spanner\Connection;
22+
use Colopl\Spanner\Query\Processor;
2223
use Illuminate\Database\Schema\Builder as BaseBuilder;
2324

2425
/**
@@ -41,17 +42,15 @@ class Builder extends BaseBuilder
4142
public static $defaultMorphKeyType = 'uuid';
4243

4344
/**
44-
* @param null $schema
4545
* @inheritDoc Adds a parent key, for tracking interleaving
46-
*
47-
* @return list<array{ name: string, type: string, parent: string }>
46+
* @return list<array{name: string, schema: string|null, schema_qualified_name: string, size: int|null, comment: string|null, collation: string|null, engine: string|null, parent: string}>
4847
*/
4948
public function getTables($schema = null)
5049
{
51-
/** @var list<array{ name: string, type: string, parent: string }> */
52-
return $this->connection->select(
53-
$this->grammar->compileTables(null),
54-
);
50+
$results = $this->connection->select($this->grammar->compileTables($schema));
51+
assert(array_is_list($results));
52+
/** @phpstan-ignore return.type */
53+
return $this->connection->getPostProcessor()->processTables($results);
5554
}
5655

5756
/**

src/Schema/Grammar.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ class Grammar extends BaseGrammar
4747
*/
4848
public function compileTables($schema)
4949
{
50-
return 'select `table_name` as name, `table_type` as type, `parent_table_name` as parent from information_schema.tables where table_schema = \'\' and table_type = \'BASE TABLE\'';
50+
if ($schema === null || (is_array($schema) && count($schema) === 0)) {
51+
$schema = '';
52+
}
53+
54+
return
55+
'select `table_name` as name, `table_type` as type, `parent_table_name` as parent `table_schema` as `schema` ' .
56+
'from information_schema.tables where table_type = \'BASE TABLE\'' .
57+
'table_schema in (' . $this->quoteString($schema) . ')';
5158
}
5259

5360
/**

0 commit comments

Comments
 (0)