Skip to content

Commit b2e4387

Browse files
author
Stepan Zolotarev
committed
CS and tests fixes
1 parent 0be6aba commit b2e4387

29 files changed

+196
-366
lines changed

src/Common/StorageConfiguration.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,14 @@ public function __construct(string $connectionDSN)
135135
$parsedDSN = \parse_url((string) $preparedDSN);
136136

137137
// @codeCoverageIgnoreStart
138-
if (\is_array($parsedDSN) === false)
139-
{
138+
if (\is_array($parsedDSN) === false) {
140139
throw new InvalidConfigurationOptions('Error while parsing connection DSN');
141140
}
142141
// @codeCoverageIgnoreEnd
143142

144143
$queryString = 'charset=UTF-8';
145144

146-
if (!empty($parsedDSN['query']))
147-
{
145+
if (!empty($parsedDSN['query'])) {
148146
$queryString = $parsedDSN['query'];
149147
}
150148

src/Module/SqlStorageModule.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ public function boot(ContainerBuilder $containerBuilder): void
9999

100100
$adapterDefinitionParameters = [new Reference(StorageConfiguration::class)];
101101

102-
if (true === $this->loggerEnabled)
103-
{
102+
if (true === $this->loggerEnabled) {
104103
$adapterDefinitionParameters[] = new Reference(LoggerInterface::class);
105104
}
106105

src/Sql/AmpPosgreSQL/AmpPostgreSQLAdapter.php

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use ServiceBus\Storage\Common\DatabaseAdapter;
2727
use ServiceBus\Storage\Common\Exceptions\InvalidConfigurationOptions;
2828
use ServiceBus\Storage\Common\StorageConfiguration;
29+
2930
use function Amp\call;
3031
use function Amp\Postgres\connector;
3132

@@ -61,8 +62,7 @@ final class AmpPostgreSQLAdapter implements DatabaseAdapter
6162
public function __construct(StorageConfiguration $configuration, ?LoggerInterface $logger = null)
6263
{
6364
// @codeCoverageIgnoreStart
64-
if (\extension_loaded('pgsql') === false)
65-
{
65+
if (\extension_loaded('pgsql') === false) {
6666
throw new InvalidConfigurationOptions('ext-pgsql must be installed');
6767
}
6868
// @codeCoverageIgnoreEnd
@@ -79,19 +79,15 @@ public function __destruct()
7979
public function execute(string $queryString, array $parameters = []): Promise
8080
{
8181
return call(
82-
function () use ($queryString, $parameters): \Generator
83-
{
84-
try
85-
{
82+
function () use ($queryString, $parameters): \Generator {
83+
try {
8684
$this->logger->debug($queryString, $parameters);
8785

8886
/** @var Iterator|CommandResult|PooledResultSet $resultSet */
8987
$resultSet = yield $this->pool()->execute($queryString, $parameters);
9088

9189
return new AmpPostgreSQLResultSet($resultSet);
92-
}
93-
catch (\Throwable $throwable)
94-
{
90+
} catch (\Throwable $throwable) {
9591
throw adaptAmpThrowable($throwable);
9692
}
9793
}
@@ -101,17 +97,15 @@ function () use ($queryString, $parameters): \Generator
10197
public function transactional(callable $function): Promise
10298
{
10399
return call(
104-
function () use ($function): \Generator
105-
{
100+
function () use ($function): \Generator {
106101
/** @var \Amp\Postgres\Transaction $originalTransaction */
107102
$originalTransaction = yield $this->pool()->beginTransaction();
108103

109104
$transaction = new AmpPostgreSQLTransaction($originalTransaction, $this->logger);
110105

111106
$this->logger->debug('BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED');
112107

113-
try
114-
{
108+
try {
115109
/** @var \Generator $generator */
116110
$generator = $function($transaction);
117111

@@ -120,15 +114,11 @@ function () use ($function): \Generator
120114
yield new Coroutine($generator);
121115

122116
yield $transaction->commit();
123-
}
124-
catch (\Throwable $throwable)
125-
{
117+
} catch (\Throwable $throwable) {
126118
yield $transaction->rollback();
127119

128120
throw $throwable;
129-
}
130-
finally
131-
{
121+
} finally {
132122
unset($transaction);
133123
}
134124
}
@@ -138,10 +128,8 @@ function () use ($function): \Generator
138128
public function transaction(): Promise
139129
{
140130
return call(
141-
function (): \Generator
142-
{
143-
try
144-
{
131+
function (): \Generator {
132+
try {
145133
$this->logger->debug('BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED');
146134

147135
/** @var \Amp\Postgres\Transaction $transaction */
@@ -150,8 +138,7 @@ function (): \Generator
150138
return new AmpPostgreSQLTransaction($transaction, $this->logger);
151139
}
152140
// @codeCoverageIgnoreStart
153-
catch (\Throwable $throwable)
154-
{
141+
catch (\Throwable $throwable) {
155142
throw adaptAmpThrowable($throwable);
156143
}
157144
// @codeCoverageIgnoreEnd
@@ -161,8 +148,7 @@ function (): \Generator
161148

162149
public function unescapeBinary($payload): string
163150
{
164-
if (\is_resource($payload))
165-
{
151+
if (\is_resource($payload)) {
166152
$payload = \stream_get_contents($payload, -1, 0);
167153
}
168154

@@ -174,8 +160,7 @@ public function unescapeBinary($payload): string
174160
*/
175161
private function pool(): Pool
176162
{
177-
if ($this->pool === null)
178-
{
163+
if ($this->pool === null) {
179164
$queryData = $this->configuration->queryParameters;
180165

181166
$this->pool = new Pool(

src/Sql/AmpPosgreSQL/AmpPostgreSQLResultSet.php

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Amp\Success;
2222
use ServiceBus\Storage\Common\Exceptions\ResultSetIterationFailed;
2323
use ServiceBus\Storage\Common\ResultSet;
24+
2425
use function Amp\call;
2526

2627
class AmpPostgreSQLResultSet implements ResultSet
@@ -44,29 +45,24 @@ public function advance(): Promise
4445
{
4546
$this->advanceCalled = true;
4647

47-
try
48-
{
49-
if ($this->originalResultSet instanceof Iterator)
50-
{
48+
try {
49+
if ($this->originalResultSet instanceof Iterator) {
5150
return $this->originalResultSet->advance();
5251
}
5352

5453
return new Success(false);
5554
}
5655
// @codeCoverageIgnoreStart
57-
catch (\Throwable $throwable)
58-
{
56+
catch (\Throwable $throwable) {
5957
throw new ResultSetIterationFailed($throwable->getMessage(), (int) $throwable->getCode(), $throwable);
6058
}
6159
// @codeCoverageIgnoreEnd
6260
}
6361

6462
public function getCurrent(): ?array
6563
{
66-
try
67-
{
68-
if ($this->originalResultSet instanceof CommandResult)
69-
{
64+
try {
65+
if ($this->originalResultSet instanceof CommandResult) {
7066
return null;
7167
}
7268

@@ -78,8 +74,7 @@ public function getCurrent(): ?array
7874
return $data;
7975
}
8076
// @codeCoverageIgnoreStart
81-
catch (\Throwable $throwable)
82-
{
77+
catch (\Throwable $throwable) {
8378
throw new ResultSetIterationFailed($throwable->getMessage(), (int) $throwable->getCode(), $throwable);
8479
}
8580
// @codeCoverageIgnoreEnd
@@ -88,14 +83,10 @@ public function getCurrent(): ?array
8883
public function lastInsertId(): Promise
8984
{
9085
return call(
91-
function (): \Generator
92-
{
93-
try
94-
{
95-
if ($this->originalResultSet instanceof PooledResultSet)
96-
{
97-
if ($this->advanceCalled === false)
98-
{
86+
function (): \Generator {
87+
try {
88+
if ($this->originalResultSet instanceof PooledResultSet) {
89+
if ($this->advanceCalled === false) {
9990
yield $this->originalResultSet->advance();
10091

10192
$this->advanceCalled = true;
@@ -104,22 +95,18 @@ function (): \Generator
10495
/** @var array<string, mixed> $result */
10596
$result = $this->originalResultSet->getCurrent();
10697

107-
if (\count($result) !== 0)
108-
{
98+
if (\count($result) !== 0) {
10999
/** @var bool|int|string $value */
110100
$value = \reset($result);
111101

112-
if (false !== $value)
113-
{
102+
if (false !== $value) {
114103
return (string) $value;
115104
}
116105
}
117106
}
118107

119108
return null;
120-
}
121-
catch (\Throwable $throwable)
122-
{
109+
} catch (\Throwable $throwable) {
123110
throw new ResultSetIterationFailed($throwable->getMessage(), (int) $throwable->getCode(), $throwable);
124111
}
125112
// @codeCoverageIgnoreEnd
@@ -129,8 +116,7 @@ function (): \Generator
129116

130117
public function affectedRows(): int
131118
{
132-
try
133-
{
119+
try {
134120
if (
135121
$this->originalResultSet instanceof PgSqlCommandResult ||
136122
$this->originalResultSet instanceof PqCommandResult
@@ -141,8 +127,7 @@ public function affectedRows(): int
141127
return 0;
142128
}
143129
// @codeCoverageIgnoreStart
144-
catch (\Throwable $throwable)
145-
{
130+
catch (\Throwable $throwable) {
146131
throw new ResultSetIterationFailed($throwable->getMessage(), (int) $throwable->getCode(), $throwable);
147132
}
148133
// @codeCoverageIgnoreEnd

src/Sql/AmpPosgreSQL/AmpPostgreSQLTransaction.php

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Amp\Promise;
2121
use Psr\Log\LoggerInterface;
2222
use ServiceBus\Storage\Common\Transaction;
23+
2324
use function Amp\call;
2425

2526
/**
@@ -47,19 +48,16 @@ public function __construct(AmpTransaction $transaction, LoggerInterface $logger
4748

4849
public function __destruct()
4950
{
50-
if ($this->transaction->isAlive())
51-
{
51+
if ($this->transaction->isAlive()) {
5252
$this->transaction->close();
5353
}
5454
}
5555

5656
public function execute(string $queryString, array $parameters = []): Promise
5757
{
5858
return call(
59-
function () use ($queryString, $parameters): \Generator
60-
{
61-
try
62-
{
59+
function () use ($queryString, $parameters): \Generator {
60+
try {
6361
$this->logger->debug($queryString, $parameters);
6462

6563
/** @var AmpResultSet|PgSqlCommandResult|PooledResultSet|PqCommandResult $resultSet */
@@ -68,8 +66,7 @@ function () use ($queryString, $parameters): \Generator
6866
return new AmpPostgreSQLResultSet($resultSet);
6967
}
7068
// @codeCoverageIgnoreStart
71-
catch (\Throwable $throwable)
72-
{
69+
catch (\Throwable $throwable) {
7370
throw adaptAmpThrowable($throwable);
7471
}
7572
// @codeCoverageIgnoreEnd
@@ -80,21 +77,16 @@ function () use ($queryString, $parameters): \Generator
8077
public function commit(): Promise
8178
{
8279
return call(
83-
function (): \Generator
84-
{
85-
try
86-
{
80+
function (): \Generator {
81+
try {
8782
$this->logger->debug('COMMIT');
8883

8984
yield $this->transaction->commit();
9085
}
9186
// @codeCoverageIgnoreStart
92-
catch (\Throwable $throwable)
93-
{
87+
catch (\Throwable $throwable) {
9488
throw adaptAmpThrowable($throwable);
95-
}
96-
finally
97-
{
89+
} finally {
9890
$this->transaction->close();
9991
}
10092
// @codeCoverageIgnoreEnd
@@ -105,21 +97,16 @@ function (): \Generator
10597
public function rollback(): Promise
10698
{
10799
return call(
108-
function (): \Generator
109-
{
110-
try
111-
{
100+
function (): \Generator {
101+
try {
112102
$this->logger->debug('ROLLBACK');
113103

114104
yield $this->transaction->rollback();
115105
}
116106
// @codeCoverageIgnoreStart
117-
catch (\Throwable)
118-
{
107+
catch (\Throwable) {
119108
/** We will not throw an exception */
120-
}
121-
finally
122-
{
109+
} finally {
123110
$this->transaction->close();
124111
}
125112
// @codeCoverageIgnoreEnd
@@ -129,8 +116,7 @@ function (): \Generator
129116

130117
public function unescapeBinary($payload): string
131118
{
132-
if (\is_resource($payload))
133-
{
119+
if (\is_resource($payload)) {
134120
$payload = \stream_get_contents($payload, -1, 0);
135121
}
136122

src/Sql/AmpPosgreSQL/functions.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ function adaptAmpThrowable(\Throwable $throwable): \Throwable
3838
);
3939
}
4040

41-
if ($throwable instanceof ConnectionException)
42-
{
41+
if ($throwable instanceof ConnectionException) {
4342
/** @psalm-suppress RedundantCast */
4443
return new InternalExceptions\ConnectionFailed(
4544
$throwable->getMessage(),

0 commit comments

Comments
 (0)