Skip to content

Commit

Permalink
Resolves #939 replaced single quotes with nowdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-karkus authored and Kamil Karkus committed Nov 29, 2024
1 parent 1065fbe commit 7b67927
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/Generator/SqlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public function generate(
}
}

$code[] = sprintf('$this->addSql(%s);', var_export($query, true));
$code[] = sprintf(
"\$this->addSql(<<<'SQL'\n%s\nSQL);",
preg_replace('/^/m', str_repeat(' ', 4), $query)

Check failure on line 66 in src/Generator/SqlGenerator.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (PHP: 8.4)

Function preg_replace() should not be referenced via a fallback global name, but via a use statement.

Check failure on line 66 in src/Generator/SqlGenerator.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (PHP: 8.4)

Function str_repeat() should not be referenced via a fallback global name, but via a use statement.

Check failure on line 66 in src/Generator/SqlGenerator.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (PHP: 8.4)

Multi-line function calls must have a trailing comma after the last parameter.
);
}

if (count($code) !== 0 && $checkDbPlatform && $this->configuration->isDatabasePlatformChecked()) {
Expand Down
46 changes: 35 additions & 11 deletions tests/Generator/SqlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ public function testGenerate(): void
!\$this->connection->getDatabasePlatform() instanceof \\$expectedPlatform,
"Migration can only be executed safely on '\\$expectedPlatform'."
);
\$this->addSql('SELECT 1');
\$this->addSql('SELECT 2');
\$this->addSql('%s');
\$this->addSql(<<<'SQL'
SELECT 1
SQL);
\$this->addSql(<<<'SQL'
SELECT 2
SQL);
\$this->addSql(<<<'SQL'
%s
SQL);
CODE,
);

Expand All @@ -65,9 +71,15 @@ public function testGenerationWithoutCheckingDatabasePlatform(): void

$expectedCode = $this->prepareGeneratedCode(
<<<'CODE'
$this->addSql('SELECT 1');
$this->addSql('SELECT 2');
$this->addSql('%s');
$this->addSql(<<<'SQL'
SELECT 1
SQL);
$this->addSql(<<<'SQL'
SELECT 2
SQL);
$this->addSql(<<<'SQL'
%s
SQL);
CODE,
);

Expand All @@ -82,9 +94,15 @@ public function testGenerationWithoutCheckingDatabasePlatformWithConfiguration()

$expectedCode = $this->prepareGeneratedCode(
<<<'CODE'
$this->addSql('SELECT 1');
$this->addSql('SELECT 2');
$this->addSql('%s');
$this->addSql(<<<'SQL'
SELECT 1
SQL);
$this->addSql(<<<'SQL'
SELECT 2
SQL);
$this->addSql(<<<'SQL'
%s
SQL);
CODE,
);

Expand Down Expand Up @@ -119,7 +137,13 @@ private function prepareGeneratedCode(string $expectedCode): string

return sprintf(
$expectedCode,
(new SqlFormatter(new NullHighlighter()))->format($this->sql[2]),
implode(

Check failure on line 140 in tests/Generator/SqlGeneratorTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (PHP: 8.4)

Function implode() should not be referenced via a fallback global name, but via a use statement.
"\n" . str_repeat(' ', 4),

Check failure on line 141 in tests/Generator/SqlGeneratorTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (PHP: 8.4)

Function str_repeat() should not be referenced via a fallback global name, but via a use statement.
explode(

Check failure on line 142 in tests/Generator/SqlGeneratorTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (PHP: 8.4)

Function explode() should not be referenced via a fallback global name, but via a use statement.
"\n",
(new SqlFormatter(new NullHighlighter()))->format($this->sql[2]),
),
),
);
}
}

0 comments on commit 7b67927

Please sign in to comment.