Skip to content

Commit 46bc7a2

Browse files
committed
chore(migration): Port away from deprecated IQueryBuilder::execute
And make sures psalm works correctly in the Migration files by providing stubds for the DBAL Schema classes. Signed-off-by: Carl Schwan <[email protected]>
1 parent 6c08514 commit 46bc7a2

File tree

7 files changed

+1357
-15
lines changed

7 files changed

+1357
-15
lines changed

REUSE.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,9 @@ path = "tests/integration/vendor/symfony/**"
106106
precedence = "aggregate"
107107
SPDX-FileCopyrightText = "Fabien Potencier"
108108
SPDX-License-Identifier = "MIT"
109+
110+
[[annotations]]
111+
path = ["tests/stubs/doctrine_dbal_**"]
112+
precedence = "aggregate"
113+
SPDX-FileCopyrightText = "none"
114+
SPDX-License-Identifier = "MIT"

lib/Migration/Version5000Date20211025124248.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ protected function deleteOldConfiguration(array $keys): bool {
151151

152152
$deletedRows = $this->deleteQuery
153153
->setParameter('cfgKeys', $keys, IQueryBuilder::PARAM_STR_ARRAY)
154-
->execute();
154+
->executeStatement();
155155

156156
return $deletedRows > 0;
157157
}
@@ -174,7 +174,7 @@ protected function insertConfiguration(int $id, array $configData): bool {
174174
->setParameter('configId', $id)
175175
->setParameter('displayName', $configData['general-idp0_display_name'] ?? '')
176176
->setParameter('configuration', \json_encode($configData, JSON_THROW_ON_ERROR))
177-
->execute();
177+
->executeStatement();
178178

179179
return $insertedRows > 0;
180180
}
@@ -190,7 +190,7 @@ protected function readConfiguration(array $configKeys): \Generator {
190190
}
191191

192192
$r = $this->readQuery->setParameter('cfgKeys', $configKeys, IQueryBuilder::PARAM_STR_ARRAY)
193-
->execute();
193+
->executeQuery();
194194

