Skip to content

Commit

Permalink
Improving static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
mmasiukevich committed Aug 26, 2020
1 parent 8dac2f7 commit 33a2f04
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 5,272 deletions.
5,127 changes: 0 additions & 5,127 deletions composer.lock

This file was deleted.

19 changes: 6 additions & 13 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
parameters:
ignoreErrors:
-
message: '#Unable to resolve the template type#'
path: %currentWorkingDirectory%/src
-
message: '#no value type specified in iterable type array#'
path: %currentWorkingDirectory%/src
-
message: '#with no value type specified#'
path: %currentWorkingDirectory%/src/Sql/DoctrineDBAL/
-
message: '#parameters of method#'
path: %currentWorkingDirectory%/src/Sql/Migration/SqlMigrationProcessor.php
checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false
ignoreErrors:
-
message: '#Unable to resolve the template type#'
path: %currentWorkingDirectory%/src
2 changes: 1 addition & 1 deletion src/Common/DatabaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function transaction(): Promise;
/**
* Executes a function in a transaction.
*
* @psalm-param callable(\ServiceBus\Storage\Common\QueryExecutor):\Generator<void> $function
* @psalm-param callable(\ServiceBus\Storage\Common\QueryExecutor):\Generator $function
*
* @return Promise<void>
*
Expand Down
2 changes: 1 addition & 1 deletion src/Common/QueryExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface QueryExecutor
/**
* Execute query.
*
* @psalm-param array<string, string|int|float|null> $parameters
* @psalm-param array<array-key, string|int|float|null> $parameters
*
* @return Promise<\ServiceBus\Storage\Common\ResultSet>
*
Expand Down
1 change: 0 additions & 1 deletion src/Common/StorageConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public function __construct(string $connectionDSN)

if ($databaseName !== null)
{
/** @psalm-suppress PossiblyInvalidArgument */
$databaseName = \ltrim($databaseName, '/');
}

