Skip to content

Commit

Permalink
Use Psalm
Browse files Browse the repository at this point in the history
Fixed type notations found by Psalm.
  • Loading branch information
trowski committed Jun 6, 2020
1 parent 2781a20 commit 807daec
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 60 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -29,7 +29,8 @@
"ext-pq": "*",
"amphp/phpunit-util": "^1.1.2",
"phpunit/phpunit": "^8 | ^7",
"amphp/php-cs-fixer-config": "dev-master"
"amphp/php-cs-fixer-config": "dev-master",
"vimeo/psalm": "^3.11@dev"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 15 additions & 0 deletions psalm.xml
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="7"
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>
22 changes: 11 additions & 11 deletions src/Connection.php
Expand Up @@ -35,23 +35,23 @@ public function __construct(Handle $handle)


/**
* {@inheritdoc}
* @inheritDoc
*/
final public function isAlive(): bool
{
return $this->handle->isAlive();
}

/**
* {@inheritdoc}
* @inheritDoc
*/
final public function getLastUsedAt(): int
{
return $this->handle->getLastUsedAt();
}

/**
* {@inheritdoc}
* @inheritDoc
*/
final public function close(): void
{
Expand Down Expand Up @@ -102,23 +102,23 @@ private function release(): void
}

/**
* {@inheritdoc}
* @inheritDoc
*/
final public function query(string $sql): Promise
{
return $this->send("query", $sql);
}

/**
* {@inheritdoc}
* @inheritDoc
*/
final public function execute(string $sql, array $params = []): Promise
{
return $this->send("execute", $sql, $params);
}

/**
* {@inheritdoc}
* @inheritDoc
*/
final public function prepare(string $sql): Promise
{
Expand All @@ -127,23 +127,23 @@ final public function prepare(string $sql): Promise


/**
* {@inheritdoc}
* @inheritDoc
*/
final public function notify(string $channel, string $payload = ""): Promise
{
return $this->send("notify", $channel, $payload);
}

/**
* {@inheritdoc}
* @inheritDoc
*/
final public function listen(string $channel): Promise
{
return $this->send("listen", $channel);
}

/**
* {@inheritdoc}
* @inheritDoc
*/
final public function beginTransaction(int $isolation = Transaction::ISOLATION_COMMITTED): Promise
{
Expand Down Expand Up @@ -181,15 +181,15 @@ final public function beginTransaction(int $isolation = Transaction::ISOLATION_C
}

/**
* {@inheritdoc}
* @inheritDoc
*/
final public function quoteString(string $data): string
{
return $this->handle->quoteString($data);
}

/**
* {@inheritdoc}
* @inheritDoc
*/
final public function quoteName(string $name): string
{
Expand Down
4 changes: 2 additions & 2 deletions src/ConnectionListener.php
Expand Up @@ -36,7 +36,7 @@ public function __destruct()
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function continue(): Promise
{
Expand Down Expand Up @@ -68,7 +68,7 @@ public function isListening(): bool
/**
* Unlistens from the channel. No more values will be emitted from this listener.
*
* @return Promise<\Amp\Sql\CommandResult>
* @return Promise<void>
*
* @throws \Error If this method was previously invoked.
*/
Expand Down
18 changes: 9 additions & 9 deletions src/ConnectionTransaction.php
Expand Up @@ -63,15 +63,15 @@ public function __destruct()
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function getLastUsedAt(): int
{
return $this->handle->getLastUsedAt();
}

/**
* {@inheritdoc}
* @inheritDoc
*
* Closes and commits all changes in the transaction.
*/
Expand All @@ -83,7 +83,7 @@ public function close(): void
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function isAlive(): bool
{
Expand All @@ -107,7 +107,7 @@ public function getIsolationLevel(): int
}

/**
* {@inheritdoc}
* @inheritDoc
*
* @throws TransactionError If the transaction has been committed or rolled back.
*/
Expand All @@ -131,7 +131,7 @@ public function query(string $sql): Promise
}

/**
* {@inheritdoc}
* @inheritDoc
*
* @throws TransactionError If the transaction has been committed or rolled back.
*/
Expand All @@ -155,7 +155,7 @@ public function prepare(string $sql): Promise
}

/**
* {@inheritdoc}
* @inheritDoc
*
* @throws TransactionError If the transaction has been committed or rolled back.
*/
Expand All @@ -180,7 +180,7 @@ public function execute(string $sql, array $params = []): Promise


/**
* {@inheritdoc}
* @inheritDoc
*
* @throws TransactionError If the transaction has been committed or rolled back.
*/
Expand Down Expand Up @@ -276,7 +276,7 @@ public function releaseSavepoint(string $identifier): Promise
}

/**
* {@inheritdoc}
* @inheritDoc
*
* @throws TransactionError If the transaction has been committed or rolled back.
*/
Expand All @@ -290,7 +290,7 @@ public function quoteString(string $data): string
}

