Skip to content

Commit

Permalink
Merge pull request #4051 from morozov/fix-final-class-members
Browse files Browse the repository at this point in the history
Fix final class member names according to the coding standard
  • Loading branch information
morozov authored Jun 6, 2020
2 parents 66e9dc3 + 52ad7ab commit ece6cd6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ parameters:
path: %currentWorkingDirectory%/tests/Functional/DataAccessTest.php

# https://github.com/JetBrains/phpstorm-stubs/pull/766
- '~^Method Doctrine\\DBAL\\Driver\\Mysqli\\MysqliStatement::_fetch\(\) never returns null so it can be removed from the return typehint\.$~'
- '~^Method Doctrine\\DBAL\\Driver\\Mysqli\\MysqliStatement::fetch\(\) never returns null so it can be removed from the return typehint\.$~'

# The ReflectionException in the case when the class does not exist is acceptable and does not need to be handled
- '~^Parameter #1 \$argument of class ReflectionClass constructor expects class-string<T of object>\|T of object, string given\.$~'
Expand Down
4 changes: 2 additions & 2 deletions src/Driver/Mysqli/MysqliStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private function bindUntypedValues(array $values) : bool
/**
* @return mixed[]|false|null
*/
private function _fetch()
private function fetch()
{
$ret = $this->stmt->fetch();

Expand All @@ -328,7 +328,7 @@ public function fetchNumeric()
return false;
}

$values = $this->_fetch();
$values = $this->fetch();

