Skip to content

Commit

Permalink
[TASK] Clean up code with CS fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
fsuter committed Dec 6, 2024
1 parent 26b1905 commit 23e3c1e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 40 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-12-06 Francois Suter (Idéative) <[email protected]>

* Automate documentation and code linting

2024-12-02 Francois Suter (Idéative) <[email protected]>

* Clean up and improve documentation
Expand Down
47 changes: 22 additions & 25 deletions Classes/Database/DoctrineDbalConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ class DoctrineDbalConnection
*
* @param array $parameters Parameters needed to connect to the database
* @throws DatabaseConnectionException
* @return void
* @throws QueryErrorException
*/
public function connect(array $parameters = []): void
{
$configuration = new Configuration();
if (array_key_exists('uri', $parameters)) {
$connectionParameters = [
'url' => $parameters['uri']
'url' => $parameters['uri'],
];
} else {
$connectionParameters = [
Expand All @@ -52,37 +51,36 @@ public function connect(array $parameters = []): void
'password' => $parameters['password'],
'host' => $parameters['server'],
'driver' => $parameters['driver'] ?? null,
'driverClass' => $parameters['driverClass'] ?? null
'driverClass' => $parameters['driverClass'] ?? null,
];
}
try {
$this->connection = DriverManager::getConnection(
$connectionParameters,
$configuration
$connectionParameters,
$configuration
);
} catch (\Exception $e) {
// Throw unified exception
throw new DatabaseConnectionException(
sprintf(
'Database connection failed (%s)',
$e->getMessage()
),
1491062456
sprintf(
'Database connection failed (%s)',
$e->getMessage()
),
1491062456
);
}

// Execute connection initialization if defined
if (!empty($parameters['init'])) {
try {
$this->connection->executeQuery($parameters['init']);
}
catch (\Throwable $e) {
} catch (\Throwable $e) {
throw new QueryErrorException(
sprintf(
'Failled executing "init" statement (%s)',
$e->getMessage()
),
1491379532
sprintf(
'Failled executing "init" statement (%s)',
$e->getMessage()
),
1491379532
);
}
}
Expand All @@ -101,14 +99,13 @@ public function query(string $sql, int $fetchMode = \PDO::FETCH_ASSOC): array
{
try {
$result = $this->connection->executeQuery($sql);
}
catch (\Exception $e) {
} catch (\Exception $e) {
throw new QueryErrorException(
sprintf(
'Failled executing query (%s)',
$e->getMessage()
),
1491379701
sprintf(
'Failled executing query (%s)',
$e->getMessage()
),
1491379701
);
}

Expand All @@ -118,4 +115,4 @@ public function query(string $sql, int $fetchMode = \PDO::FETCH_ASSOC): array
default => $result->fetchAllAssociative(),
};
}
}
}
8 changes: 2 additions & 6 deletions Classes/Exception/DatabaseConnectionException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Cobweb\SvconnectorSql\Exception;

/*
Expand All @@ -18,10 +19,5 @@

/**
* Exception to be thrown when failing to connect to a DBMS.
*
* @package Cobweb\SvconnectorSql\Exception
*/
class DatabaseConnectionException extends SourceErrorException
{

}
class DatabaseConnectionException extends SourceErrorException {}
8 changes: 2 additions & 6 deletions Classes/Exception/QueryErrorException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Cobweb\SvconnectorSql\Exception;

/*
Expand All @@ -18,10 +19,5 @@

/**
* Exception to be thrown when a SQL query fails.
*
* @package Cobweb\SvconnectorSql\Exception
*/
class QueryErrorException extends SourceErrorException
{

}
class QueryErrorException extends SourceErrorException {}
6 changes: 3 additions & 3 deletions Classes/Service/ConnectorSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
use Cobweb\Svconnector\Event\ProcessRawDataEvent;
use Cobweb\Svconnector\Event\ProcessResponseEvent;
use Cobweb\Svconnector\Event\ProcessXmlDataEvent;
use Cobweb\SvconnectorSql\Exception\DatabaseConnectionException;
use Cobweb\SvconnectorSql\Exception\QueryErrorException;
use Cobweb\Svconnector\Service\ConnectorBase;
use Cobweb\SvconnectorSql\Database\DoctrineDbalConnection;
use Cobweb\SvconnectorSql\Exception\DatabaseConnectionException;
use Cobweb\SvconnectorSql\Exception\QueryErrorException;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand All @@ -39,7 +39,7 @@ class ConnectorSql extends ConnectorBase
/**
* Verifies that the connection is functional
* In this case it always is, as the connection can really be tested only for specific configurations
* @return boolean TRUE if the service is available
* @return bool TRUE if the service is available
*/
public function isAvailable(): bool
{
Expand Down

0 comments on commit 23e3c1e

Please sign in to comment.