You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
try {
$driver = 'driver';
$connection = new \PDO('dsn', 'user', 'password', []);
#Enforce some attributes. I've noticed that some of them do not apply when used during initial creation. The most frequent culprit is prepare emulationif ($driver === 'mysql') {
if (!$connection->setAttribute(\PDO::MYSQL_ATTR_MULTI_STATEMENTS, false)) {
thrownew \PDOException('Failed to set `MYSQL_ATTR_MULTI_STATEMENTS` to `false`.');
}
if (!$connection->setAttribute(\PDO::MYSQL_ATTR_IGNORE_SPACE, true)) {
thrownew \PDOException('Failed to set `MYSQL_ATTR_IGNORE_SPACE` to `true`.');
}
if (!$connection->setAttribute(\PDO::MYSQL_ATTR_DIRECT_QUERY, false)) {
thrownew \PDOException('Failed to set `MYSQL_ATTR_DIRECT_QUERY` to `false`.');
}
if (!$connection->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true)) {
thrownew \PDOException('Failed to set `MYSQL_ATTR_USE_BUFFERED_QUERY` to `true`.');
}
} elseif ($driver === 'sqlsrv') {
if (!$connection->setAttribute(\PDO::SQLSRV_ATTR_DIRECT_QUERY, false)) {
thrownew \PDOException('Failed to set `SQLSRV_ATTR_DIRECT_QUERY` to `false`.');
}
}
if (!$connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true)) {
thrownew \PDOException('Failed to set `ATTR_EMULATE_PREPARES` to `true`.');
}
if (!$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION)) {
thrownew \PDOException('Failed to set `ATTR_ERRMODE` to exception mode.');
}
} catch (\Throwable$exception) {
#Do something
}
Get [EA] Consider moving non-related statements (5 in total) outside the try-block or refactoring the try-body into a function/method. warning on try.
Remove
if (!$connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true)) {
thrownew \PDOException('Failed to set `ATTR_EMULATE_PREPARES` to `true`.');
}
if (!$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION)) {
thrownew \PDOException('Failed to set `ATTR_ERRMODE` to exception mode.');
}
Lose the warning. Same behavior is observed with this code
try {
$driver = 'driver';
$connection = new \PDO('dsn', 'user', 'password', []);
#Enforce some attributes. I've noticed that some of them do not apply when used during initial creation. The most frequent culprit is prepare emulationif ($driver === 'mysql') {
$connection->setAttribute(\PDO::MYSQL_ATTR_MULTI_STATEMENTS, false);
$connection->setAttribute(\PDO::MYSQL_ATTR_IGNORE_SPACE, true);
$connection->setAttribute(\PDO::MYSQL_ATTR_DIRECT_QUERY, false);
$connection->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
} elseif ($driver === 'sqlsrv') {
$connection->setAttribute(\PDO::SQLSRV_ATTR_DIRECT_QUERY, false);
}
$connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
} catch (\Throwable$exception) {
#Do something
}
But here it makes at least some sense, because setAttribute does not throw exceptions., but the number in the warning is still incorrect, and it still reacts only to the setAttribute lines outside the if statements.
Expected behavior
No warning is shown, at least when there are exceptions thrown. If there are no exceptions in the code, number probably needs correction.
Environment details
PhpStorm 2024.1.1
Build #PS-241.15989.102, built on April 23, 2024
Licensed to simbiat.ru / Dmitry Kustov
Subscription is active until March 31, 2025.
For non-commercial open source development only.
Runtime version: 17.0.10+1-b1207.14 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11.0
GC: G1 Young Generation, G1 Old Generation
Memory: 5120M
Cores: 16
Registry:
debugger.new.tool.window.layout=true
run.processes.with.pty=TRUE
ide.experimental.ui=true
terminal.new.ui=true
Non-Bundled Plugins:
com.intellij.ml.llm (241.15989.156)
com.kalessil.phpStorm.phpInspectionsEA (5.0.0.0)
org.intellij.qodana (241.15989.121)
The text was updated successfully, but these errors were encountered:
Current behaviour
Have a code like this (simplified of this file)
Get
[EA] Consider moving non-related statements (5 in total) outside the try-block or refactoring the try-body into a function/method.
warning ontry
.Remove
Lose the warning. Same behavior is observed with this code
But here it makes at least some sense, because
setAttribute
does not throw exceptions., but the number in the warning is still incorrect, and it still reacts only to thesetAttribute
lines outside the if statements.Expected behavior
No warning is shown, at least when there are exceptions thrown. If there are no exceptions in the code, number probably needs correction.
Environment details
The text was updated successfully, but these errors were encountered: