Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ parameters:
paths:
- src

scanDirectories:
- vendor

universalObjectCratesClasses: # to ignore magic property errors
- ipl\Sql\Config

Expand Down
21 changes: 14 additions & 7 deletions src/Adapter/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public function setClientTimezone(Connection $db)
{
$db->exec('SET time_zone = ' . $db->quote($this->getTimezoneOffset()));

Check failure on line 17 in src/Adapter/Mysql.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Binary operation "." between 'SET time_zone = ' and mixed results in an error.

Check failure on line 17 in src/Adapter/Mysql.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Binary operation "." between 'SET time_zone = ' and mixed results in an error.

Check failure on line 17 in src/Adapter/Mysql.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Binary operation "." between 'SET time_zone = ' and mixed results in an error.

Check failure on line 17 in src/Adapter/Mysql.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Binary operation "." between 'SET time_zone = ' and mixed results in an error.

return $this;
}
Expand All @@ -22,33 +22,40 @@
public function getOptions(Config $config)
{
$options = parent::getOptions($config);
// In PHP 8.5+, driver-specific constants of the PDO class are deprecated,
// but the replacements are only available since php 8.4
if (version_compare(PHP_VERSION, '8.4.0', '<')) {
$mysqlConstantPrefix = 'PDO::MYSQL_ATTR_';
} else {
$mysqlConstantPrefix = 'Pdo\Mysql::ATTR_';
}

if (! empty($config->useSsl)) {
if (! empty($config->sslKey)) {
$options[PDO::MYSQL_ATTR_SSL_KEY] = $config->sslKey;
$options[constant($mysqlConstantPrefix . 'SSL_KEY')] = $config->sslKey;

Check failure on line 35 in src/Adapter/Mysql.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Possibly invalid array key type mixed.

Check failure on line 35 in src/Adapter/Mysql.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Possibly invalid array key type mixed.
}

if (! empty($config->sslCert)) {
$options[PDO::MYSQL_ATTR_SSL_CERT] = $config->sslCert;
$options[constant($mysqlConstantPrefix . 'SSL_CERT')] = $config->sslCert;

Check failure on line 39 in src/Adapter/Mysql.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Possibly invalid array key type mixed.

Check failure on line 39 in src/Adapter/Mysql.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Possibly invalid array key type mixed.
}

if (! empty($config->sslCa)) {
$options[PDO::MYSQL_ATTR_SSL_CA] = $config->sslCa;
$options[constant($mysqlConstantPrefix . 'SSL_CA')] = $config->sslCa;

Check failure on line 43 in src/Adapter/Mysql.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Possibly invalid array key type mixed.

Check failure on line 43 in src/Adapter/Mysql.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Possibly invalid array key type mixed.
}

if (! empty($config->sslCapath)) {
$options[PDO::MYSQL_ATTR_SSL_CAPATH] = $config->sslCapath;
$options[constant($mysqlConstantPrefix . 'SSL_CAPATH')] = $config->sslCapath;

Check failure on line 47 in src/Adapter/Mysql.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Possibly invalid array key type mixed.

Check failure on line 47 in src/Adapter/Mysql.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Possibly invalid array key type mixed.
}

if (! empty($config->sslCipher)) {
$options[PDO::MYSQL_ATTR_SSL_CIPHER] = $config->sslCipher;
$options[constant($mysqlConstantPrefix . 'SSL_CIPHER')] = $config->sslCipher;
}

if (
defined('PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT')
defined($mysqlConstantPrefix . 'SSL_VERIFY_SERVER_CERT')
&& ! empty($config->sslDoNotVerifyServerCert)
) {
$options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false;
$options[constant($mysqlConstantPrefix . 'SSL_VERIFY_SERVER_CERT')] = false;
}
}

Expand Down
30 changes: 15 additions & 15 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ public function ping($reconnect = true)
* Fetch and return all result rows as sequential array
*
* @param Select|string $stmt The SQL statement to prepare and execute.
* @param array $values Values to bind to the statement
* @param ?array $values Values to bind to the statement
*
* @return array
*/
public function fetchAll($stmt, array $values = null)
public function fetchAll($stmt, ?array $values = null)
{
return $this->prepexec($stmt, $values)
->fetchAll();
Expand All @@ -224,11 +224,11 @@ public function fetchAll($stmt, array $values = null)
* Fetch and return the first column of all result rows as sequential array
*
* @param Select|string $stmt The SQL statement to prepare and execute.
* @param array $values Values to bind to the statement
* @param ?array $values Values to bind to the statement
*
* @return array
*/
public function fetchCol($stmt, array $values = null)
public function fetchCol($stmt, ?array $values = null)
{
return $this->prepexec($stmt, $values)
->fetchAll(PDO::FETCH_COLUMN, 0);
Expand All @@ -238,11 +238,11 @@ public function fetchCol($stmt, array $values = null)
* Fetch and return the first row of the result rows
*
* @param Select|string $stmt The SQL statement to prepare and execute.
* @param array $values Values to bind to the statement
* @param ?array $values Values to bind to the statement
*
* @return array
*/
public function fetchOne($stmt, array $values = null)
public function fetchOne($stmt, ?array $values = null)
{
return $this->prepexec($stmt, $values)
->fetch();
Expand All @@ -251,7 +251,7 @@ public function fetchOne($stmt, array $values = null)
/**
* Alias of {@link fetchOne()}
*/
public function fetchRow($stmt, array $values = null)
public function fetchRow($stmt, ?array $values = null)
{
return $this->prepexec($stmt, $values)
->fetch();
Expand All @@ -263,11 +263,11 @@ public function fetchRow($stmt, array $values = null)
* First column is the key and the second column is the value.
*
* @param Select|string $stmt The SQL statement to prepare and execute.
* @param array $values Values to bind to the statement
* @param ?array $values Values to bind to the statement
*
* @return array
*/
public function fetchPairs($stmt, array $values = null)
public function fetchPairs($stmt, ?array $values = null)
{
return $this->prepexec($stmt, $values)
->fetchAll(PDO::FETCH_KEY_PAIR);
Expand All @@ -277,11 +277,11 @@ public function fetchPairs($stmt, array $values = null)
* Fetch and return the first column of the first result row
*
* @param Select|string $stmt The SQL statement to prepare and execute.
* @param array $values Values to bind to the statement
* @param ?array $values Values to bind to the statement
*
* @return string
*/
public function fetchScalar($stmt, array $values = null)
public function fetchScalar($stmt, ?array $values = null)
{
return $this->prepexec($stmt, $values)
->fetchColumn(0);
Expand Down Expand Up @@ -343,11 +343,11 @@ public function yieldAll($stmt, ...$args)
* Yield the first column of each result row
*
* @param Select|string $stmt The SQL statement to prepare and execute
* @param array $values Values to bind to the statement
* @param ?array $values Values to bind to the statement
*
* @return \Generator
*/
public function yieldCol($stmt, array $values = null)
public function yieldCol($stmt, ?array $values = null)
{
$sth = $this->prepexec($stmt, $values);

Expand All @@ -362,11 +362,11 @@ public function yieldCol($stmt, array $values = null)
* Yield key-value pairs with the first column as key and the second column as value for each result row
*
* @param Select|string $stmt The SQL statement to prepare and execute
* @param array $values Values to bind to the statement
* @param ?array $values Values to bind to the statement
*
* @return \Generator
*/
public function yieldPairs($stmt, array $values = null)
public function yieldPairs($stmt, ?array $values = null)
{
$sth = $this->prepexec($stmt, $values);

Expand Down
4 changes: 2 additions & 2 deletions src/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class Expression implements ExpressionInterface
* Create a new database expression
*
* @param string $statement The statement of the expression
* @param array $columns The columns used by the expression
* @param ?array $columns The columns used by the expression
* @param mixed ...$values The values for the expression
*/
public function __construct($statement, array $columns = null, ...$values)
public function __construct($statement, ?array $columns = null, ...$values)
{
$this->statement = $statement;
$this->columns = $columns;
Expand Down
36 changes: 18 additions & 18 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ public function buildWith(array $with, array &$values)
/**
* Build the DELETE FROM part of a query
*
* @param array $from
* @param ?array $from
*
* @return string The DELETE FROM part of a query
*/
public function buildDeleteFrom(array $from = null)
public function buildDeleteFrom(?array $from = null)
{
if ($from === null) {
return '';
Expand Down Expand Up @@ -486,12 +486,12 @@ public function buildCondition(array $condition, array &$values)
/**
* Build the WHERE part of a query
*
* @param array $where
* @param ?array $where
* @oaram array $values
*
* @return string The WHERE part of the query
*/
public function buildWhere(array $where = null, array &$values = [])
public function buildWhere(?array $where = null, array &$values = [])
{
if ($where === null) {
return '';
Expand Down Expand Up @@ -609,12 +609,12 @@ public function buildSelect(array $columns, $distinct, array &$values)
/**
* Build the FROM part of a query
*
* @param array $from
* @param ?array $from
* @param array $values
*
* @return string The FROM part of the query
*/
public function buildFrom(array $from = null, array &$values = [])
public function buildFrom(?array $from = null, array &$values = [])
{
if ($from === null) {
return '';
Expand Down Expand Up @@ -686,12 +686,12 @@ public function buildJoin($joins, array &$values)
/**
* Build the GROUP BY part of a query
*
* @param array $groupBy
* @param ?array $groupBy
* @param array $values
*
* @return string The GROUP BY part of the query
*/
public function buildGroupBy(array $groupBy = null, array &$values = [])
public function buildGroupBy(?array $groupBy = null, array &$values = [])
{
if ($groupBy === null) {
return '';
Expand All @@ -711,12 +711,12 @@ public function buildGroupBy(array $groupBy = null, array &$values = [])
/**
* Build the HAVING part of a query
*
* @param array $having
* @param ?array $having
* @param array $values
*
* @return string The HAVING part of the query
*/
public function buildHaving(array $having = null, array &$values = [])
public function buildHaving(?array $having = null, array &$values = [])
{
if ($having === null) {
return '';
Expand All @@ -728,12 +728,12 @@ public function buildHaving(array $having = null, array &$values = [])
/**
* Build the ORDER BY part of a query
*
* @param array $orderBy
* @param ?array $orderBy
* @param array $values
*
* @return string The ORDER BY part of the query
*/
public function buildOrderBy(array $orderBy = null, array &$values = [])
public function buildOrderBy(?array $orderBy = null, array &$values = [])
{
if ($orderBy === null) {
return '';
Expand Down Expand Up @@ -798,12 +798,12 @@ public function buildLimitOffset($limit = null, $offset = null)
/**
* Build the UNION parts of a query
*
* @param array $unions
* @param ?array $unions
* @param array $values
*
* @return array|null The UNION parts of the query
*/
public function buildUnions(array $unions = null, array &$values = [])
public function buildUnions(?array $unions = null, array &$values = [])
{
if ($unions === null) {
return null;
Expand All @@ -829,11 +829,11 @@ public function buildUnions(array $unions = null, array &$values = [])
/**
* Build the UPDATE {table} part of a query
*
* @param array $updateTable The table to UPDATE
* @param ?array $updateTable The table to UPDATE
*
* @return string The UPDATE {table} part of the query
*/
public function buildUpdateTable(array $updateTable = null)
public function buildUpdateTable(?array $updateTable = null)
{
if ($updateTable === null) {
return '';
Expand All @@ -857,12 +857,12 @@ public function buildUpdateTable(array $updateTable = null)
/**
* Build the SET part of a UPDATE query
*
* @param array $set
* @param ?array $set
* @param array $values
*
* @return string The SET part of a UPDATE query
*/
public function buildUpdateSet(array $set = null, array &$values = [])
public function buildUpdateSet(?array $set = null, array &$values = [])
{
if (empty($set)) {
return '';
Expand Down
2 changes: 1 addition & 1 deletion src/Test/SqlAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function setUpSqlAssertions(): void
*
* @return void
*/
public function assertSql(string $sql, $statement, array $values = null, string $message = ''): void
public function assertSql(string $sql, $statement, ?array $values = null, string $message = ''): void
{
// Reduce whitespaces to just one space
$sql = preg_replace('/\s+/', ' ', trim($sql));
Expand Down
4 changes: 2 additions & 2 deletions src/Test/TestConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getIterator(): \Iterator
return new \ArrayIterator([]);
}

public function setFetchMode($mode, ...$args): bool
public function setFetchMode($mode, ...$args): true
{
return true;
}
Expand All @@ -55,7 +55,7 @@ public function getIterator(): \Iterator
return new \ArrayIterator([]);
}

public function setFetchMode($mode, $params = null): bool
public function setFetchMode($mode, ...$params): true
{
return true;
}
Expand Down
Loading