From d3faa02120366beb1ed4524649faf272851bfc00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 22 Apr 2020 19:02:20 +0200 Subject: [PATCH 1/3] Use OCI_NO_AUTO_COMMIT instead of OCI_DEFAULT This constant is not recognized by PHPStan, and besides the docs say this: > Prior to PHP 5.3.2 (PECL OCI8 1.4) use OCI_DEFAULT which is equivalent to OCI_NO_AUTO_COMMIT. See https://www.php.net/manual/en/function.oci-execute.php --- lib/Doctrine/DBAL/Driver/OCI8/Driver.php | 4 ++-- lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php index edda32d6a56..0f2ebf362cb 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractOracleDriver; -use const OCI_DEFAULT; +use const OCI_NO_AUTO_COMMIT; /** * A Doctrine DBAL driver for the Oracle OCI8 PHP extensions. @@ -22,7 +22,7 @@ public function connect(array $params, $username = null, $password = null, array (string) $password, $this->_constructDsn($params), $params['charset'] ?? '', - $params['sessionMode'] ?? OCI_DEFAULT, + $params['sessionMode'] ?? OCI_NO_AUTO_COMMIT, $params['persistent'] ?? false ); } catch (OCI8Exception $e) { diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php index c1857936f5a..b67ef9210a5 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\ParameterType; use UnexpectedValueException; use const OCI_COMMIT_ON_SUCCESS; -use const OCI_DEFAULT; use const OCI_NO_AUTO_COMMIT; use function addcslashes; use function func_get_args; @@ -51,7 +50,7 @@ public function __construct( $password, $db, $charset = '', - $sessionMode = OCI_DEFAULT, + $sessionMode = OCI_NO_AUTO_COMMIT, $persistent = false ) { $dbh = $persistent From 30430efc3230bba244b2b2aebc5a73251ce6a238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 22 Apr 2020 18:56:42 +0200 Subject: [PATCH 2/3] Ignore issue about unreleased constant stub --- phpstan.neon.dist | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 85bc4ce351c..7178aa6a906 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -72,3 +72,8 @@ parameters: - message: '~^Cannot cast array\|bool\|string\|null to int\.$~' path: %currentWorkingDirectory%/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php + + # Requires a release of https://github.com/JetBrains/phpstorm-stubs/pull/732 + - + message: '~^Access to undefined constant PDO::PGSQL_ATTR_DISABLE_PREPARES\.$~' + path: %currentWorkingDirectory%/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php From c643ac38d7d5fd412c77b2a63ab524c92c81ecd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 22 Apr 2020 19:46:01 +0200 Subject: [PATCH 3/3] Remove unneeded and risky stub parsing PHPStan already reads these stubs, but in a controlled and safe why. It does not seem to read global constants yet, which is why we define OCI_NO_AUTO_COMMIT if undefined. Might be unneeded in the future too. --- tests/phpstan-polyfill.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/phpstan-polyfill.php b/tests/phpstan-polyfill.php index f27e09de3a0..7782435ee26 100644 --- a/tests/phpstan-polyfill.php +++ b/tests/phpstan-polyfill.php @@ -2,12 +2,9 @@ declare(strict_types=1); -(static function () : void { - foreach (['ibm_db2', 'mysqli', 'oci8', 'sqlsrv', 'pgsql'] as $extension) { - if (extension_loaded($extension)) { - continue; - } +// PHPStan does not read global constants from the stubs yet, remove this when it does +if (defined('OCI_NO_AUTO_COMMIT')) { + return; +} - require sprintf(__DIR__ . '/../vendor/jetbrains/phpstorm-stubs/%1$s/%1$s.php', $extension); - } -})(); +define('OCI_NO_AUTO_COMMIT', 0);