fixes with code inspection

This commit is contained in:
Robin Krahnen 2021-09-21 10:39:03 +02:00
parent 2b15d25ebe
commit 722111191f
4 changed files with 24 additions and 4 deletions

View file

@ -5,7 +5,10 @@ declare(strict_types=1);
namespace DigiComp\Sequence\Command; namespace DigiComp\Sequence\Command;
use DigiComp\Sequence\Domain\Model\Insert; use DigiComp\Sequence\Domain\Model\Insert;
use DigiComp\Sequence\Service\Exception as DigiCompSequenceServiceException;
use DigiComp\Sequence\Service\SequenceGenerator; use DigiComp\Sequence\Service\SequenceGenerator;
use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException;
use Doctrine\DBAL\Exception as DoctrineDBALException;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Neos\Flow\Annotations as Flow; use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController; use Neos\Flow\Cli\CommandController;
@ -34,6 +37,7 @@ class SequenceCommandController extends CommandController
* *
* @param int $to * @param int $to
* @param string $type * @param string $type
* @throws DigiCompSequenceServiceException
*/ */
public function advanceCommand(int $to, string $type): void public function advanceCommand(int $to, string $type): void
{ {
@ -42,6 +46,9 @@ class SequenceCommandController extends CommandController
/** /**
* @param string[] $typesToClean * @param string[] $typesToClean
* @throws DigiCompSequenceServiceException
* @throws DoctrineDBALDriverException
* @throws DoctrineDBALException
*/ */
public function cleanSequenceInsertsCommand(array $typesToClean = []) public function cleanSequenceInsertsCommand(array $typesToClean = [])
{ {

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace DigiComp\Sequence\Service; namespace DigiComp\Sequence\Service;
use DigiComp\Sequence\Domain\Model\Insert; use DigiComp\Sequence\Domain\Model\Insert;
use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException;
use Doctrine\DBAL\Exception as DoctrineDBALException; use Doctrine\DBAL\Exception as DoctrineDBALException;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Neos\Flow\Annotations as Flow; use Neos\Flow\Annotations as Flow;
@ -37,6 +38,7 @@ class SequenceGenerator
* @param string|object $type * @param string|object $type
* @return int * @return int
* @throws Exception * @throws Exception
* @throws DoctrineDBALDriverException
* @throws DoctrineDBALException * @throws DoctrineDBALException
*/ */
public function getNextNumberFor($type): int public function getNextNumberFor($type): int
@ -71,10 +73,10 @@ class SequenceGenerator
return false; return false;
} catch (DoctrineDBALException $e) { } catch (DoctrineDBALException $e) {
if (!$e->getPrevious() instanceof \PDOException) { if (!$e->getPrevious() instanceof \PDOException) {
$this->logger->critical('Exception occured: ' . $e->getMessage()); $this->logger->critical('Exception occurred: ' . $e->getMessage());
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->critical('Exception occured: ' . $e->getMessage()); $this->logger->critical('Exception occurred: ' . $e->getMessage());
} }
return false; return false;
@ -98,6 +100,7 @@ class SequenceGenerator
* @param string|object $type * @param string|object $type
* @return int * @return int
* @throws Exception * @throws Exception
* @throws DoctrineDBALDriverException
* @throws DoctrineDBALException * @throws DoctrineDBALException
*/ */
public function getLastNumberFor($type): int public function getLastNumberFor($type): int
@ -107,7 +110,7 @@ class SequenceGenerator
. $this->entityManager->getClassMetadata(Insert::class)->getTableName() . $this->entityManager->getClassMetadata(Insert::class)->getTableName()
. ' WHERE type = :type', . ' WHERE type = :type',
['type' => $this->inferTypeFromSource($type)] ['type' => $this->inferTypeFromSource($type)]
)->fetchAll(\PDO::FETCH_COLUMN)[0]; )->fetchOne();
} }
/** /**

View file

@ -2,18 +2,24 @@
namespace DigiComp\Sequence\Tests\Functional; namespace DigiComp\Sequence\Tests\Functional;
use DigiComp\Sequence\Service\Exception as DigiCompSequenceServiceException;
use DigiComp\Sequence\Service\SequenceGenerator; use DigiComp\Sequence\Service\SequenceGenerator;
use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException;
use Doctrine\DBAL\Exception as DoctrineDBALException;
use Neos\Flow\Tests\FunctionalTestCase; use Neos\Flow\Tests\FunctionalTestCase;
class SequenceTest extends FunctionalTestCase class SequenceTest extends FunctionalTestCase
{ {
/** /**
* @var bool * @inheritDoc
*/ */
protected static $testablePersistenceEnabled = true; protected static $testablePersistenceEnabled = true;
/** /**
* @test * @test
* @throws DigiCompSequenceServiceException
* @throws DoctrineDBALDriverException
* @throws DoctrineDBALException
*/ */
public function sequenceTest() public function sequenceTest()
{ {
@ -47,6 +53,9 @@ class SequenceTest extends FunctionalTestCase
/** /**
* @test * @test
* @throws DigiCompSequenceServiceException
* @throws DoctrineDBALDriverException
* @throws DoctrineDBALException
*/ */
public function advanceTest() public function advanceTest()
{ {

View file

@ -3,6 +3,7 @@
"description": "Sequence is a very simple database agnostic but database based sequence generator", "description": "Sequence is a very simple database agnostic but database based sequence generator",
"type": "neos-package", "type": "neos-package",
"require": { "require": {
"ext-pdo": "*",
"neos/flow": "^5.3.0 || ^6.3.5", "neos/flow": "^5.3.0 || ^6.3.5",
"php": "~7.4.0" "php": "~7.4.0"
}, },