Skip to content

Commit

Permalink
Revert some changes and add suppression of `RiskyTruthyFalsyCompariso…
Browse files Browse the repository at this point in the history
…n` to config
  • Loading branch information
Tigrov committed Jan 29, 2024
1 parent 6e0aeef commit 58df64c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<RiskyTruthyFalsyComparison errorLevel="suppress" />
</issueHandlers>
</psalm>
1 change: 0 additions & 1 deletion src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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 ($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() !== null
$schemaName = $tableSchema->getSchemaName()
? "N'" . (string) $tableSchema->getSchemaName() . "'" : 'SCHEMA_NAME()';
$tableName = 'N' . (string) $this->quoter->quoteValue($tableSchema->getName());
$columnName = $column !== null ? 'N' . (string) $this->quoter->quoteValue($column) : null;
$columnName = $column ? '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 !== null ? ", @level2type = N'COLUMN', @level2name = $columnName" : '') . ';';
. ($column ? ", @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 !== null ? "'COLUMN', $columnName " : ' DEFAULT, DEFAULT ') . "
" . ($column ? "'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() !== null
$schemaName = $tableSchema->getSchemaName()
? "N'" . (string) $tableSchema->getSchemaName() . "'" : 'SCHEMA_NAME()';
$tableName = 'N' . (string) $this->quoter->quoteValue($tableSchema->getName());
$columnName = $column !== null ? 'N' . (string) $this->quoter->quoteValue($column) : null;
$columnName = $column ? '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 !== null ? "'COLUMN', $columnName " : ' DEFAULT, DEFAULT ') . "
" . ($column ? "'COLUMN', $columnName " : ' DEFAULT, DEFAULT ') . "
)
)
EXEC sys.sp_dropextendedproperty
@name = N'MS_description',
@level0type = N'SCHEMA', @level0name = $schemaName,
@level1type = N'TABLE', @level1name = $tableName"
. ($column !== null ? ", @level2type = N'COLUMN', @level2name = $columnName" : '') . ';';
. ($column ? ", @level2type = N'COLUMN', @level2name = $columnName" : '') . ';';
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/DMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ 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 ($this->databaseName !== null && $this->databaseName !== '') {
if (!empty($this->databaseName)) {
$dsn = "$this->driver:" . $server . "Database=$this->databaseName";
} else {
$dsn = "$this->driver:" . $server;
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() !== null
$schemaName = $tableSchema->getSchemaName()
? "N'" . (string) $tableSchema->getSchemaName() . "'" : 'SCHEMA_NAME()';
$tableName = 'N' . (string) $this->db->getQuoter()->quoteValue($tableSchema->getName());

Expand Down

0 comments on commit 58df64c

Please sign in to comment.