Skip to content

Commit e3d9164

Browse files
authored
Remove unused code in Command class + Cleanup psalm annotations (#281)
1 parent 8b652d1 commit e3d9164

File tree

8 files changed

+14
-39
lines changed

8 files changed

+14
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 1.1.1 under development
44

5-
- no changes in this release.
5+
- Enh #281: Remove unused code in `Command` class (@vjik)
66

77
## 1.1.0 November 12, 2023
88

src/AbstractTokenizer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public function tokenize(): SqlToken
101101
$token[] = (new SqlToken())->type(SqlToken::TYPE_STATEMENT);
102102

103103
$this->tokenStack->push($token[0]);
104-
/** @psalm-var SqlToken */
105104
$this->currentToken = $this->tokenStack->top();
106105
$length = 0;
107106

src/Builder/JsonExpressionBuilder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public function __construct(private QueryBuilderInterface $queryBuilder)
4141
*/
4242
public function build(ExpressionInterface $expression, array &$params = []): string
4343
{
44-
/** @psalm-var mixed $value */
4544
$value = $expression->getValue();
4645

4746
if ($value instanceof QueryInterface) {

src/Command.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public function insertWithReturningPks(string $table, array $columns): bool|arra
4141
continue;
4242
}
4343

44-
/** @psalm-var mixed */
4544
$result[$name] = $columns[$name] ?? $tableSchema?->getColumn($name)?->getDefaultValue();
4645
}
4746

@@ -72,7 +71,6 @@ public function execute(): int
7271
{
7372
$sql = $this->getSql();
7473

75-
/** @psalm-var array<string, string> $params */
7674
$params = $this->params;
7775

7876
$statements = $this->splitStatements($sql, $params);
@@ -83,11 +81,8 @@ public function execute(): int
8381

8482
$result = 0;
8583

86-
/** @psalm-var array<array-key, array<array-key, string|array>> $statements */
8784
foreach ($statements as $statement) {
8885
[$statementSql, $statementParams] = $statement;
89-
$statementSql = is_string($statementSql) ? $statementSql : '';
90-
$statementParams = is_array($statementParams) ? $statementParams : [];
9186
$this->setSql($statementSql)->bindValues($statementParams);
9287
$result = parent::execute();
9388
}
@@ -111,7 +106,6 @@ protected function queryInternal(int $queryMode): mixed
111106
{
112107
$sql = $this->getSql();
113108

114-
/** @psalm-var array<string, string> $params */
115109
$params = $this->params;
116110

117111
$statements = $this->splitStatements($sql, $params);
@@ -122,22 +116,14 @@ protected function queryInternal(int $queryMode): mixed
122116

123117
[$lastStatementSql, $lastStatementParams] = array_pop($statements);
124118

125-
/**
126-
* @psalm-var array<array-key, array> $statements
127-
*/
128119
foreach ($statements as $statement) {
129-
/**
130-
* @psalm-var string $statementSql
131-
* @psalm-var array $statementParams
132-
*/
133120
[$statementSql, $statementParams] = $statement;
134121
$this->setSql($statementSql)->bindValues($statementParams);
135122
parent::execute();
136123
}
137124

138125
$this->setSql($lastStatementSql)->bindValues($lastStatementParams);
139126

140-
/** @psalm-var string $result */
141127
$result = parent::queryInternal($queryMode);
142128

143129
$this->setSql($sql)->bindValues($params);
@@ -155,8 +141,6 @@ protected function queryInternal(int $queryMode): mixed
155141
*
156142
* @return array|bool List of SQL statements or `false` if there's a single statement.
157143
*
158-
* @psalm-param array<string, string> $params
159-
*
160144
* @psalm-return false|list<array{0: string, 1: array}>
161145
*/
162146
private function splitStatements(string $sql, array $params): bool|array
@@ -186,8 +170,6 @@ private function splitStatements(string $sql, array $params): bool|array
186170

187171
/**
188172
* Returns named bindings used in the specified statement token.
189-
*
190-
* @psalm-param array<string, string> $params
191173
*/
192174
private function extractUsedParams(SqlToken $statement, array $params): array
193175
{

src/DMLQueryBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function upsert(
5656
bool|array $updateColumns,
5757
array &$params
5858
): string {
59-
/** @psalm-var Constraint[] $constraints */
59+
/** @var Constraint[] $constraints */
6060
$constraints = [];
6161

6262
[$uniqueNames, $insertNames, $updateNames] = $this->prepareUpsertColumns(

src/DQLQueryBuilder.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public function build(QueryInterface $query, array $params = []): array
4646
$sql = $this->buildOrderByAndLimit($sql, $orderBy, $query->getLimit(), $query->getOffset());
4747

4848
if (!empty($orderBy)) {
49-
/** @psalm-var array<string|ExpressionInterface> $orderBy */
5049
foreach ($orderBy as $expression) {
5150
if ($expression instanceof ExpressionInterface) {
5251
$this->buildExpression($expression, $params);
@@ -57,7 +56,6 @@ public function build(QueryInterface $query, array $params = []): array
5756
$groupBy = $query->getGroupBy();
5857

5958
if (!empty($groupBy)) {
60-
/** @psalm-var array<string|ExpressionInterface> $groupBy */
6159
foreach ($groupBy as $expression) {
6260
if ($expression instanceof ExpressionInterface) {
6361
$this->buildExpression($expression, $params);

src/QueryBuilder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
final class QueryBuilder extends AbstractQueryBuilder
1515
{
1616
/**
17-
* @var array Mapping from abstract column types (keys) to physical column types (values).
18-
*
19-
* @psalm-var string[] $typeMap
17+
* @var string[] Mapping from abstract column types (keys) to physical column types (values).
2018
*/
2119
protected array $typeMap = [
2220
SchemaInterface::TYPE_PK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',

src/Schema.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@
7272
final class Schema extends AbstractPdoSchema
7373
{
7474
/**
75-
* @var array Mapping from physical column types (keys) to abstract column types (values).
76-
*
77-
* @psalm-var array<array-key, string> $typeMap
75+
* @var string[] Mapping from physical column types (keys) to abstract column types (values).
7876
*/
7977
private array $typeMap = [
8078
'tinyint' => self::TYPE_TINYINT,
@@ -218,7 +216,6 @@ protected function loadTableForeignKeys(string $tableName): array
218216
$primaryKey = $this->getTablePrimaryKey($table);
219217

220218
if ($primaryKey !== null) {
221-
/** @psalm-var string $primaryKeyColumnName */
222219
foreach ((array) $primaryKey->getColumnNames() as $i => $primaryKeyColumnName) {
223220
$foreignKey[$i]['to'] = $primaryKeyColumnName;
224221
}
@@ -303,7 +300,6 @@ protected function loadTableChecks(string $tableName): array
303300

304301
$sql = ($sql === false || $sql === null) ? '' : (string) $sql;
305302

306-
/** @psalm-var SqlToken[]|SqlToken[][]|SqlToken[][][] $code */
307303
$code = (new SqlTokenizer($sql))->tokenize();
308304
$pattern = (new SqlTokenizer('any CREATE any TABLE any()'))->tokenize();
309305
$result = [];
@@ -363,7 +359,6 @@ protected function loadTableDefaultValues(string $tableName): array
363359
*/
364360
protected function findColumns(TableSchemaInterface $table): bool
365361
{
366-
/** @psalm-var ColumnInfo[] $columns */
367362
$columns = $this->getPragmaTableInfo($table->getName());
368363
$jsonColumns = $this->getJsonColumns($table);
369364

@@ -444,7 +439,6 @@ public function findUniqueIndexes(TableSchemaInterface $table): array
444439

445440
foreach ($indexList as $index) {
446441
$indexName = $index['name'];
447-
/** @psalm-var IndexInfo[] $indexInfo */
448442
$indexInfo = $this->getPragmaIndexInfo($index['name']);
449443

450444
if ($index['unique']) {
@@ -551,13 +545,16 @@ private function normalizeDefaultValue(string|null $defaultValue, ColumnSchemaIn
551545
* @throws Throwable
552546
*
553547
* @return array The table columns info.
548+
*
549+
* @psalm-return ColumnInfo[] $tableColumns;
554550
*/
555551
private function loadTableColumnsInfo(string $tableName): array
556552
{
557553
$tableColumns = $this->getPragmaTableInfo($tableName);
558554
/** @psalm-var ColumnInfo[] $tableColumns */
559555
$tableColumns = $this->normalizeRowKeyCase($tableColumns, true);
560556

557+
/** @psalm-var ColumnInfo[] */
561558
return DbArrayHelper::index($tableColumns, 'cid');
562559
}
563560

@@ -585,7 +582,6 @@ private function loadTableConstraints(string $tableName, string $returnType): Co
585582
];
586583

587584
foreach ($indexes as $index) {
588-
/** @psalm-var IndexInfo[] $columns */
589585
$columns = $this->getPragmaIndexInfo($index['name']);
590586

591587
if ($index['origin'] === 'pk') {
@@ -611,8 +607,6 @@ private function loadTableConstraints(string $tableName, string $returnType): Co
611607
* Extra check for PK in case of `INTEGER PRIMARY KEY` with ROWID.
612608
*
613609
* @link https://www.sqlite.org/lang_createtable.html#primkeyconst
614-
*
615-
* @psalm-var ColumnInfo[] $tableColumns
616610
*/
617611
$tableColumns = $this->loadTableColumnsInfo($tableName);
618612

@@ -659,16 +653,18 @@ private function getPragmaForeignKeyList(string $tableName): array
659653
* @throws Exception
660654
* @throws InvalidConfigException
661655
* @throws Throwable
656+
*
657+
* @psalm-return IndexInfo[]
662658
*/
663659
private function getPragmaIndexInfo(string $name): array
664660
{
665661
$column = $this->db
666662
->createCommand('PRAGMA INDEX_INFO(' . (string) $this->db->getQuoter()->quoteValue($name) . ')')
667663
->queryAll();
668-
/** @psalm-var IndexInfo[] $column */
669664
$column = $this->normalizeRowKeyCase($column, true);
670665
DbArrayHelper::multisort($column, 'seqno');
671666

667+
/** @psalm-var IndexInfo[] $column */
672668
return $column;
673669
}
674670

@@ -688,9 +684,12 @@ private function getPragmaIndexList(string $tableName): array
688684
* @throws Exception
689685
* @throws InvalidConfigException
690686
* @throws Throwable
687+
*
688+
* @psalm-return ColumnInfo[]
691689
*/
692690
private function getPragmaTableInfo(string $tableName): array
693691
{
692+
/** @psalm-var ColumnInfo[] */
694693
return $this->db->createCommand(
695694
'PRAGMA TABLE_INFO(' . $this->db->getQuoter()->quoteSimpleTableName($tableName) . ')'
696695
)->queryAll();
@@ -703,7 +702,7 @@ private function getPragmaTableInfo(string $tableName): array
703702
*/
704703
protected function findViewNames(string $schema = ''): array
705704
{
706-
/** @psalm-var string[][] $views */
705+
/** @var string[][] $views */
707706
$views = $this->db->createCommand(
708707
<<<SQL
709708
SELECT name as view FROM sqlite_master WHERE type = 'view' AND name NOT LIKE 'sqlite_%'

0 commit comments

Comments
 (0)