diff --git a/CHANGELOG.md b/CHANGELOG.md index f92de014..99610dd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 1.1.1 under development -- no changes in this release. +- Enh #281: Remove unused code in `Command` class (@vjik) ## 1.1.0 November 12, 2023 diff --git a/src/AbstractTokenizer.php b/src/AbstractTokenizer.php index 7febb90b..effa5a31 100644 --- a/src/AbstractTokenizer.php +++ b/src/AbstractTokenizer.php @@ -101,7 +101,6 @@ public function tokenize(): SqlToken $token[] = (new SqlToken())->type(SqlToken::TYPE_STATEMENT); $this->tokenStack->push($token[0]); - /** @psalm-var SqlToken */ $this->currentToken = $this->tokenStack->top(); $length = 0; diff --git a/src/Builder/JsonExpressionBuilder.php b/src/Builder/JsonExpressionBuilder.php index 73ef7c91..219d88e0 100644 --- a/src/Builder/JsonExpressionBuilder.php +++ b/src/Builder/JsonExpressionBuilder.php @@ -41,7 +41,6 @@ public function __construct(private QueryBuilderInterface $queryBuilder) */ public function build(ExpressionInterface $expression, array &$params = []): string { - /** @psalm-var mixed $value */ $value = $expression->getValue(); if ($value instanceof QueryInterface) { diff --git a/src/Command.php b/src/Command.php index aa8176dc..6996cd7f 100644 --- a/src/Command.php +++ b/src/Command.php @@ -41,7 +41,6 @@ public function insertWithReturningPks(string $table, array $columns): bool|arra continue; } - /** @psalm-var mixed */ $result[$name] = $columns[$name] ?? $tableSchema?->getColumn($name)?->getDefaultValue(); } @@ -72,7 +71,6 @@ public function execute(): int { $sql = $this->getSql(); - /** @psalm-var array $params */ $params = $this->params; $statements = $this->splitStatements($sql, $params); @@ -83,11 +81,8 @@ public function execute(): int $result = 0; - /** @psalm-var array> $statements */ foreach ($statements as $statement) { [$statementSql, $statementParams] = $statement; - $statementSql = is_string($statementSql) ? $statementSql : ''; - $statementParams = is_array($statementParams) ? $statementParams : []; $this->setSql($statementSql)->bindValues($statementParams); $result = parent::execute(); } @@ -111,7 +106,6 @@ protected function queryInternal(int $queryMode): mixed { $sql = $this->getSql(); - /** @psalm-var array $params */ $params = $this->params; $statements = $this->splitStatements($sql, $params); @@ -122,14 +116,7 @@ protected function queryInternal(int $queryMode): mixed [$lastStatementSql, $lastStatementParams] = array_pop($statements); - /** - * @psalm-var array $statements - */ foreach ($statements as $statement) { - /** - * @psalm-var string $statementSql - * @psalm-var array $statementParams - */ [$statementSql, $statementParams] = $statement; $this->setSql($statementSql)->bindValues($statementParams); parent::execute(); @@ -137,7 +124,6 @@ protected function queryInternal(int $queryMode): mixed $this->setSql($lastStatementSql)->bindValues($lastStatementParams); - /** @psalm-var string $result */ $result = parent::queryInternal($queryMode); $this->setSql($sql)->bindValues($params); @@ -155,8 +141,6 @@ protected function queryInternal(int $queryMode): mixed * * @return array|bool List of SQL statements or `false` if there's a single statement. * - * @psalm-param array $params - * * @psalm-return false|list */ private function splitStatements(string $sql, array $params): bool|array @@ -186,8 +170,6 @@ private function splitStatements(string $sql, array $params): bool|array /** * Returns named bindings used in the specified statement token. - * - * @psalm-param array $params */ private function extractUsedParams(SqlToken $statement, array $params): array { diff --git a/src/DMLQueryBuilder.php b/src/DMLQueryBuilder.php index 798697a0..e772a598 100644 --- a/src/DMLQueryBuilder.php +++ b/src/DMLQueryBuilder.php @@ -56,7 +56,7 @@ public function upsert( bool|array $updateColumns, array &$params ): string { - /** @psalm-var Constraint[] $constraints */ + /** @var Constraint[] $constraints */ $constraints = []; [$uniqueNames, $insertNames, $updateNames] = $this->prepareUpsertColumns( diff --git a/src/DQLQueryBuilder.php b/src/DQLQueryBuilder.php index 753e9504..1faa2b0c 100644 --- a/src/DQLQueryBuilder.php +++ b/src/DQLQueryBuilder.php @@ -46,7 +46,6 @@ public function build(QueryInterface $query, array $params = []): array $sql = $this->buildOrderByAndLimit($sql, $orderBy, $query->getLimit(), $query->getOffset()); if (!empty($orderBy)) { - /** @psalm-var array $orderBy */ foreach ($orderBy as $expression) { if ($expression instanceof ExpressionInterface) { $this->buildExpression($expression, $params); @@ -57,7 +56,6 @@ public function build(QueryInterface $query, array $params = []): array $groupBy = $query->getGroupBy(); if (!empty($groupBy)) { - /** @psalm-var array $groupBy */ foreach ($groupBy as $expression) { if ($expression instanceof ExpressionInterface) { $this->buildExpression($expression, $params); diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 3aa810b1..4f867bd2 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -14,9 +14,7 @@ final class QueryBuilder extends AbstractQueryBuilder { /** - * @var array Mapping from abstract column types (keys) to physical column types (values). - * - * @psalm-var string[] $typeMap + * @var string[] Mapping from abstract column types (keys) to physical column types (values). */ protected array $typeMap = [ SchemaInterface::TYPE_PK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', diff --git a/src/Schema.php b/src/Schema.php index ef856721..57134f1a 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -72,9 +72,7 @@ final class Schema extends AbstractPdoSchema { /** - * @var array Mapping from physical column types (keys) to abstract column types (values). - * - * @psalm-var array $typeMap + * @var string[] Mapping from physical column types (keys) to abstract column types (values). */ private array $typeMap = [ 'tinyint' => self::TYPE_TINYINT, @@ -218,7 +216,6 @@ protected function loadTableForeignKeys(string $tableName): array $primaryKey = $this->getTablePrimaryKey($table); if ($primaryKey !== null) { - /** @psalm-var string $primaryKeyColumnName */ foreach ((array) $primaryKey->getColumnNames() as $i => $primaryKeyColumnName) { $foreignKey[$i]['to'] = $primaryKeyColumnName; } @@ -303,7 +300,6 @@ protected function loadTableChecks(string $tableName): array $sql = ($sql === false || $sql === null) ? '' : (string) $sql; - /** @psalm-var SqlToken[]|SqlToken[][]|SqlToken[][][] $code */ $code = (new SqlTokenizer($sql))->tokenize(); $pattern = (new SqlTokenizer('any CREATE any TABLE any()'))->tokenize(); $result = []; @@ -363,7 +359,6 @@ protected function loadTableDefaultValues(string $tableName): array */ protected function findColumns(TableSchemaInterface $table): bool { - /** @psalm-var ColumnInfo[] $columns */ $columns = $this->getPragmaTableInfo($table->getName()); $jsonColumns = $this->getJsonColumns($table); @@ -444,7 +439,6 @@ public function findUniqueIndexes(TableSchemaInterface $table): array foreach ($indexList as $index) { $indexName = $index['name']; - /** @psalm-var IndexInfo[] $indexInfo */ $indexInfo = $this->getPragmaIndexInfo($index['name']); if ($index['unique']) { @@ -551,6 +545,8 @@ private function normalizeDefaultValue(string|null $defaultValue, ColumnSchemaIn * @throws Throwable * * @return array The table columns info. + * + * @psalm-return ColumnInfo[] $tableColumns; */ private function loadTableColumnsInfo(string $tableName): array { @@ -558,6 +554,7 @@ private function loadTableColumnsInfo(string $tableName): array /** @psalm-var ColumnInfo[] $tableColumns */ $tableColumns = $this->normalizeRowKeyCase($tableColumns, true); + /** @psalm-var ColumnInfo[] */ return DbArrayHelper::index($tableColumns, 'cid'); } @@ -585,7 +582,6 @@ private function loadTableConstraints(string $tableName, string $returnType): Co ]; foreach ($indexes as $index) { - /** @psalm-var IndexInfo[] $columns */ $columns = $this->getPragmaIndexInfo($index['name']); if ($index['origin'] === 'pk') { @@ -611,8 +607,6 @@ private function loadTableConstraints(string $tableName, string $returnType): Co * Extra check for PK in case of `INTEGER PRIMARY KEY` with ROWID. * * @link https://www.sqlite.org/lang_createtable.html#primkeyconst - * - * @psalm-var ColumnInfo[] $tableColumns */ $tableColumns = $this->loadTableColumnsInfo($tableName); @@ -659,16 +653,18 @@ private function getPragmaForeignKeyList(string $tableName): array * @throws Exception * @throws InvalidConfigException * @throws Throwable + * + * @psalm-return IndexInfo[] */ private function getPragmaIndexInfo(string $name): array { $column = $this->db ->createCommand('PRAGMA INDEX_INFO(' . (string) $this->db->getQuoter()->quoteValue($name) . ')') ->queryAll(); - /** @psalm-var IndexInfo[] $column */ $column = $this->normalizeRowKeyCase($column, true); DbArrayHelper::multisort($column, 'seqno'); + /** @psalm-var IndexInfo[] $column */ return $column; } @@ -688,9 +684,12 @@ private function getPragmaIndexList(string $tableName): array * @throws Exception * @throws InvalidConfigException * @throws Throwable + * + * @psalm-return ColumnInfo[] */ private function getPragmaTableInfo(string $tableName): array { + /** @psalm-var ColumnInfo[] */ return $this->db->createCommand( 'PRAGMA TABLE_INFO(' . $this->db->getQuoter()->quoteSimpleTableName($tableName) . ')' )->queryAll(); @@ -703,7 +702,7 @@ private function getPragmaTableInfo(string $tableName): array */ protected function findViewNames(string $schema = ''): array { - /** @psalm-var string[][] $views */ + /** @var string[][] $views */ $views = $this->db->createCommand( <<