Skip to content

Commit

Permalink
Fix psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Jan 29, 2024
1 parent 2964f96 commit 8da62b7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ final class Command extends AbstractPdoCommand
{
public function insertWithReturningPks(string $table, array $columns): bool|array
{
/** @psalm-suppress RiskyTruthyFalsyComparison */
if (empty($this->db->getSchema()->getTableSchema($table)?->getPrimaryKey())) {
if (parent::insert($table, $columns)->execute() === 0) {
if ($this->insert($table, $columns)->execute() === 0) {
return false;
}

Expand Down
16 changes: 8 additions & 8 deletions src/DDLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,17 @@ private function buildAddCommentSql(string $comment, string $table, string $colu
throw new InvalidArgumentException("Table not found: $table");
}

$schemaName = $tableSchema->getSchemaName()
$schemaName = $tableSchema->getSchemaName() !== null
? "N'" . (string) $tableSchema->getSchemaName() . "'" : 'SCHEMA_NAME()';
$tableName = 'N' . (string) $this->quoter->quoteValue($tableSchema->getName());
$columnName = $column ? 'N' . (string) $this->quoter->quoteValue($column) : null;
$columnName = $column !== null ? 'N' . (string) $this->quoter->quoteValue($column) : null;
$comment = 'N' . (string) $this->quoter->quoteValue($comment);
$functionParams = "
@name = N'MS_description',
@value = $comment,
@level0type = N'SCHEMA', @level0name = $schemaName,
@level1type = N'TABLE', @level1name = $tableName"
. ($column ? ", @level2type = N'COLUMN', @level2name = $columnName" : '') . ';';
. ($column !== null ? ", @level2type = N'COLUMN', @level2name = $columnName" : '') . ';';

return "
IF NOT EXISTS (
Expand All @@ -210,7 +210,7 @@ private function buildAddCommentSql(string $comment, string $table, string $colu
N'MS_description',
'SCHEMA', $schemaName,
'TABLE', $tableName,
" . ($column ? "'COLUMN', $columnName " : ' DEFAULT, DEFAULT ') . "
" . ($column !== null ? "'COLUMN', $columnName " : ' DEFAULT, DEFAULT ') . "
)
)
EXEC sys.sp_addextendedproperty $functionParams
Expand Down Expand Up @@ -242,10 +242,10 @@ private function buildRemoveCommentSql(string $table, string $column = null): st
throw new InvalidArgumentException("Table not found: $table");
}

$schemaName = $tableSchema->getSchemaName()
$schemaName = $tableSchema->getSchemaName() !== null
? "N'" . (string) $tableSchema->getSchemaName() . "'" : 'SCHEMA_NAME()';
$tableName = 'N' . (string) $this->quoter->quoteValue($tableSchema->getName());
$columnName = $column ? 'N' . (string) $this->quoter->quoteValue($column) : null;
$columnName = $column !== null ? 'N' . (string) $this->quoter->quoteValue($column) : null;

return "
IF EXISTS (
Expand All @@ -254,14 +254,14 @@ private function buildRemoveCommentSql(string $table, string $column = null): st
N'MS_description',
'SCHEMA', $schemaName,
'TABLE', $tableName,
" . ($column ? "'COLUMN', $columnName " : ' DEFAULT, DEFAULT ') . "
" . ($column !== null ? "'COLUMN', $columnName " : ' DEFAULT, DEFAULT ') . "
)
)
EXEC sys.sp_dropextendedproperty
@name = N'MS_description',
@level0type = N'SCHEMA', @level0name = $schemaName,
@level1type = N'TABLE', @level1name = $tableName"
. ($column ? ", @level2type = N'COLUMN', @level2name = $columnName" : '') . ';';
. ($column !== null ? ", @level2type = N'COLUMN', @level2name = $columnName" : '') . ';';
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/DMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function insertWithReturningPks(string $table, QueryInterface|array $colu
$tableSchema = $this->schema->getTableSchema($table);
$primaryKeys = $tableSchema?->getPrimaryKey();

/** @psalm-suppress RiskyTruthyFalsyComparison */
if (empty($primaryKeys)) {
return $this->insert($table, $columns, $params);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function asString(): string
$server = "Server=$this->host;";
}

if (!empty($this->databaseName)) {
if ($this->databaseName !== null) {
$dsn = "$this->driver:" . $server . "Database=$this->databaseName";
} else {
$dsn = "$this->driver:" . $server;
Expand Down
2 changes: 1 addition & 1 deletion src/Quoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function quoteColumnName(string $name): string

public function getTableNameParts(string $name, bool $withColumn = false): array
{
if (preg_match_all('/([^.\[\]]+)|\[([^\[\]]+)]/', $name, $matches)) {
if (preg_match_all('/([^.\[\]]+)|\[([^\[\]]+)]/', $name, $matches) > 0) {
$parts = array_slice($matches[0], -4, 4);
} else {
$parts = [$name];
Expand Down
2 changes: 1 addition & 1 deletion src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ protected function findSchemaNames(): array
*/
protected function findTableComment(TableSchemaInterface $tableSchema): void
{
$schemaName = $tableSchema->getSchemaName()
$schemaName = $tableSchema->getSchemaName() !== null
? "N'" . (string) $tableSchema->getSchemaName() . "'" : 'SCHEMA_NAME()';
$tableName = 'N' . (string) $this->db->getQuoter()->quoteValue($tableSchema->getName());

Expand Down

0 comments on commit 8da62b7

Please sign in to comment.