195195
while ($row = $r->fetch()) {
196196
yield $row;
@@ -216,7 +216,7 @@ protected function fetchPrefixes(): array {
216216
->where($q->expr()->eq('appid', $q->createNamedParameter('user_saml')))
217217
->andWhere($q->expr()->eq('configkey', $q->createNamedParameter('providerIds')));
218218

219-
$r = $q->execute();
219+
$r = $q->executeQuery();
220220
$prefixes = $r->fetchOne();
221221
if ($prefixes === false) {
222222
return [1]; // 1 is the default value for providerIds
@@ -229,6 +229,6 @@ protected function deletePrefixes(): void {
229229
$q->delete('appconfig')
230230
->where($q->expr()->eq('appid', $q->createNamedParameter('user_saml')))
231231
->andWhere($q->expr()->eq('configkey', $q->createNamedParameter('providerIds')))
232-
->execute();
232+
->executeStatement();
233233
}
234234
}

psalm.xml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
>
1616
<stubs>
1717
<file name="tests/stub.phpstub" preloadClasses="true"/>
18+
<file name="tests/stubs/doctrine_dbal_schema_abstractasset.php" />
19+
<file name="tests/stubs/doctrine_dbal_schema_column.php" />
20+
<file name="tests/stubs/doctrine_dbal_schema_schema.php" />
21+
<file name="tests/stubs/doctrine_dbal_schema_table.php" />
1822
</stubs>
1923
<projectFiles>
2024
<directory name="lib" />
@@ -31,18 +35,8 @@
3135
<DeprecatedConstant errorLevel="info" />
3236
<UndefinedClass>
3337
<errorLevel type="suppress">
34-
<referencedClass name="Doctrine\DBAL\Types\Types"/>
3538
<referencedClass name="Symfony\Component\Console\Command\Command"/>
3639
</errorLevel>
3740
</UndefinedClass>
38-
<UndefinedDocblockClass>
39-
<errorLevel type="suppress">
40-
<referencedClass name="Doctrine\DBAL\Driver\Statement" />
41-
<referencedClass name="Doctrine\DBAL\Schema\Schema" />
42-
<referencedClass name="Doctrine\DBAL\Schema\SchemaException" />
43-
<referencedClass name="Doctrine\DBAL\Schema\Table" />
44-
<referencedClass name="Doctrine\DBAL\Statement" />
45-
</errorLevel>
46-
</UndefinedDocblockClass>
4741
</issueHandlers>
4842
</psalm>
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?php
2+
3+
namespace Doctrine\DBAL\Schema;
4+
5+
use Doctrine\DBAL\Platforms\AbstractPlatform;
6+
use Doctrine\Deprecations\Deprecation;
7+
8+
use function array_map;
9+
use function crc32;
10+
use function dechex;
11+
use function explode;
12+
use function implode;
13+
use function str_replace;
14+
use function strpos;
15+
use function strtolower;
16+
use function strtoupper;
17+
use function substr;
18+
19+
/**
20+
* The abstract asset allows to reset the name of all assets without publishing this to the public userland.
21+
*
22+
* This encapsulation hack is necessary to keep a consistent state of the database schema. Say we have a list of tables
23+
* array($tableName => Table($tableName)); if you want to rename the table, you have to make sure this does not get
24+
* recreated during schema migration.
25+
*/
26+
abstract class AbstractAsset
27+
{
28+
/** @var string */
29+
protected $_name = '';
30+
31+
/**
32+
* Namespace of the asset. If none isset the default namespace is assumed.
33+
*
34+
* @var string|null
35+
*/
36+
protected $_namespace;
37+
38+
/** @var bool */
39+
protected $_quoted = false;
40+
41+
/**
42+
* Sets the name of this asset.
43+
*
44+
* @param string $name
45+
*
46+
* @return void
47+
*/
48+
protected function _setName($name)
49+
{
50+
}
51+
52+
/**
53+
* Is this asset in the default namespace?
54+
*
55+
* @param string $defaultNamespaceName
56+
*
57+
* @return bool
58+
*/
59+
public function isInDefaultNamespace($defaultNamespaceName)
60+
{
61+
}
62+
63+
/**
64+
* Gets the namespace name of this asset.
65+
*
66+
* If NULL is returned this means the default namespace is used.
67+
*
68+
* @return string|null
69+
*/
70+
public function getNamespaceName()
71+
{
72+
}
73+
74+
/**
75+
* The shortest name is stripped of the default namespace. All other
76+
* namespaced elements are returned as full-qualified names.
77+
*
78+
* @param string|null $defaultNamespaceName
79+
*
80+
* @return string
81+
*/
82+
public function getShortestName($defaultNamespaceName)
83+
{
84+
}
85+
86+
/**
87+
* The normalized name is full-qualified and lower-cased. Lower-casing is
88+
* actually wrong, but we have to do it to keep our sanity. If you are
89+
* using database objects that only differentiate in the casing (FOO vs
90+
* Foo) then you will NOT be able to use Doctrine Schema abstraction.
91+
*
92+
* Every non-namespaced element is prefixed with the default namespace
93+
* name which is passed as argument to this method.
94+
*
95+
* @deprecated Use {@see getNamespaceName()} and {@see getName()} instead.
96+
*
97+
* @param string $defaultNamespaceName
98+
*
99+
* @return string
100+
*/
101+
public function getFullQualifiedName($defaultNamespaceName)
102+
{
103+
}
104+
105+
/**
106+
* Checks if this asset's name is quoted.
107+
*
108+
* @return bool
109+
*/
110+
public function isQuoted()
111+
{
112+
}
113+
114+
/**
115+
* Checks if this identifier is quoted.
116+
*
117+
* @param string $identifier
118+
*
119+
* @return bool
120+
*/
121+
protected function isIdentifierQuoted($identifier)
122+
{
123+
}
124+
125+
/**
126+
* Trim quotes from the identifier.
127+
*
128+
* @param string $identifier
129+
*
130+
* @return string
131+
*/
132+
protected function trimQuotes($identifier)
133+
{
134+
}
135+
136+
/**
137+
* Returns the name of this schema asset.
138+
*
139+
* @return string
140+
*/
141+
public function getName()
142+
{
143+
}
144+
145+
/**
146+
* Gets the quoted representation of this asset but only if it was defined with one. Otherwise
147+
* return the plain unquoted value as inserted.
148+
*
149+
* @return string
150+
*/
151+
public function getQuotedName(AbstractPlatform $platform)
152+
{
153+
}
154+
155+
/**
156+
* Generates an identifier from a list of column names obeying a certain string length.
157+
*
158+
* This is especially important for Oracle, since it does not allow identifiers larger than 30 chars,
159+
* however building idents automatically for foreign keys, composite keys or such can easily create
160+
* very long names.
161+
*
162+
* @param string[] $columnNames
163+
* @param string $prefix
164+
* @param int $maxSize
165+
*
166+
* @return string
167+
*/
168+
protected function _generateIdentifierName($columnNames, $prefix = '', $maxSize = 30)
169+
{
170+
}
171+
}

0 commit comments

Comments
 (0)