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: 1 addition & 2 deletions src/Adapter/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@

use ipl\Sql\Config;
use ipl\Sql\Connection;
use PDO;

class Mysql extends BaseAdapter
{
protected $quoteCharacter = ['`', '`'];

protected $escapeCharacter = '``';

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

Check failure on line 16 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 16 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 16 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 16 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 @@ -32,15 +31,15 @@

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

Check failure on line 34 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 34 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[constant($mysqlConstantPrefix . 'SSL_CERT')] = $config->sslCert;

Check failure on line 38 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 38 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[constant($mysqlConstantPrefix . 'SSL_CA')] = $config->sslCa;

Check failure on line 42 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 42 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)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Compat/FilterProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class FilterProcessor
{
public static function assembleFilter(Filter\Rule $filter, $level = 0)
public static function assembleFilter(Filter\Rule $filter, int $level = 0): ?array
{
$condition = null;

Expand Down Expand Up @@ -60,7 +60,7 @@ public static function assembleFilter(Filter\Rule $filter, $level = 0)
return $condition;
}

public static function assemblePredicate(Filter\Condition $filter)
public static function assemblePredicate(Filter\Condition $filter): array
{
$column = $filter->getColumn();
$expression = $filter->getValue();
Expand Down
45 changes: 16 additions & 29 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,31 @@

namespace ipl\Sql;

use InvalidArgumentException;
use ipl\Stdlib\Str;
use OutOfRangeException;

use function ipl\Stdlib\get_php_type;

/**
* SQL connection configuration
*/
class Config
{
/** @var string Type of the DBMS */
public $db;
/** @var ?string Type of the DBMS */
public ?string $db = null;

/** @var string Database host */
public $host;
/** @var ?string Database host */
public ?string $host = null;

/** @var int Database port */
public $port;
/** @var string|int|null Database port */
public string|int|null $port = null;

/** @var string Database name */
public $dbname;
/** @var ?string Database name */
public ?string $dbname = null;

/** @var string Username to use for authentication */
public $username;
/** @var ?string Username to use for authentication */
public ?string $username = null;

/** @var string Password to use for authentication */
public $password;
/** @var ?string Password to use for authentication */
public ?string $password = null;

/**
* Character set for the connection
Expand All @@ -38,7 +35,7 @@ class Config
*
* @var string
*/
public $charset;
public string $charset = '';

/**
* PDO connect options
Expand All @@ -48,30 +45,20 @@ class Config
*
* @var array
*/
public $options;
public array $options = [];

/** @var array Extra settings e.g. for SQL SSL connections */
protected $extraSettings = [];
protected array $extraSettings = [];

/**
* Create a new SQL connection configuration from the given configuration key-value pairs
*
* Keys will be converted to camelCase, e.g. use_ssl → useSsl.
*
* @param iterable $config Configuration key-value pairs
*
* @throws InvalidArgumentException If $config is not iterable
*/
public function __construct($config)
public function __construct(iterable $config)
{
if (! is_iterable($config)) {
throw new InvalidArgumentException(sprintf(
'%s expects parameter one to be iterable, got %s instead',
__METHOD__,
get_php_type($config)
));
}

foreach ($config as $key => $value) {
$key = Str::camel($key);
$this->$key = $value;
Expand Down
Loading
Loading