Skip to content

Commit

Permalink
Minor refactoring of DDLQueryBuilder and Schema + Fix psalm issues (
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Feb 3, 2024
1 parent fa3c327 commit 9fae32a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/static.yml
Expand Up @@ -39,6 +39,7 @@ jobs:
- '8.0'
- '8.1'
- '8.2'
- '8.3'

steps:
- name: Checkout.
Expand Down Expand Up @@ -70,4 +71,9 @@ jobs:
run: composer update --no-interaction --no-progress --optimize-autoloader --ansi

- name: Static analysis.
if: ${{ matrix.php != '8.0' }}
run: vendor/bin/psalm --config=${{ inputs.psalm-config }} --shepherd --stats --output-format=github --php-version=${{ matrix.php }}

- name: Static analysis.
if: ${{ matrix.php == '8.0' }}
run: vendor/bin/psalm --config=psalm4.xml --shepherd --stats --output-format=github --php-version=${{ matrix.php }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

- Enh #312: Change property `Schema::$typeMap` to constant `Schema::TYPE_MAP` (@Tigrov)
- Bug #314: Fix `Command::insertWithReturningPks()` method for empty values (@Tigrov)
- Enh #319: Minor refactoring of `DDLQueryBuilder` and `Schema` (@Tigrov)

## 1.1.0 November 12, 2023

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -35,7 +35,7 @@
"rector/rector": "^0.19",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.3|^5.6",
"vimeo/psalm": "^4.30|^5.20",
"yiisoft/aliases": "^2.0",
"yiisoft/log-target-file": "^2.0",
"yiisoft/cache-file": "^3.1",
Expand Down
3 changes: 3 additions & 0 deletions psalm.xml
Expand Up @@ -14,4 +14,7 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<RiskyTruthyFalsyComparison errorLevel="suppress" />
</issueHandlers>
</psalm>
17 changes: 17 additions & 0 deletions psalm4.xml
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedBaselineEntry="true"
findUnusedCode="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
6 changes: 3 additions & 3 deletions src/DDLQueryBuilder.php
Expand Up @@ -84,9 +84,9 @@ public function createIndex(
string $indexType = null,
string $indexMethod = null
): string {
return 'CREATE ' . ($indexType ? ($indexType . ' ') : '') . 'INDEX '
return 'CREATE ' . (!empty($indexType) ? $indexType . ' ' : '') . 'INDEX '
. $this->quoter->quoteTableName($name)
. ($indexMethod !== null ? " USING $indexMethod" : '')
. (!empty($indexMethod) ? " USING $indexMethod" : '')
. ' ON ' . $this->quoter->quoteTableName($table)
. ' (' . $this->queryBuilder->buildColumns($columns) . ')';
}
Expand Down Expand Up @@ -180,7 +180,7 @@ public function getColumnDefinition(string $table, string $column): string
return '';
}

if (preg_match_all('/^\s*([`"])(.*?)\\1\s+(.*?),?$/m', $sql, $matches)) {
if (preg_match_all('/^\s*([`"])(.*?)\\1\s+(.*?),?$/m', $sql, $matches) > 0) {
foreach ($matches[2] as $i => $c) {
if ($c === $column) {
$result = $matches[3][$i];
Expand Down
6 changes: 3 additions & 3 deletions src/Schema.php
Expand Up @@ -161,7 +161,7 @@ public function findUniqueIndexes(TableSchemaInterface $table): array
$uniqueIndexes = [];
$regexp = '/UNIQUE KEY\s+[`"](.+)[`"]\s*\(([`"].+[`"])+\)/mi';

if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) {
if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER) > 0) {
foreach ($matches as $match) {
$indexName = $match[1];
$indexColumns = array_map('trim', preg_split('/[`"],[`"]/', trim($match[2], '`"')));
Expand Down Expand Up @@ -575,7 +575,7 @@ private function normalizeDefaultValue(?string $defaultValue, ColumnSchemaInterf
return new Expression('CURRENT_TIMESTAMP' . (!empty($matches[1]) ? '(' . $matches[1] . ')' : ''));
}

if (!empty($column->getExtra()) && !empty($defaultValue)) {
if (!empty($defaultValue) && !empty($column->getExtra())) {
return new Expression($defaultValue);
}

Expand Down Expand Up @@ -927,7 +927,7 @@ private function getJsonColumns(TableSchemaInterface $table): array
$result = [];
$regexp = '/json_valid\([\`"](.+)[\`"]\s*\)/mi';

if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) {
if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER) > 0) {
foreach ($matches as $match) {
$result[] = $match[1];
}
Expand Down

0 comments on commit 9fae32a

Please sign in to comment.