Expand Down
34 changes: 4 additions & 30 deletions src/Sql/AmpPosgreSQL/AmpPostgreSQLAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,12 @@ public function __construct(StorageConfiguration $configuration, ?LoggerInterfac

public function __destruct()
{
/** @psalm-suppress RedundantConditionGivenDocblockType Null in case of error */
if ($this->pool !== null)
{
$this->pool->close();
}
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
*/
public function execute(string $queryString, array $parameters = []): Promise
{
return call(
Expand All @@ -81,7 +75,7 @@ function () use ($queryString, $parameters) : \Generator
{
$this->logger->debug($queryString, $parameters);

/** @var AmpResultSet|PgSqlCommandResult|PooledResultSet|PqCommandResult $resultSet */
/** @var AmpResultSet|PgSqlCommandResult|PooledResultSet|PqCommandResult $resultSet */
$resultSet = yield $this->pool()->execute($queryString, $parameters);

return new AmpPostgreSQLResultSet($resultSet);
Expand All @@ -94,21 +88,12 @@ function () use ($queryString, $parameters) : \Generator
);
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
*/
public function transactional(callable $function): Promise
{
return call(
function () use ($function): \Generator
{
/**
* @psalm-suppress TooManyTemplateParams
*
* @var \Amp\Postgres\Transaction $originalTransaction
*/
/** @var \Amp\Postgres\Transaction $originalTransaction */
$originalTransaction = yield $this->pool()->beginTransaction();

$transaction = new AmpPostgreSQLTransaction($originalTransaction, $this->logger);
Expand All @@ -117,13 +102,10 @@ function () use ($function): \Generator

try
{
/** @var \Generator<mixed> $generator */
/** @var \Generator $generator */
$generator = $function($transaction);

/**
* @psalm-suppress MixedArgumentTypeCoercion
* @psalm-suppress InvalidArgument
*/
/** @psalm-suppress MixedArgumentTypeCoercion */
yield new Coroutine($generator);

yield $transaction->commit();
Expand All @@ -142,11 +124,6 @@ function () use ($function): \Generator
);
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
*/
public function transaction(): Promise
{
return call(
Expand All @@ -171,9 +148,6 @@ function (): \Generator
);
}

/**
* {@inheritdoc}
*/
public function unescapeBinary($payload): string
{
if (\is_resource($payload) === true)
Expand Down
4 changes: 0 additions & 4 deletions src/Sql/AmpPosgreSQL/AmpPostgreSQLResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ class AmpPostgreSQLResultSet implements ResultSet
private $advanceCalled = false;

/**
* @noinspection PhpDocSignatureInspection
*
* @psalm-suppress TypeCoercion Assume a different data type
*
* @param AmpResultSet|PgSqlCommandResult|PooledResultSet|PqCommandResult $originalResultSet
*/
public function __construct(object $originalResultSet)
Expand Down
18 changes: 0 additions & 18 deletions src/Sql/AmpPosgreSQL/AmpPostgreSQLTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ public function __destruct()
}
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
*/
public function execute(string $queryString, array $parameters = []): Promise
{
return call(
Expand All @@ -78,11 +73,6 @@ function () use ($queryString, $parameters): \Generator
);
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
*/
public function commit(): Promise
{
return call(
Expand All @@ -109,11 +99,6 @@ function (): \Generator
);
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
*/
public function rollback(): Promise
{
return call(
Expand All @@ -139,9 +124,6 @@ function (): \Generator
);
}

/**
* {@inheritdoc}
*/
public function unescapeBinary($payload): string
{
if (\is_resource($payload) === true)
Expand Down
21 changes: 3 additions & 18 deletions src/Sql/DoctrineDBAL/DoctrineDBALAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public function __construct(StorageConfiguration $configuration, LoggerInterface
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
*/
public function execute(string $queryString, array $parameters = []): Promise
Expand Down Expand Up @@ -77,15 +75,10 @@ public function execute(string $queryString, array $parameters = []): Promise
}
catch (\Throwable $throwable)
{
return new Failure(adaptDbalThrowable($throwable));
throw adaptDbalThrowable($throwable);
}
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
*/
public function transactional(callable $function): Promise
{
return call(
Expand All @@ -96,7 +89,7 @@ function () use ($function): \Generator

try
{
/** @var \Generator<null> $generator */
/** @var \Generator $generator */
$generator = $function($transaction);

yield from $generator;
Expand All @@ -117,11 +110,6 @@ function () use ($function): \Generator
);
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
*/
public function transaction(): Promise
{
try
Expand All @@ -135,14 +123,11 @@ public function transaction(): Promise
// @codeCoverageIgnoreStart
catch (\Throwable $exception)
{
return new Failure(adaptDbalThrowable($exception));
throw adaptDbalThrowable($exception);
}
// @codeCoverageIgnoreEnd
}

/**
* {@inheritdoc}
*/
public function unescapeBinary($payload): string
{
/** @var resource|string $payload */
Expand Down
8 changes: 0 additions & 8 deletions src/Sql/DoctrineDBAL/DoctrineDBALResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ public function __construct(Connection $connection, Statement $wrappedStmt)
$this->resultsCount = \count($this->fetchResult);
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
*/
public function advance(): Promise
{
$this->currentRow = null;
Expand All @@ -92,9 +87,6 @@ public function advance(): Promise
return new Success(true);
}

/**
* {@inheritdoc}
*/
public function getCurrent(): ?array
{
if (null !== $this->currentRow)
Expand Down
22 changes: 1 addition & 21 deletions src/Sql/DoctrineDBAL/DoctrineDBALTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public function __construct(Connection $connection, LoggerInterface $logger)
$this->logger = $logger;
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
*/
public function execute(string $queryString, array $parameters = []): Promise
{
$this->logger->debug($queryString, $parameters);
Expand All @@ -66,17 +61,11 @@ public function execute(string $queryString, array $parameters = []): Promise
// @codeCoverageIgnoreStart
catch (\Throwable $throwable)
{
return new Failure(adaptDbalThrowable($throwable));
throw adaptDbalThrowable($throwable);
}
// @codeCoverageIgnoreEnd
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
* @psalm-suppress InvalidReturnType
*/
public function commit(): Promise
{
/** @psalm-suppress InvalidReturnStatement */
Expand All @@ -99,12 +88,6 @@ function (): void
);
}

/**
* {@inheritdoc}
*
* @psalm-suppress MixedReturnTypeCoercion
* @psalm-suppress InvalidReturnType
*/
public function rollback(): Promise
{
/** @psalm-suppress InvalidReturnStatement */
Expand All @@ -127,9 +110,6 @@ function (): void
);
}

/**
* {@inheritdoc}
*/
public function unescapeBinary($payload): string
{
/** @var resource|string $payload */
Expand Down
8 changes: 4 additions & 4 deletions src/Sql/Migration/SqlMigrationProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ function () use ($direction): \Generator
foreach ($migrations as $version => $migration)
{
/**
* @psalm-suppress InvalidScalarArgument
*
* @var \ServiceBus\Storage\Common\ResultSet $resultSet
*/
$resultSet = yield $transaction->execute(
Expand All @@ -135,8 +133,10 @@ function () use ($direction): \Generator

foreach ($queries as $query)
{
/** @psalm-suppress MixedArgument */
yield $transaction->execute($query, $parameters[\sha1($query)] ?? []);
/** @psalm-var array<array-key, string|int|float|null> $queryParameters */
$queryParameters = $parameters[\sha1($query)] ?? [];

yield $transaction->execute($query, $queryParameters);

$executedQueries++;
}
Expand Down
Loading

0 comments on commit 33a2f04

Please sign in to comment.