Skip to content

Commit

Permalink
Merge pull request #10 from irontec/fix-static-analysis-issues
Browse files Browse the repository at this point in the history
Enhanced hints
  • Loading branch information
mmadariaga authored Jan 10, 2023
2 parents 0fdf603 + 5b11c7b commit b5c6716
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 20 deletions.
12 changes: 3 additions & 9 deletions Application/Service/DataGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Ivoz\Core\Application\Service;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Ivoz\Core\Application\DataTransferObjectInterface;
use Ivoz\Core\Application\Event\CommandWasExecuted;
use Ivoz\Core\Application\RequestId;
Expand All @@ -18,7 +18,7 @@
class DataGateway
{
/**
* @var EntityManager
* @var EntityManagerInterface
*/
private $em;

Expand Down Expand Up @@ -54,15 +54,9 @@ class DataGateway

/**
* DataGateway constructor.
* @param EntityManager $entityManager
* @param QueryBuilderFactory $queryBuilderFactory
* @param DoctrineEntityPersister $entityPersister
* @param DtoAssembler $dtoAssembler
* @param DomainEventPublisher $eventPublisher
* @param RequestId $requestId
*/
public function __construct(
EntityManager $entityManager,
EntityManagerInterface $entityManager,
QueryBuilderFactory $queryBuilderFactory,
DoctrineEntityPersister $entityPersister,
DtoAssembler $dtoAssembler,
Expand Down
4 changes: 2 additions & 2 deletions Application/Service/EntityTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Ivoz\Core\Application\Service;

use Doctrine\DBAL\LockMode;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\PessimisticLockException;
use Ivoz\Core\Application\DataTransferObjectInterface;
Expand All @@ -25,7 +25,7 @@ class EntityTools
private $entityUpdater;

public function __construct(
EntityManager $entityManager,
EntityManagerInterface $entityManager,
EntityPersisterInterface $entityPersister,
DtoAssembler $dtoAssembler,
CreateEntityFromDto $createEntityFromDto,
Expand Down
6 changes: 3 additions & 3 deletions Application/Service/QueryBuilderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace Ivoz\Core\Application\Service;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;

class QueryBuilderFactory
{
/**
* @var EntityManager
* @var EntityManagerInterface
*/
private $em;

public function __construct(EntityManager $entityManager)
public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}
Expand Down
2 changes: 2 additions & 0 deletions Domain/Model/EntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function hasBeenDeleted(): bool;

public function __toString(): string;

public function isInitialized(): bool;

public function initChangelog(): void;

/**
Expand Down
6 changes: 3 additions & 3 deletions Infrastructure/Application/DoctrineForeignKeyTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Ivoz\Core\Infrastructure\Application;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Ivoz\Core\Application\DataTransferObjectInterface;
use Ivoz\Core\Application\ForeignKeyTransformerInterface;
use Ivoz\Core\Application\Helper\EntityClassHelper;
Expand All @@ -12,11 +12,11 @@
class DoctrineForeignKeyTransformer implements ForeignKeyTransformerInterface
{
/**
* @var EntityManager
* @var EntityManagerInterface
*/
private $em;

public function __construct(EntityManager $em)
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
Expand Down
67 changes: 65 additions & 2 deletions Infrastructure/Persistence/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\Decorator\EntityManagerDecorator;
use Doctrine\ORM\EntityManager as DoctrineEntityManager;
use Doctrine\ORM\NativeQuery;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Query as DqlQuery;
use Ivoz\Core\Infrastructure\Persistence\Doctrine\Hydration\ObjectHydrator;
use Ivoz\Core\Infrastructure\Persistence\Doctrine\Hydration\SimpleObjectHydrator;
use Ivoz\Core\Infrastructure\Persistence\Doctrine\Hydration\DtoHydrator;

class EntityManager extends DoctrineEntityManager implements ToggleableBufferedQueryInterface
class EntityManager extends EntityManagerDecorator implements ToggleableBufferedQueryInterface
{
public function enableBufferedQuery()
{
Expand Down Expand Up @@ -67,7 +72,30 @@ public static function create($conn, Configuration $config, EventManager $eventM
throw new \InvalidArgumentException("Invalid argument: " . $conn);
}

return new self($conn, $config, $conn->getEventManager());
$emRef = new \ReflectionClass(
DoctrineEntityManager::class
);
/** @var DoctrineEntityManager $em */
$em = $emRef->newInstanceWithoutConstructor();
$eventManager = $conn->getEventManager();
(function () use ($conn, $config, $eventManager) {
$this->__construct($conn, $config, $eventManager);
})->call($em);

$instance = new self($em);
(function () use ($instance) {
$this->em = $instance;
})->call($instance->getUnitOfWork());

return $instance;
}

/**
* {@inheritDoc}
*/
public function getHydrator($hydrationMode)
{
return $this->newHydrator($hydrationMode);
}

/**
Expand All @@ -89,4 +117,39 @@ public function newHydrator($hydrationMode)
return parent::newHydrator(...func_get_args());
}
}

/**
* {@inheritDoc}
*/
public function createQuery($dql = '')
{
$query = new DqlQuery($this);

if (! empty($dql)) {
$query->setDQL($dql);
}

return $query;
}

/**
* {@inheritDoc}
*/
public function createNativeQuery($sql, ResultSetMapping $rsm)
{
$query = new NativeQuery($this);

$query->setSQL($sql);
$query->setResultSetMapping($rsm);

return $query;
}

/**
* {@inheritDoc}
*/
public function createQueryBuilder()
{
return new QueryBuilder($this);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"symfony/finder": "^5.1",
"symfony/http-foundation": "^5.1",
"symfony/serializer": "^5.1",
"symfony/mailer": "^5.4"
"symfony/mailer": "^5.4",
"symfony/mime": "^5.4"
},
"require-dev": {
"phpstan/phpstan": "^1.0"
Expand Down

0 comments on commit b5c6716

Please sign in to comment.