Skip to content

Commit e9767f8

Browse files
authored
Merge branch '4.x-dev' into deprecated-class-parameter
2 parents d999aee + fc83b5e commit e9767f8

10 files changed

Lines changed: 193 additions & 317 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ jobs:
5050
runs-on: ubuntu-latest
5151
container: joomlaprojects/docker-images:php8.4
5252
needs: [code-style-php]
53-
continue-on-error: true
5453
steps:
5554
- uses: actions/checkout@v4
5655
- uses: actions/cache/restore@v4
@@ -208,6 +207,6 @@ jobs:
208207
- name: Install Composer dependencies
209208
run: |
210209
git config --global --add safe.directory $GITHUB_WORKSPACE
211-
composer install --no-progress --ignore-platform-reqs
210+
composer update
212211
- name: Run Unit tests
213212
run: php vendor/bin/phpunit -c phpunit.appveyor_sql2019.xml.dist

Tests/Mysqli/MysqliPreparedStatementTest.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ protected function setUp(): void
5151
)
5252
);
5353
}
54+
55+
$insertQuery = 'INSERT INTO dbtest (title, description, start_date) VALUES (:title, :description, :start_date)';
56+
$mysqliStatementObject = new MysqliStatement(static::$connection->getConnection(), $insertQuery);
57+
$mysqliStatementObject->execute([
58+
':title' => 'Test Title',
59+
':description' => 'Test Description',
60+
':start_date' => '2023-01-01',
61+
]);
5462
}
5563

5664
/**
@@ -148,10 +156,45 @@ public function testPreparedStatementWithSingleKey()
148156
$statement = 'SELECT * FROM dbtest WHERE `title` LIKE :search OR `description` LIKE :search2';
149157
$mysqliStatementObject = new MysqliStatement(static::$connection->getConnection(), $statement);
150158
$dummyValue = 'test';
151-
$dummyValue2 = 'test';
152159
$mysqliStatementObject->bindParam(':search', $dummyValue);
153160
$mysqliStatementObject->bindParam(':search2', $dummyValue);
154161

155162
$mysqliStatementObject->execute();
156163
}
164+
165+
/**
166+
* Regression test to ensure running queries with bound variables still works
167+
*/
168+
public function testPreparedStatementWithBinding()
169+
{
170+
$statement = 'SELECT id FROM dbtest WHERE `title` LIKE :search';
171+
$mysqliStatementObject = new MysqliStatement(static::$connection->getConnection(), $statement);
172+
$title = 'Test Title';
173+
$mysqliStatementObject->bindParam(':search', $title);
174+
$mysqliStatementObject->execute();
175+
$result = $mysqliStatementObject->fetchColumn();
176+
177+
$title = 'changed';
178+
$mysqliStatementObject->execute();
179+
$result2 = $mysqliStatementObject->fetchColumn();
180+
$this->assertNotEquals($result, $result2);
181+
}
182+
183+
/**
184+
* Regression test to ensure running queries with bound variables still works
185+
*/
186+
public function testPreparedStatementWithoutBinding()
187+
{
188+
$statement = 'SELECT id FROM dbtest WHERE `title` LIKE :search';
189+
$mysqliStatementObject = new MysqliStatement(static::$connection->getConnection(), $statement);
190+
$title = 'Test Title';
191+
$params = [':search' => $title];
192+
$mysqliStatementObject->execute($params);
193+
$result = $mysqliStatementObject->fetchColumn();
194+
195+
$params[':search'] = 'changed';
196+
$mysqliStatementObject->execute($params);
197+
$result2 = $mysqliStatementObject->fetchColumn();
198+
$this->assertNotEquals($result, $result2);
199+
}
157200
}

phpstan-baseline.neon

Lines changed: 9 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,6 @@ parameters:
126126
count: 1
127127
path: src/DatabaseQuery.php
128128

129-
-
130-
message: '#^If condition is always true\.$#'
131-
identifier: if.alwaysTrue
132-
count: 9
133-
path: src/DatabaseQuery.php
134-
135129
-
136130
message: '#^Instanceof between Joomla\\Database\\DatabaseInterface and Joomla\\Database\\DatabaseInterface will always evaluate to true\.$#'
137131
identifier: instanceof.alwaysTrue
@@ -144,30 +138,12 @@ parameters:
144138
count: 1
145139
path: src/DatabaseQuery.php
146140

