Skip to content

Commit c2a250a

Browse files
CarlSchwancome-nc
authored andcommitted
Cleanup plsam issues in DB/ContactsManager and Console
Signed-off-by: Carl Schwan <[email protected]>
1 parent 590c202 commit c2a250a

9 files changed

Lines changed: 58 additions & 111 deletions

File tree

build/psalm-baseline.xml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,32 +1806,6 @@
18061806
<code>dispatch</code>
18071807
</TooManyArguments>
18081808
</file>
1809-
<file src="lib/private/ContactsManager.php">
1810-
<InvalidNullableReturnType occurrences="3">
1811-
<code>IAddressBook</code>
1812-
<code>array</code>
1813-
<code>bool</code>
1814-
</InvalidNullableReturnType>
1815-
<NullableReturnStatement occurrences="5">
1816-
<code>null</code>
1817-
<code>null</code>
1818-
<code>null</code>
1819-
<code>null</code>
1820-
<code>null</code>
1821-
</NullableReturnStatement>
1822-
<ParamNameMismatch occurrences="2">
1823-
<code>$addressBook</code>
1824-
<code>$addressBook</code>
1825-
</ParamNameMismatch>
1826-
</file>
1827-
<file src="lib/private/DB/Adapter.php">
1828-
<InvalidReturnStatement occurrences="1">
1829-
<code>$builder-&gt;execute()</code>
1830-
</InvalidReturnStatement>
1831-
<InvalidReturnType occurrences="1">
1832-
<code>int</code>
1833-
</InvalidReturnType>
1834-
</file>
18351809
<file src="lib/private/DB/AdapterMySQL.php">
18361810
<InternalMethod occurrences="1">
18371811
<code>getParams</code>

lib/private/Console/Application.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,12 @@
4747
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
4848