/**
* {@inheritdoc}
* @inheritDoc
*
* @throws TransactionError If the transaction has been committed or rolled back.
*/
Expand Down
9 changes: 6 additions & 3 deletions src/Executor.php
Expand Up @@ -3,18 +3,21 @@
namespace Amp\Postgres;

use Amp\Promise;
use Amp\Sql\ConnectionException;
use Amp\Sql\Executor as SqlExecutor;
use Amp\Sql\FailureException;
use Amp\Sql\Result;

interface Executor extends SqlExecutor
{
/**
* @param string $channel Channel name.
* @param string $payload Notification payload.
*
* @return Promise<\Amp\Sql\CommandResult>
* @return Promise<Result>
*
* @throws \Amp\Sql\FailureException If the operation fails due to unexpected condition.
* @throws \Amp\Sql\ConnectionException If the connection to the database is lost.
* @throws FailureException If the operation fails due to unexpected condition.
* @throws ConnectionException If the connection to the database is lost.
*/
public function notify(string $channel, string $payload = ""): Promise;
}
2 changes: 1 addition & 1 deletion src/Listener.php
Expand Up @@ -25,7 +25,7 @@ public function isListening(): bool;
/**
* Unlistens from the channel. No more values will be emitted from this listener.
*
* @return Promise<\Amp\Sql\CommandResult>
* @return Promise<void>
*
* @throws \Error If this method was previously invoked.
*/
Expand Down
1 change: 1 addition & 0 deletions src/PgSqlConnection.php
Expand Up @@ -23,6 +23,7 @@ final class PgSqlConnection extends Connection implements Link
public static function connect(ConnectionConfig $connectionConfig, ?CancellationToken $token = null): Promise
{
// @codeCoverageIgnoreStart
/** @psalm-suppress UndefinedClass */
if (Loop::get()->getHandle() instanceof \EvLoop) {
throw new \Error('ext-pgsql is not compatible with pecl-ev; use pecl-pq or a different loop extension');
} // @codeCoverageIgnoreEnd
Expand Down
22 changes: 11 additions & 11 deletions src/PgSqlHandle.php
Expand Up @@ -47,7 +47,7 @@ final class PgSqlHandle implements Handle
/** @var StreamSource[] */
private $listeners = [];

/** @var Struct[] */
/** @var object[] Anonymous class using Struct trait. */
private $statements = [];

/** @var int */
Expand Down Expand Up @@ -154,7 +154,7 @@ public function __destruct()
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function close(): void
{
Expand All @@ -180,15 +180,15 @@ private function free(): void
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function isAlive(): bool
{
return \is_resource($this->handle);
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function getLastUsedAt(): int
{
Expand Down Expand Up @@ -337,7 +337,7 @@ public function statementDeallocate(string $name): Promise
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function query(string $sql): Promise
{
Expand All @@ -351,7 +351,7 @@ public function query(string $sql): Promise
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function execute(string $sql, array $params = []): Promise
{
Expand All @@ -368,7 +368,7 @@ public function execute(string $sql, array $params = []): Promise
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function prepare(string $sql): Promise
{
Expand Down Expand Up @@ -442,7 +442,7 @@ public function prepare(string $sql): Promise
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function notify(string $channel, string $payload = ""): Promise
{
Expand All @@ -454,7 +454,7 @@ public function notify(string $channel, string $payload = ""): Promise
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function listen(string $channel): Promise
{
Expand Down Expand Up @@ -502,7 +502,7 @@ private function unlisten(string $channel): Promise
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function quoteString(string $data): string
{
Expand All @@ -514,7 +514,7 @@ public function quoteString(string $data): string
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function quoteName(string $name): string
{
Expand Down
8 changes: 4 additions & 4 deletions src/PgSqlStatement.php
Expand Up @@ -42,25 +42,25 @@ public function __destruct()
$this->handle->statementDeallocate($this->name);
}

/** {@inheritdoc} */
/** @inheritDoc */
public function isAlive(): bool
{
return $this->handle->isAlive();
}

/** {@inheritdoc} */
/** @inheritDoc */
public function getQuery(): string
{
return $this->sql;
}

/** {@inheritdoc} */
/** @inheritDoc */
public function getLastUsedAt(): int
{
return $this->lastUsedAt;
}

/** {@inheritdoc} */
/** @inheritDoc */
public function execute(array $params = []): Promise
{
return $this->handle->statementExecute($this->name, Internal\replaceNamedParams($params, $this->params));
Expand Down

0 comments on commit 807daec

Please sign in to comment.