Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support PHP8 #10

Merged
merged 4 commits into from
Jan 28, 2021
Merged
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
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
language: php

php:
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0

cache:
directories:
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
}
],
"require": {
"php": ">=7.1",
"php": ">=8.0",
"ext-pdo": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"php-coveralls/php-coveralls": "^2.2",
"phpunit/phpunit": "^7.0",
"vimeo/psalm": "~3.11.0"
"phpunit/phpunit": "^7.0|^9.3",
"vimeo/psalm": "dev-master#f1123d0ccc75a2e565198c92b17b720d0f5485c4"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 8 additions & 8 deletions src/AbstractConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function errorInfo()
/**
* {@inheritdoc}
*/
public function exec($statement)
public function exec(string $statement)
{
return $this->getPdo()->exec($statement);
}
Expand All @@ -97,33 +97,33 @@ public function inTransaction()
/**
* {@inheritdoc}
*/
public function lastInsertId($name = null)
public function lastInsertId(?string $name = null)
{
return $this->getPdo()->lastInsertId();
}

/**
* {@inheritdoc}
*/
public function prepare($statement)
public function prepare(string $statement, array $options = [])
{
return $this->getPdo()->prepare($statement);
return $this->getPdo()->prepare($statement, $options);
}

/**
* {@inheritdoc}
*/
public function query($statement, $param1 = null, $param2 = null, $param3 = null)
public function query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs)
{
return $this->getPdo()->query($statement, $param1, $param2, $param3);
return $this->getPdo()->query($query, $fetchMode, ...$fetchModeArgs);
}

/**
* {@inheritdoc}
*/
public function quote($string, $parameter_type = \PDO::PARAM_STR)
public function quote(string $string, int $type = \PDO::PARAM_STR)
{
return $this->getPdo()->quote($string, $parameter_type);
return $this->getPdo()->quote($string, $type);
}