4949
class Application {
50-
/** @var IConfig */
51-
private $config;
50+
private IConfig $config;
5251
private SymfonyApplication $application;
53-
/** @var EventDispatcherInterface */
54-
private $dispatcher;
55-
/** @var IRequest */
56-
private $request;
57-
/** @var LoggerInterface */
58-
private $logger;
59-
/** @var MemoryInfo */
60-
private $memoryInfo;
52+
private EventDispatcherInterface $dispatcher;
53+
private IRequest $request;
54+
private LoggerInterface $logger;
55+
private MemoryInfo $memoryInfo;
6156

6257
public function __construct(IConfig $config,
6358
EventDispatcherInterface $dispatcher,
@@ -74,8 +69,6 @@ public function __construct(IConfig $config,
7469
}
7570

7671
/**
77-
* @param InputInterface $input
78-
* @param ConsoleOutputInterface $output
7972
* @throws \Exception
8073
*/
8174
public function loadCommands(

lib/private/ContactsManager.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,32 @@ public function search($pattern, $searchProperties = [], $options = []) {
8888
* This function can be used to delete the contact identified by the given id
8989
*
9090
* @param int $id the unique identifier to a contact
91-
* @param string $address_book_key identifier of the address book in which the contact shall be deleted
91+
* @param string $addressBookKey identifier of the address book in which the contact shall be deleted
9292
* @return bool successful or not
9393
*/
94-
public function delete($id, $address_book_key) {
95-
$addressBook = $this->getAddressBook($address_book_key);
94+
public function delete($id, $addressBookKey) {
95+
$addressBook = $this->getAddressBook($addressBookKey);
9696
if (!$addressBook) {
97-
return null;
97+
return false;
9898
}
9999

100100
if ($addressBook->getPermissions() & Constants::PERMISSION_DELETE) {
101101
return $addressBook->delete($id);
102102
}
103103

104-
return null;
104+
return false;
105105
}
106106

107107
/**
108108
* This function is used to create a new contact if 'id' is not given or not present.
109109
* Otherwise the contact will be updated by replacing the entire data set.
110110
*
111111
* @param array $properties this array if key-value-pairs defines a contact
112-
* @param string $address_book_key identifier of the address book in which the contact shall be created or updated
113-
* @return array representing the contact just created or updated
112+
* @param string $addressBookKey identifier of the address book in which the contact shall be created or updated
113+
* @return ?array representing the contact just created or updated
114114
*/
115-
public function createOrUpdate($properties, $address_book_key) {
116-
$addressBook = $this->getAddressBook($address_book_key);
115+
public function createOrUpdate($properties, $addressBookKey) {
116+
$addressBook = $this->getAddressBook($addressBookKey);
117117
if (!$addressBook) {
118118
return null;
119119
}
@@ -130,7 +130,7 @@ public function createOrUpdate($properties, $address_book_key) {
130130
*
131131
* @return bool true if enabled, false if not
132132
*/
133-
public function isEnabled() {
133+
public function isEnabled(): bool {
134134
return !empty($this->addressBooks) || !empty($this->addressBookLoaders);
135135
}
136136

@@ -189,11 +189,8 @@ public function register(\Closure $callable) {
189189

190190
/**
191191
* Get (and load when needed) the address book for $key
192-
*
193-
* @param string $addressBookKey
194-
* @return IAddressBook
195192
*/
196-
protected function getAddressBook($addressBookKey) {
193+
protected function getAddressBook(string $addressBookKey): ?IAddressBook {
197194
$this->loadAddressBooks();
198195
if (!array_key_exists($addressBookKey, $this->addressBooks)) {
199196
return null;

lib/private/DB/Adapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function insertIgnoreConflict(string $table, array $values) : int {
142142
foreach ($values as $key => $value) {
143143
$builder->setValue($key, $builder->createNamedParameter($value));
144144
}
145-
return $builder->execute();
145+
return $builder->executeStatement();
146146
} catch (UniqueConstraintViolationException $e) {
147147
return 0;
148148
}

lib/private/DB/Connection.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function connect() {
137137
return $status;
138138
} catch (Exception $e) {
139139
// throw a new exception to prevent leaking info from the stacktrace
140-
throw new Exception('Failed to connect to the database: ' . $e->getMessage(), $e->getCode());
140+
throw new Exception('Failed to connect to the database: ' . $e->getMessage(), (int)$e->getCode());
141141
}
142142
}
143143

@@ -220,7 +220,7 @@ public function getPrefix() {
220220
* @return Statement The prepared statement.
221221
* @throws Exception
222222
*/
223-
public function prepare($statement, $limit = null, $offset = null): Statement {
223+
public function prepare($sql, $limit = null, $offset = null): Statement {
224224
if ($limit === -1 || $limit === null) {
225225
$limit = null;
226226
} else {
@@ -231,9 +231,9 @@ public function prepare($statement, $limit = null, $offset = null): Statement {
231231
}
232232
if (!is_null($limit)) {
233233
$platform = $this->getDatabasePlatform();
234-
$statement = $platform->modifyLimitQuery($statement, $limit, $offset);
234+
$sql = $platform->modifyLimitQuery($sql, $limit, $offset);
235235
}
236-
$statement = $this->replaceTablePrefix($statement);
236+
$statement = $this->replaceTablePrefix($sql);
237237
$statement = $this->adapter->fixupStatement($statement);
238238

239239
return parent::prepare($statement);
@@ -321,14 +321,14 @@ protected function logQueryToFile(string $sql): void {
321321
*
322322
* @param string $seqName Name of the sequence object from which the ID should be returned.
323323
*
324-
* @return string the last inserted ID.
324+
* @return int the last inserted ID.
325325
* @throws Exception
326326
*/
327-
public function lastInsertId($seqName = null) {
328-
if ($seqName) {
329-
$seqName = $this->replaceTablePrefix($seqName);
327+
public function lastInsertId($name = null): int {
328+
if ($name) {
329+
$name = $this->replaceTablePrefix($name);
330330
}
331-
return $this->adapter->lastInsertId($seqName);
331+
return $this->adapter->lastInsertId($name);
332332
}
333333

334334
/**

lib/private/DB/ConnectionAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function executeStatement($sql, array $params = [], array $types = []): i
8787

8888
public function lastInsertId(string $table): int {
8989
try {
90-
return (int)$this->inner->lastInsertId($table);
90+
return $this->inner->lastInsertId($table);
9191
} catch (Exception $e) {
9292
throw DbalException::wrap($e);
9393
}

lib/private/DB/MigrationService.php

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class MigrationService {
5858
/**
5959
* @throws \Exception
6060
*/
61-
public function __construct($appName, Connection $connection, ?IOutput $output = null, ?AppLocator $appLocator = null) {
61+
public function __construct(string $appName, Connection $connection, ?IOutput $output = null, ?AppLocator $appLocator = null) {
6262
$this->appName = $appName;
6363
$this->connection = $connection;
6464
if ($output === null) {
@@ -100,18 +100,15 @@ public function __construct($appName, Connection $connection, ?IOutput $output =
100100

101101
/**
102102
* Returns the name of the app for which this migration is executed
103-
*
104-
* @return string
105103
*/
106-
public function getApp() {
104+
public function getApp(): string {
107105
return $this->appName;
108106
}
109107

110108
/**
111-
* @return bool
112109
* @codeCoverageIgnore - this will implicitly tested on installation
113110
*/
114-
private function createMigrationTable() {
111+
private function createMigrationTable(): bool {
115112
if ($this->migrationTableCreated) {
116113
return false;
117114
}
@@ -176,7 +173,7 @@ private function createMigrationTable() {
176173
/**
177174
* Returns all versions which have already been applied
178175
*
179-
* @return string[]
176+
* @return list<string>
180177
* @codeCoverageIgnore - no need to test this
181178
*/
182179
public function getMigratedVersions() {
@@ -188,7 +185,7 @@ public function getMigratedVersions() {
188185
->where($qb->expr()->eq('app', $qb->createNamedParameter($this->getApp())))
189186
->orderBy('version');
190187

191-
$result = $qb->execute();
188+
$result = $qb->executeQuery();
192189
$rows = $result->fetchAll(\PDO::FETCH_COLUMN);
193190
$result->closeCursor();
194191

@@ -197,15 +194,17 @@ public function getMigratedVersions() {
197194

198195
/**
199196
* Returns all versions which are available in the migration folder
200-
*
201-
* @return array
197+
* @return list<string>
202198
*/
203-
public function getAvailableVersions() {
199+
public function getAvailableVersions(): array {
204200
$this->ensureMigrationsAreLoaded();
205201
return array_map('strval', array_keys($this->migrations));
206202
}
207203

208-
protected function findMigrations() {
204+
/**
205+
* @return array<string, string>
206+
*/
207+
protected function findMigrations(): array {
209208
$directory = realpath($this->migrationsPath);
210209
if ($directory === false || !file_exists($directory) || !is_dir($directory)) {
211210
return [];
@@ -322,10 +321,9 @@ public function getMigrationsDirectory() {
322321
/**
323322
* Return the explicit version for the aliases; current, next, prev, latest
324323
*
325-
* @param string $alias
326324
* @return mixed|null|string
327325
*/
328-
public function getMigration($alias) {
326+
public function getMigration(string $alias) {
329327
switch ($alias) {
330328
case 'current':
331329
return $this->getCurrentVersion();
@@ -342,29 +340,22 @@ public function getMigration($alias) {
342340
return '0';
343341
}
344342

345-
/**
346-
* @param string $version
347-
* @param int $delta
348-
* @return null|string
349-
*/
350-
private function getRelativeVersion($version, $delta) {
343+
private function getRelativeVersion(string $version, int $delta): ?string {
351344
$this->ensureMigrationsAreLoaded();
352345

353346
$versions = $this->getAvailableVersions();
354-
array_unshift($versions, 0);
347+
array_unshift($versions, '0');
348+
/** @var int $offset */
355349
$offset = array_search($version, $versions, true);
356350
if ($offset === false || !isset($versions[$offset + $delta])) {
357351
// Unknown version or delta out of bounds.
358352
return null;
359353
}
360354

361-
return (string) $versions[$offset + $delta];
355+
return (string)$versions[$offset + $delta];
362356
}
363357

364-
/**
365-
* @return string
366-
*/
367-
private function getCurrentVersion() {
358+
private function getCurrentVersion(): string {
368359
$m = $this->getMigratedVersions();
369360
if (count($m) === 0) {
370361
return '0';
@@ -374,11 +365,9 @@ private function getCurrentVersion() {
374365
}
375366

376367
/**
377-
* @param string $version
378-
* @return string
379368
* @throws \InvalidArgumentException
380369
*/
381-
private function getClass($version) {
370+
private function getClass(string $version): string {
382371
$this->ensureMigrationsAreLoaded();
383372

384373
if (isset($this->migrations[$version])) {
@@ -390,21 +379,16 @@ private function getClass($version) {
390379

391380
/**
392381
* Allows to set an IOutput implementation which is used for logging progress and messages
393-
*
394-
* @param IOutput $output
395382
*/
396-
public function setOutput(IOutput $output) {
383+
public function setOutput(IOutput $output): void {
397384
$this->output = $output;
398385
}
399386

400387
/**
401388
* Applies all not yet applied versions up to $to
402-
*
403-
* @param string $to
404-
* @param bool $schemaOnly
405389
* @throws \InvalidArgumentException
406390
*/
407-
public function migrate($to = 'latest', $schemaOnly = false) {
391+
public function migrate(string $to = 'latest', bool $schemaOnly = false): void {
408392
if ($schemaOnly) {
409393
$this->migrateSchemaOnly($to);
410394
return;
@@ -425,11 +409,9 @@ public function migrate($to = 'latest', $schemaOnly = false) {
425409

426410
/**
427411
* Applies all not yet applied versions up to $to
428-
*
429-
* @param string $to
430412
* @throws \InvalidArgumentException
431413
*/
432-
public function migrateSchemaOnly($to = 'latest') {
414+
public function migrateSchemaOnly(string $to = 'latest'): void {
433415
// read known migrations
434416
$toBeExecuted = $this->getMigrationsToExecute($to);
435417

lib/private/DB/OracleConnection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
class OracleConnection extends Connection {
3030
/**
3131
* Quote the keys of the array
32+
* @param array<string, string> $data
33+
* @return array<string, string>
3234
*/
3335
private function quoteKeys(array $data) {
3436
$return = [];

0 commit comments

Comments
 (0)