147-
-
148-
message: '#^Left side of \|\| is always true\.$#'
149-
identifier: booleanOr.leftAlwaysTrue
150-
count: 1
151-
path: src/DatabaseQuery.php
152-
153-
-
154-
message: '#^Parameter \#2 \$array of function implode expects array\|null, string given\.$#'
155-
identifier: argument.type
156-
count: 1
157-
path: src/DatabaseQuery.php
158-
159141
-
160142
message: '#^Parameter \#2 \$elements of class Joomla\\Database\\Query\\QueryElement constructor expects array\<string\>\|string, null given\.$#'
161143
identifier: argument.type
162144
count: 1
163145
path: src/DatabaseQuery.php
164146

165-
-
166-
message: '#^Property Joomla\\Database\\DatabaseQuery\:\:\$querySet has unknown class Joomla\\Database\\Query\\DatabaseQuery as its type\.$#'
167-
identifier: class.notFound
168-
count: 1
169-
path: src/DatabaseQuery.php
170-
171147
-
172148
message: '#^Return type \(string\) of method Joomla\\Database\\DatabaseQuery\:\:length\(\) should be compatible with return type \(int\) of method Joomla\\Database\\QueryInterface\:\:length\(\)$#'
173149
identifier: method.childReturnType
@@ -216,18 +192,6 @@ parameters:
216192
count: 1
217193
path: src/Mysql/MysqlDriver.php
218194

219-
-
220-
message: '#^Method Joomla\\Database\\Mysql\\MysqlImporter\:\:getKeyLookup\(\) has Exception in PHPDoc @throws tag but it''s not thrown\.$#'
221-
identifier: throws.unusedType
222-
count: 1
223-
path: src/Mysql/MysqlImporter.php
224-
225-
-
226-
message: '#^If condition is always true\.$#'
227-
identifier: if.alwaysTrue
228-
count: 1
229-
path: src/Mysql/MysqlQuery.php
230-
231195
-
232196
message: '#^Call to function is_callable\(\) with array\{mysqli, ''close''\} will always evaluate to true\.$#'
233197
identifier: function.alreadyNarrowedType
@@ -264,12 +228,6 @@ parameters:
264228
count: 1
265229
path: src/Mysqli/MysqliDriver.php
266230

267-
-
268-
message: '#^Method Joomla\\Database\\Mysqli\\MysqliDriver\:\:connect\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
269-
identifier: throws.unusedType
270-
count: 1
271-
path: src/Mysqli/MysqliDriver.php
272-
273231
-
274232
message: '#^Method Joomla\\Database\\Mysqli\\MysqliDriver\:\:serverClaimsUtf8mb4Support\(\) is unused\.$#'
275233
identifier: method.unused
@@ -300,12 +258,6 @@ parameters:
300258
count: 2
301259
path: src/Mysqli/MysqliDriver.php
302260

303-
-
304-
message: '#^If condition is always true\.$#'
305-
identifier: if.alwaysTrue
306-
count: 1
307-
path: src/Mysqli/MysqliQuery.php
308-
309261
-
310262
message: '#^PHPDoc type array of property Joomla\\Database\\Mysqli\\MysqliQuery\:\:\$nullDatetimeList is not covariant with PHPDoc type array\<string\> of overridden property Joomla\\Database\\DatabaseQuery\:\:\$nullDatetimeList\.$#'
311263
identifier: property.phpDocType
@@ -360,12 +312,6 @@ parameters:
360312
count: 4
361313
path: src/Pdo/PdoDriver.php
362314

363-
-
364-
message: '#^Method Joomla\\Database\\Pdo\\PdoDriver\:\:connect\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
365-
identifier: throws.unusedType
366-
count: 1
367-
path: src/Pdo/PdoDriver.php
368-
369315
-
370316
message: '#^PHPDoc type PDO of property Joomla\\Database\\Pdo\\PdoDriver\:\:\$connection is not covariant with PHPDoc type resource of overridden property Joomla\\Database\\DatabaseDriver\:\:\$connection\.$#'
371317
identifier: property.phpDocType
@@ -402,12 +348,6 @@ parameters:
402348
count: 1
403349
path: src/Pgsql/PgsqlDriver.php
404350