/**
Expand Down
20 changes: 10 additions & 10 deletions src/ListenableConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function errorInfo()
/**
* {@inheritdoc}
*/
public function exec($statement)
public function exec(string $statement)
{
$start = microtime(true);

Expand All @@ -93,17 +93,17 @@ public function inTransaction()
/**
* {@inheritdoc}
*/
public function lastInsertId($name = null)
public function lastInsertId(?string $name = null)
{
return $this->delegate->lastInsertId();
}

/**
* {@inheritdoc}
*/
public function prepare($statement)
public function prepare(string $statement, array $options = [])
{
$stmt = $this->delegate->prepare($statement);
$stmt = $this->delegate->prepare($statement, $options);
if ($stmt !== false) {
$stmt = new ListenableStatement($this->delegate, $this->listeners, $stmt, $statement);
}
Expand All @@ -113,20 +113,20 @@ public function prepare($statement)
/**
* {@inheritdoc}
*/
public function query($statement, $param1 = null, $param2 = null, $param3 = null)
public function query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs)
{
$start = microtime(true);

$stmt = $this->delegate->query($statement, $param1, $param2, $param3);
$stmt = $this->delegate->query($query, $fetchMode, ...$fetchModeArgs);

if ($stmt !== false) {
$elapsedTime = microtime(true) - $start;

foreach ($this->listeners as $listener) {
$listener->onQuery($this->delegate, $statement, [], $elapsedTime);
$listener->onQuery($this->delegate, $query, [], $elapsedTime);
}

$stmt = new ListenableStatement($this->delegate, $this->listeners, $stmt, $statement);
$stmt = new ListenableStatement($this->delegate, $this->listeners, $stmt, $query);
}

return $stmt;
Expand All @@ -135,9 +135,9 @@ public function query($statement, $param1 = null, $param2 = null, $param3 = null
/**
* {@inheritdoc}
*/
public function quote($string, $parameter_type = \PDO::PARAM_STR)
public function quote(string $string, int $type = \PDO::PARAM_STR)
{
return $this->delegate->quote($string, $parameter_type);
return $this->delegate->quote($string, $type);
}

/**
Expand Down
28 changes: 14 additions & 14 deletions src/ListenableStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public function getIterator()
/**
* {@inheritdoc}
*/
public function bindValue($parameter, $value, $data_type = \PDO::PARAM_STR)
public function bindValue(string $param, mixed $value, int $type = \PDO::PARAM_STR)
{
$this->bindings[] = $value;

return $this->delegate->bindValue($parameter, $value, $data_type);
return $this->delegate->bindValue($param, $value, $type);
}

/**
Expand All @@ -77,16 +77,16 @@ public function errorInfo()
/**
* {@inheritdoc}
*/
public function execute($input_parameters = null)
public function execute(?array $params = null)
{
$start = microtime(true);

try {
return $this->delegate->execute($input_parameters);
return $this->delegate->execute($params);
} finally {
$elapsedTime = microtime(true) - $start;
$bindings = $input_parameters !== null
? array_merge($this->bindings, $input_parameters)
$bindings = $params !== null
? array_merge($this->bindings, $params)
: $this->bindings;

foreach ($this->listeners as $listener) {
Expand All @@ -98,25 +98,25 @@ public function execute($input_parameters = null)
/**
* {@inheritdoc}
*/
public function fetch($fetch_style = null, $cursor_orientation = null, $cursor_offset = null)
public function fetch(int $mode = \PDO::ATTR_DEFAULT_FETCH_MODE, int $cursorOrientation = PDO::FETCH_ORI_NEXT, int $cursorOffset = 0)
{
return $this->delegate->Fetch($fetch_style, $cursor_orientation, $cursor_offset);
return $this->delegate->Fetch($mode, $cursorOrientation, $cursorOffset);
}

/**
* {@inheritdoc}
*/
public function fetchAll($fetch_style = null, $fetch_argument = null, $ctor_args = null)
public function fetchAll(int $mode = \PDO::ATTR_DEFAULT_FETCH_MODE, mixed ...$args)
{
return $this->delegate->FetchAll($fetch_style, $fetch_argument, $ctor_args);
return $this->delegate->FetchAll($mode, ...$args);
}

/**
* {@inheritdoc}
*/
public function fetchColumn($column_number = 0)
public function fetchColumn(int $column = 0)
{
return $this->delegate->fetchColumn($column_number);
return $this->delegate->fetchColumn($column);
}

/**
Expand All @@ -130,8 +130,8 @@ public function rowCount()
/**
* {@inheritdoc}
*/
public function setFetchMode($mode, $param1 = null, $param2 = null)
public function setFetchMode(int $mode, mixed ...$args)
{
return $this->delegate->setFetchMode($mode, $param1, $param2);
return $this->delegate->setFetchMode($mode, ...$args);
}
}
14 changes: 7 additions & 7 deletions src/MasterSlaveConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function errorInfo()
/**
* {@inheritdoc}
*/
public function exec($statement)
public function exec(string $statement)
{
return $this->activePdo->exec($statement);
}
Expand All @@ -93,33 +93,33 @@ public function inTransaction()
/**
* {@inheritdoc}
*/
public function lastInsertId($name = null)
public function lastInsertId(?string $name = null)
{
return $this->activePdo->lastInsertId();
}

/**
* {@inheritdoc}
*/
public function prepare($statement)
public function prepare(string $statement, array $options = [])
{
return $this->activePdo->prepare($statement);
}

/**
* {@inheritdoc}
*/
public function query($statement, $param1 = null, $param2 = null, $param3 = null)
public function query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs)
{
return $this->activePdo->query($statement, $param1, $param2, $param3);
return $this->activePdo->query($query, $fetchMode, ...$fetchModeArgs);
}

/**
* {@inheritdoc}
*/
public function quote($string, $parameter_type = \PDO::PARAM_STR)
public function quote(string $string, int $type = \PDO::PARAM_STR)
{
return $this->activePdo->quote($string, $parameter_type);
return $this->activePdo->quote($string, $type);
}

/**
Expand Down
23 changes: 9 additions & 14 deletions src/MysqliAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function errorInfo()
/**
* {@inheritdoc}
*/
public function exec($statement)
public function exec(string $statement)
{
if (!$this->mysqli->real_query($statement)) {
return false;
Expand All @@ -96,15 +96,15 @@ public function inTransaction()
/**
* {@inheritdoc}
*/
public function lastInsertId($name = null)
public function lastInsertId(?string $name = null)
{
return $this->mysqli->insert_id;
return (string) $this->mysqli->insert_id;
}

/**
* {@inheritdoc}
*/
public function prepare($statement)
public function prepare(string $statement, array $options = [])
{
$stmt = $this->mysqli->prepare($statement);
return $stmt !== false ? new MysqliStmtAdapter($stmt) : false;
Expand All @@ -113,18 +113,13 @@ public function prepare($statement)
/**
* {@inheritdoc}
*/
public function query($statement, $param1 = null, $param2 = null, $param3 = null)
public function query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs)
{
$stmt = $this->prepare($statement);
$stmt = $this->prepare($query);

if ($stmt !== false) {
if ($param1 === null) {
} elseif ($param2 === null) {
$stmt->setFetchMode($param1);
} elseif ($param3 !== null) {
$stmt->setFetchMode($param1, $param2);
} else {
$stmt->setFetchMode($param1, $param2, $param3);
if (!is_null($fetchMode)) {
$stmt->setFetchMode($fetchMode, ...$fetchModeArgs);
}

$stmt->execute();
Expand All @@ -136,7 +131,7 @@ public function query($statement, $param1 = null, $param2 = null, $param3 = null
/**
* {@inheritdoc}
*/
public function quote($string, $parameter_type = \PDO::PARAM_STR)
public function quote(string $string, int $type = \PDO::PARAM_STR)
{
return "'" . $this->mysqli->real_escape_string($string) . "'";
}
Expand Down
Loading