Skip to content

Commit

Permalink
Cleanup plsam issues in DB/ContactsManager and Console
Browse files Browse the repository at this point in the history
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
  • Loading branch information
CarlSchwan committed Dec 1, 2022
1 parent 5f3585d commit 3afb0e5
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 143 deletions.
59 changes: 0 additions & 59 deletions build/psalm-baseline.xml
Expand Up @@ -2164,41 +2164,6 @@
<TooManyArguments occurrences="1">
<code>dispatch</code>
</TooManyArguments>
<UndefinedThisPropertyAssignment occurrences="1">
<code>$this-&gt;application</code>
</UndefinedThisPropertyAssignment>
<UndefinedThisPropertyFetch occurrences="4">
<code>$this-&gt;application</code>
<code>$this-&gt;application</code>
<code>$this-&gt;application</code>
<code>$this-&gt;application</code>
</UndefinedThisPropertyFetch>
</file>
<file src="lib/private/ContactsManager.php">
<InvalidNullableReturnType occurrences="3">
<code>IAddressBook</code>
<code>array</code>
<code>bool</code>
</InvalidNullableReturnType>
<NullableReturnStatement occurrences="5">
<code>null</code>
<code>null</code>
<code>null</code>
<code>null</code>
<code>null</code>
</NullableReturnStatement>
<ParamNameMismatch occurrences="2">
<code>$addressBook</code>
<code>$addressBook</code>
</ParamNameMismatch>
</file>
<file src="lib/private/DB/Adapter.php">
<InvalidReturnStatement occurrences="1">
<code>$builder-&gt;execute()</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="1">
<code>int</code>
</InvalidReturnType>
</file>
<file src="lib/private/DB/AdapterMySQL.php">
<InternalMethod occurrences="1">
Expand All @@ -2209,30 +2174,6 @@
<InternalMethod occurrences="1">
<code>getParams</code>
</InternalMethod>
<InvalidReturnStatement occurrences="1">
<code>$this-&gt;adapter-&gt;lastInsertId($seqName)</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="1">
<code>string</code>
</InvalidReturnType>
<InvalidScalarArgument occurrences="1">
<code>$e-&gt;getCode()</code>
</InvalidScalarArgument>
<ParamNameMismatch occurrences="2">
<code>$seqName</code>
<code>$statement</code>
</ParamNameMismatch>
</file>
<file src="lib/private/DB/MigrationService.php">
<InvalidOperand occurrences="2">
<code>$offset</code>
<code>$offset</code>
</InvalidOperand>
</file>
<file src="lib/private/DB/OracleConnection.php">
<InvalidArrayAccess occurrences="1">
<code>$key[0]</code>
</InvalidArrayAccess>
</file>
<file src="lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php">
<ImplicitToStringCast occurrences="1">
Expand Down
18 changes: 6 additions & 12 deletions lib/private/Console/Application.php
Expand Up @@ -47,16 +47,12 @@
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class Application {
/** @var IConfig */
private $config;
/** @var EventDispatcherInterface */
private $dispatcher;
/** @var IRequest */
private $request;
/** @var LoggerInterface */
private $logger;
/** @var MemoryInfo */
private $memoryInfo;
private IConfig $config;
private EventDispatcherInterface $dispatcher;
private IRequest $request;
private LoggerInterface $logger;
private MemoryInfo $memoryInfo;
private SymfonyApplication $application;

public function __construct(IConfig $config,
EventDispatcherInterface $dispatcher,
Expand All @@ -73,8 +69,6 @@ public function __construct(IConfig $config,
}

/**
* @param InputInterface $input
* @param ConsoleOutputInterface $output
* @throws \Exception
*/
public function loadCommands(
Expand Down
25 changes: 11 additions & 14 deletions lib/private/ContactsManager.php
Expand Up @@ -87,32 +87,32 @@ public function search($pattern, $searchProperties = [], $options = []) {
* This function can be used to delete the contact identified by the given id
*
* @param int $id the unique identifier to a contact
* @param string $address_book_key identifier of the address book in which the contact shall be deleted
* @param string $addressBookKey identifier of the address book in which the contact shall be deleted
* @return bool successful or not
*/
public function delete($id, $address_book_key) {
$addressBook = $this->getAddressBook($address_book_key);
public function delete($id, $addressBookKey) {
$addressBook = $this->getAddressBook($addressBookKey);
if (!$addressBook) {
return null;
return false;
}

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

return null;
return false;
}

/**
* This function is used to create a new contact if 'id' is not given or not present.
* Otherwise the contact will be updated by replacing the entire data set.
*
* @param array $properties this array if key-value-pairs defines a contact
* @param string $address_book_key identifier of the address book in which the contact shall be created or updated
* @return array representing the contact just created or updated
* @param string $addressBookKey identifier of the address book in which the contact shall be created or updated
* @return ?array representing the contact just created or updated
*/
public function createOrUpdate($properties, $address_book_key) {
$addressBook = $this->getAddressBook($address_book_key);
public function createOrUpdate($properties, $addressBookKey) {
$addressBook = $this->getAddressBook($addressBookKey);
if (!$addressBook) {
return null;
}
Expand All @@ -129,7 +129,7 @@ public function createOrUpdate($properties, $address_book_key) {
*
* @return bool true if enabled, false if not
*/
public function isEnabled() {
public function isEnabled(): bool {
return !empty($this->addressBooks) || !empty($this->addressBookLoaders);
}

Expand Down Expand Up @@ -188,11 +188,8 @@ public function register(\Closure $callable) {

/**
* Get (and load when needed) the address book for $key
*
* @param string $addressBookKey
* @return IAddressBook
*/
protected function getAddressBook($addressBookKey) {
protected function getAddressBook(string $addressBookKey): ?IAddressBook {
$this->loadAddressBooks();
if (!array_key_exists($addressBookKey, $this->addressBooks)) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion lib/private/DB/Adapter.php
Expand Up @@ -143,7 +143,7 @@ public function insertIgnoreConflict(string $table, array $values) : int {
foreach ($values as $key => $value) {
$builder->setValue($key, $builder->createNamedParameter($value));
}
return $builder->execute();
return $builder->executeStatement();
} catch (UniqueConstraintViolationException $e) {
return 0;
}
Expand Down
16 changes: 8 additions & 8 deletions lib/private/DB/Connection.php
Expand Up @@ -139,7 +139,7 @@ public function connect() {
return $status;
} catch (Exception $e) {
// throw a new exception to prevent leaking info from the stacktrace
throw new Exception('Failed to connect to the database: ' . $e->getMessage(), $e->getCode());
throw new Exception('Failed to connect to the database: ' . $e->getMessage(), (int)$e->getCode());
}
}

Expand Down Expand Up @@ -222,7 +222,7 @@ public function getPrefix() {
* @return Statement The prepared statement.
* @throws Exception
*/
public function prepare($statement, $limit = null, $offset = null): Statement {
public function prepare($sql, $limit = null, $offset = null): Statement {
if ($limit === -1 || $limit === null) {
$limit = null;
} else {
Expand All @@ -233,7 +233,7 @@ public function prepare($statement, $limit = null, $offset = null): Statement {
}
if (!is_null($limit)) {
$platform = $this->getDatabasePlatform();
$statement = $platform->modifyLimitQuery($statement, $limit, $offset);
$statement = $platform->modifyLimitQuery($sql, $limit, $offset);
}
$statement = $this->replaceTablePrefix($statement);
$statement = $this->adapter->fixupStatement($statement);
Expand Down Expand Up @@ -323,14 +323,14 @@ protected function logQueryToFile(string $sql): void {
*
* @param string $seqName Name of the sequence object from which the ID should be returned.
*
* @return string the last inserted ID.
* @return int the last inserted ID.
* @throws Exception
*/
public function lastInsertId($seqName = null) {
if ($seqName) {
$seqName = $this->replaceTablePrefix($seqName);
public function lastInsertId($name = null): int {
if ($name) {
$name = $this->replaceTablePrefix($name);
}
return $this->adapter->lastInsertId($seqName);
return $this->adapter->lastInsertId($name);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/private/DB/ConnectionAdapter.php
Expand Up @@ -88,7 +88,7 @@ public function executeStatement($sql, array $params = [], array $types = []): i

public function lastInsertId(string $table): int {
try {
return (int)$this->inner->lastInsertId($table);
return $this->inner->lastInsertId($table);
} catch (Exception $e) {
throw DbalException::wrap($e);
}
Expand Down

0 comments on commit 3afb0e5

Please sign in to comment.