405-
-
406-
message: '#^Method Joomla\\Database\\Pgsql\\PgsqlDriver\:\:getTableCreate\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
407-
identifier: throws.unusedType
408-
count: 1
409-
path: src/Pgsql/PgsqlDriver.php
410-
411351
-
412352
message: '#^Strict comparison using \=\=\= between string and 0 will always evaluate to false\.$#'
413353
identifier: identical.alwaysFalse
@@ -498,12 +438,6 @@ parameters:
498438
count: 1
499439
path: src/Pgsql/PgsqlImporter.php
500440

501-
-
502-
message: '#^If condition is always true\.$#'
503-
identifier: if.alwaysTrue
504-
count: 12
505-
path: src/Pgsql/PgsqlQuery.php
506-
507441
-
508442
message: '#^Instanceof between string and \$this\(Joomla\\Database\\Pgsql\\PgsqlQuery\) will always evaluate to false\.$#'
509443
identifier: instanceof.alwaysFalse
@@ -523,8 +457,14 @@ parameters:
523457
path: src/Pgsql/PgsqlQuery.php
524458

525459
-
526-
message: '#^Ternary operator condition is always true\.$#'
527-
identifier: ternary.alwaysTrue
460+
message: '#^Property Joomla\\Database\\DatabaseQuery\:\:\$limit \(int\|null\) does not accept Joomla\\Database\\Query\\QueryElement\.$#'
461+
identifier: assign.propertyType
462+
count: 1
463+
path: src/Pgsql/PgsqlQuery.php
464+
465+
-
466+
message: '#^Property Joomla\\Database\\DatabaseQuery\:\:\$offset \(int\|null\) does not accept Joomla\\Database\\Query\\QueryElement\.$#'
467+
identifier: assign.propertyType
528468
count: 1
529469
path: src/Pgsql/PgsqlQuery.php
530470

@@ -552,72 +492,12 @@ parameters:
552492
count: 1
553493
path: src/Sqlite/SqliteDriver.php
554494

555-
-
556-
message: '#^Method Joomla\\Database\\Sqlite\\SqliteDriver\:\:alterDbCharacterSet\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
557-
identifier: throws.unusedType
558-
count: 1
559-
path: src/Sqlite/SqliteDriver.php
560-
561-
-
562-
message: '#^Method Joomla\\Database\\Sqlite\\SqliteDriver\:\:connect\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
563-
identifier: throws.unusedType
564-
count: 1
565-
path: src/Sqlite/SqliteDriver.php
566-
567-
-
568-
message: '#^Method Joomla\\Database\\Sqlite\\SqliteDriver\:\:createDatabase\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
569-
identifier: throws.unusedType
570-
count: 1
571-
path: src/Sqlite/SqliteDriver.php
572-
573-
-
574-
message: '#^Method Joomla\\Database\\Sqlite\\SqliteDriver\:\:getConnectionCollation\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
575-
identifier: throws.unusedType
576-
count: 1
577-
path: src/Sqlite/SqliteDriver.php
578-
579-
-
580-
message: '#^Method Joomla\\Database\\Sqlite\\SqliteDriver\:\:getConnectionEncryption\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
581-
identifier: throws.unusedType
582-
count: 1
583-
path: src/Sqlite/SqliteDriver.php
584-
585-
-
586-
message: '#^Method Joomla\\Database\\Sqlite\\SqliteDriver\:\:lockTable\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
587-
identifier: throws.unusedType
588-
count: 1
589-
path: src/Sqlite/SqliteDriver.php
590-
591-
-
592-
message: '#^Method Joomla\\Database\\Sqlite\\SqliteDriver\:\:unlockTables\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
593-
identifier: throws.unusedType
594-
count: 1
595-
path: src/Sqlite/SqliteDriver.php
596-
597495
-
598496
message: '#^Unreachable statement \- code above always terminates\.$#'
599497
identifier: deadCode.unreachable
600498
count: 1
601499
path: src/Sqlite/SqliteDriver.php
602500