if ($values === null) {
return false;
Expand Down
28 changes: 15 additions & 13 deletions src/Driver/OCI8/OCI8Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
final class OCI8Connection implements Connection, ServerInfoAwareConnection
{
/** @var resource */
protected $dbh;
private $connection;

/** @var ExecutionMode */
private $executionMode;
Expand All @@ -45,15 +45,17 @@ public function __construct(
int $sessionMode = OCI_NO_AUTO_COMMIT,
bool $persistent = false
) {
$dbh = $persistent
? @oci_pconnect($username, $password, $db, $charset, $sessionMode)
: @oci_connect($username, $password, $db, $charset, $sessionMode);
if ($persistent) {
$connection = @oci_pconnect($username, $password, $db, $charset, $sessionMode);
} else {
$connection = @oci_connect($username, $password, $db, $charset, $sessionMode);
}

if ($dbh === false) {
if ($connection === false) {
throw OCI8Exception::fromErrorInfo(oci_error());
}

$this->dbh = $dbh;
$this->connection = $connection;
$this->executionMode = new ExecutionMode();
}

Expand All @@ -65,10 +67,10 @@ public function __construct(
*/
public function getServerVersion() : string
{
$version = oci_server_version($this->dbh);
$version = oci_server_version($this->connection);

if ($version === false) {
throw OCI8Exception::fromErrorInfo(oci_error($this->dbh));
throw OCI8Exception::fromErrorInfo(oci_error($this->connection));
}

if (preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', $version, $matches) === 0) {
Expand All @@ -86,7 +88,7 @@ public function getServerVersion() : string

public function prepare(string $sql) : DriverStatement
{
return new OCI8Statement($this->dbh, $sql, $this->executionMode);
return new OCI8Statement($this->connection, $sql, $this->executionMode);
}

public function query(string $sql) : ResultStatement
Expand Down Expand Up @@ -132,17 +134,17 @@ public function beginTransaction() : void

public function commit() : void
{
if (! oci_commit($this->dbh)) {
throw OCI8Exception::fromErrorInfo(oci_error($this->dbh));
if (! oci_commit($this->connection)) {
throw OCI8Exception::fromErrorInfo(oci_error($this->connection));
}

$this->executionMode->enableAutoCommit();
}

public function rollBack() : void
{
if (! oci_rollback($this->dbh)) {
throw OCI8Exception::fromErrorInfo(oci_error($this->dbh));
if (! oci_rollback($this->connection)) {
throw OCI8Exception::fromErrorInfo(oci_error($this->connection));
}

$this->executionMode->enableAutoCommit();
Expand Down
44 changes: 22 additions & 22 deletions src/Driver/OCI8/OCI8Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@
final class OCI8Statement implements Statement
{
/** @var resource */
protected $_dbh;
private $connection;

/** @var resource */
protected $_sth;
private $statement;

/** @var ExecutionMode */
protected $executionMode;
private $executionMode;

/** @var string[] */
protected $_paramMap = [];
private $parameterMap = [];

/**
* Holds references to bound parameter values.
Expand Down Expand Up @@ -78,14 +78,14 @@ final class OCI8Statement implements Statement
*/
public function __construct($dbh, string $query, ExecutionMode $executionMode)
{
[$query, $paramMap] = (new ConvertPositionalToNamedPlaceholders())($query);
[$query, $parameterMap] = (new ConvertPositionalToNamedPlaceholders())($query);

$stmt = oci_parse($dbh, $query);
assert(is_resource($stmt));
$statement = oci_parse($dbh, $query);
assert(is_resource($statement));

$this->_sth = $stmt;
$this->_dbh = $dbh;
$this->_paramMap = $paramMap;
$this->statement = $statement;
$this->connection = $dbh;
$this->parameterMap = $parameterMap;
$this->executionMode = $executionMode;
}

Expand All @@ -103,15 +103,15 @@ public function bindValue($param, $value, int $type = ParameterType::STRING) : v
public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null) : void
{
if (is_int($param)) {
if (! isset($this->_paramMap[$param])) {
if (! isset($this->parameterMap[$param])) {
throw new OCI8Exception(sprintf('Could not find variable mapping with index %d, in the SQL statement', $param));
}

$param = $this->_paramMap[$param];
$param = $this->parameterMap[$param];
}

if ($type === ParameterType::LARGE_OBJECT) {
$lob = oci_new_descriptor($this->_dbh, OCI_D_LOB);
$lob = oci_new_descriptor($this->connection, OCI_D_LOB);

$class = 'OCI-Lob';
assert($lob instanceof $class);
Expand All @@ -124,13 +124,13 @@ public function bindParam($param, &$variable, int $type = ParameterType::STRING,
$this->boundValues[$param] =& $variable;

if (! oci_bind_by_name(
$this->_sth,
$this->statement,
$param,
$variable,
$length ?? -1,
$this->convertParameterType($type)
)) {
throw OCI8Exception::fromErrorInfo(oci_error($this->_sth));
throw OCI8Exception::fromErrorInfo(oci_error($this->statement));
}
}

Expand Down Expand Up @@ -158,14 +158,14 @@ public function closeCursor() : void
return;
}

oci_cancel($this->_sth);
oci_cancel($this->statement);

$this->result = false;
}

public function columnCount() : int
{
$count = oci_num_fields($this->_sth);
$count = oci_num_fields($this->statement);

if ($count !== false) {
return $count;
Expand Down Expand Up @@ -197,17 +197,17 @@ public function execute(?array $params = null) : void
$mode = OCI_NO_AUTO_COMMIT;
}

$ret = @oci_execute($this->_sth, $mode);
$ret = @oci_execute($this->statement, $mode);
if (! $ret) {
throw OCI8Exception::fromErrorInfo(oci_error($this->_sth));
throw OCI8Exception::fromErrorInfo(oci_error($this->statement));
}

$this->result = true;
}

public function rowCount() : int
{
$count = oci_num_rows($this->_sth);
$count = oci_num_rows($this->statement);

if ($count !== false) {
return $count;
Expand Down Expand Up @@ -276,7 +276,7 @@ private function fetch(int $mode)
}

return oci_fetch_array(
$this->_sth,
$this->statement,
$mode | OCI_RETURN_NULLS | OCI_RETURN_LOBS
);
}
Expand All @@ -293,7 +293,7 @@ private function fetchAll(int $mode, int $fetchStructure) : array
}

oci_fetch_all(
$this->_sth,
$this->statement,
$result,
0,
-1,
Expand Down

0 comments on commit ece6cd6

Please sign in to comment.