Add Psalm and fix doc types

This commit is contained in:
Aaron Piotrowski 2020-05-23 15:44:01 -05:00
parent 58f2931186
commit 83e21f8699
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
8 changed files with 32 additions and 19 deletions

View File

@ -16,8 +16,9 @@
},
"require-dev": {
"amphp/php-cs-fixer-config": "dev-master",
"amphp/phpunit-util": "^1",
"phpunit/phpunit": "^6"
"amphp/phpunit-util": "^1.1",
"phpunit/phpunit": "^9 | ^8 | ^7",
"vimeo/psalm": "^3.11@dev"
},
"autoload": {
"psr-4": {
@ -29,11 +30,6 @@
"Amp\\Sql\\Test\\": "test"
}
},
"config": {
"platform": {
"php": "7.0.0"
}
},
"scripts": {
"check": [
"@cs",

15
psalm.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
</psalm>

View File

@ -46,7 +46,8 @@ abstract class ConnectionConfig
}
foreach ($params as $param) {
list($key, $value) = \array_map("trim", \explode("=", $param, 2) + [1 => null]);
/** @psalm-suppress PossiblyInvalidArgument */
[$key, $value] = \array_map("trim", \explode("=", $param, 2) + [1 => null]);
if (isset($keymap[$key])) {
$key = $keymap[$key];

View File

@ -9,7 +9,7 @@ interface Executor extends TransientResource
/**
* @param string $sql SQL query to execute.
*
* @return Promise<CommandResult|ResultSet>
* @return Promise<Result>
*
* @throws FailureException If the operation fails due to unexpected condition.
* @throws ConnectionException If the connection to the database is lost.
@ -32,7 +32,7 @@ interface Executor extends TransientResource
* @param string $sql SQL query to prepare and execute.
* @param mixed[] $params Query parameters.
*
* @return Promise<CommandResult|ResultSet>
* @return Promise<Result>
*
* @throws FailureException If the operation fails due to unexpected condition.
* @throws ConnectionException If the connection to the database is lost.
@ -43,5 +43,5 @@ interface Executor extends TransientResource
/**
* Closes the executor. No further queries may be performed.
*/
public function close();
public function close(): void;
}

View File

@ -4,6 +4,7 @@ namespace Amp\Sql;
class QueryError extends \Error
{
/** @var string */
protected $query = "";
public function __construct(string $message, string $query = "", \Throwable $previous = null)

View File

@ -9,7 +9,7 @@ interface Statement extends TransientResource
/**
* @param mixed[] $params
*
* @return Promise<CommandResult|ResultSet>
* @return Promise<Result>
*/
public function execute(array $params = []): Promise;

View File

@ -24,7 +24,7 @@ interface Transaction extends Executor
/**
* Commits the transaction and makes it inactive.
*
* @return Promise<CommandResult>
* @return Promise<Result>
*
* @throws TransactionError If the transaction has been committed or rolled back.
*/
@ -33,7 +33,7 @@ interface Transaction extends Executor
/**
* Rolls back the transaction and makes it inactive.
*
* @return Promise<CommandResult>
* @return Promise<Result>
*
* @throws TransactionError If the transaction has been committed or rolled back.
*/
@ -44,7 +44,7 @@ interface Transaction extends Executor
*
* @param string $identifier Savepoint identifier.
*
* @return Promise<CommandResult>
* @return Promise<Result>
*
* @throws TransactionError If the transaction has been committed or rolled back.
*/
@ -55,7 +55,7 @@ interface Transaction extends Executor
*
* @param string $identifier Savepoint identifier.
*
* @return Promise<CommandResult>
* @return Promise<Result>
*
* @throws TransactionError If the transaction has been committed or rolled back.
*/
@ -66,7 +66,7 @@ interface Transaction extends Executor
*
* @param string $identifier Savepoint identifier.
*
* @return Promise<CommandResult>
* @return Promise<Result>
*
* @throws TransactionError If the transaction has been committed or rolled back.
*/

View File

@ -2,10 +2,10 @@
namespace Amp\Sql\Test;
use Amp\PHPUnit\TestCase;
use Amp\PHPUnit\AsyncTestCase;
use Amp\Sql\QueryError;
class QueryErrorTest extends TestCase
class QueryErrorTest extends AsyncTestCase
{
/**
* @test