603-
-
604-
message: '#^If condition is always true\.$#'
605-
identifier: if.alwaysTrue
606-
count: 1
607-
path: src/Sqlite/SqliteQuery.php
608-
609-
-
610-
message: '#^Left side of \|\| is always true\.$#'
611-
identifier: booleanOr.leftAlwaysTrue
612-
count: 1
613-
path: src/Sqlite/SqliteQuery.php
614-
615-
-
616-
message: '#^Result of \|\| is always true\.$#'
617-
identifier: booleanOr.alwaysTrue
618-
count: 1
619-
path: src/Sqlite/SqliteQuery.php
620-
621501
-
622502
message: '#^Unsafe usage of new static\(\)\.$#'
623503
identifier: new.static
@@ -642,28 +522,10 @@ parameters:
642522
count: 4
643523
path: src/Sqlsrv/SqlsrvDriver.php
644524

645-
-
646-
message: '#^Method Joomla\\Database\\Sqlsrv\\SqlsrvDriver\:\:connect\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
647-
identifier: throws.unusedType
648-
count: 1
649-
path: src/Sqlsrv/SqlsrvDriver.php
650-
651-
-
652-
message: '#^Method Joomla\\Database\\Sqlsrv\\SqlsrvDriver\:\:lockTable\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
653-
identifier: throws.unusedType
654-
count: 1
655-
path: src/Sqlsrv/SqlsrvDriver.php
656-
657-
-
658-
message: '#^Method Joomla\\Database\\Sqlsrv\\SqlsrvDriver\:\:unlockTables\(\) has RuntimeException in PHPDoc @throws tag but it''s not thrown\.$#'
659-
identifier: throws.unusedType
660-
count: 1
661-
path: src/Sqlsrv/SqlsrvDriver.php
662-
663525
-
664526
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, list\<array\|string\> given\.$#'
665527
identifier: argument.type
666-
count: 1
528+
count: 2
667529
path: src/Sqlsrv/SqlsrvDriver.php
668530

669531
-
@@ -690,24 +552,12 @@ parameters:
690552
count: 1
691553
path: src/Sqlsrv/SqlsrvQuery.php
692554

693-
-
694-
message: '#^If condition is always true\.$#'
695-
identifier: if.alwaysTrue
696-
count: 14
697-
path: src/Sqlsrv/SqlsrvQuery.php
698-
699555
-
700556
message: '#^Instanceof between Joomla\\Database\\DatabaseInterface and Joomla\\Database\\DatabaseInterface will always evaluate to true\.$#'
701557
identifier: instanceof.alwaysTrue
702558
count: 1
703559
path: src/Sqlsrv/SqlsrvQuery.php
704560

705-
-
706-
message: '#^Left side of \|\| is always true\.$#'
707-
identifier: booleanOr.leftAlwaysTrue
708-
count: 1
709-
path: src/Sqlsrv/SqlsrvQuery.php
710-
711561
-
712562
message: '#^Offset int\<1, max\> on list in isset\(\) does not exist\.$#'
713563
identifier: isset.offset
@@ -720,18 +570,6 @@ parameters:
720570
count: 1
721571
path: src/Sqlsrv/SqlsrvQuery.php
722572

723-
-
724-
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, array\<array\|string\> given\.$#'
725-
identifier: argument.type
726-
count: 1
727-
path: src/Sqlsrv/SqlsrvQuery.php
728-
729-
-
730-
message: '#^Result of \|\| is always true\.$#'
731-
identifier: booleanOr.alwaysTrue
732-
count: 1
733-
path: src/Sqlsrv/SqlsrvQuery.php
734-
735573
-
736574
message: '#^Return type \(string\) of method Joomla\\Database\\Sqlsrv\\SqlsrvQuery\:\:length\(\) should be compatible with return type \(int\) of method Joomla\\Database\\QueryInterface\:\:length\(\)$#'
737575
identifier: method.childReturnType

src/DatabaseInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public function lockTable($tableName);
470470
* @param array|string $text A string or an array of strings to quote.
471471
* @param boolean $escape True (default) to escape the string, false to leave it unchanged.
472472
*
473-
* @return string
473+
* @return array|string The quoted input string.
474474
*
475475
* @since 2.0.0
476476
*/

0 commit comments

Comments
 (0)