From bdd976c7e8ca4065981404f912e3a39d960fca0c Mon Sep 17 00:00:00 2001 From: Mikel Madariaga Date: Wed, 8 Feb 2023 16:01:07 +0100 Subject: [PATCH] move application services to domain --- Application/Service/DataGateway.php | 12 +++++------- .../DataTransferObjectInterface.php | 2 +- .../Event/CommandEventInterface.php | 2 +- .../Event/CommandWasExecuted.php | 2 +- .../ForeignKeyTransformerInterface.php | 2 +- .../Helper/ArrayObjectHelper.php | 2 +- .../Helper/EntityClassHelper.php | 4 ++-- .../Helper/LifecycleServiceHelper.php | 2 +- Domain/Model/Changelog/ChangelogAbstract.php | 4 ++-- Domain/Model/Changelog/ChangelogDtoAbstract.php | 4 ++-- Domain/Model/Changelog/ChangelogInterface.php | 4 ++-- Domain/Model/Changelog/ChangelogTrait.php | 4 ++-- Domain/Model/ChangelogTrait.php | 2 +- Domain/Model/Commandlog/Commandlog.php | 4 ++-- Domain/Model/Commandlog/CommandlogAbstract.php | 4 ++-- .../Model/Commandlog/CommandlogDtoAbstract.php | 4 ++-- Domain/Model/Commandlog/CommandlogInterface.php | 8 ++++---- Domain/Model/Commandlog/CommandlogTrait.php | 4 ++-- {Application => Domain}/Model/DtoNormalizer.php | 2 +- Domain/Model/EntityInterface.php | 4 ++-- {Application => Domain}/MutexInterface.php | 2 +- .../RegisterCommandTrait.php | 4 ++-- {Application => Domain}/RequestId.php | 2 +- .../Assembler/CustomDtoAssemblerInterface.php | 4 ++-- .../CustomEntityAssemblerInterface.php | 6 +++--- .../Service/Assembler/DtoAssembler.php | 4 ++-- .../Service/Assembler/EntityAssembler.php | 10 +++++----- .../Service/CommandEventSubscriber.php | 4 ++-- .../Service/CommonStoragePathResolver.php | 2 +- .../Service/CreateEntityFromDto.php | 6 +++--- Domain/Service/EntityPersisterInterface.php | 2 +- {Application => Domain}/Service/EntityTools.php | 7 ++++--- .../Service/QueryBuilderFactory.php | 2 +- .../Service/StoragePathResolverCollection.php | 2 +- .../Service/StoragePathResolverInterface.php | 2 +- Domain/Service/TempFile.php | 2 +- .../FileContainerEntityAssemblerTrait.php | 12 ++++++------ .../Service/UpdateEntityFromDto.php | 6 +++--- .../DoctrineForeignKeyTransformer.php | 17 ++++++----------- .../Domain/Service/Cgrates/FakeCgrRpcClient.php | 5 ++--- .../Domain/Service/DoctrineEntityPersister.php | 8 ++++---- .../Service/Lifecycle/CommandPersister.php | 4 ++-- .../Lifecycle/DoctrineEventSubscriber.php | 2 +- .../Doctrine/Hydration/DtoHydrator.php | 15 +++++++++++++-- .../Persistence/Doctrine/LoggableMigration.php | 2 +- .../Model/DBAL/Types/UtcDateTimeType.php | 7 +++++-- .../Persistence/Doctrine/ORM/EntityManager.php | 2 +- .../Filesystem/ScheduleForRemove.php | 2 +- Infrastructure/Persistence/Redis/Lock.php | 2 +- .../Compiler/DomainServiceCompiler.php | 2 +- phpstan.neon | 3 +-- 51 files changed, 116 insertions(+), 110 deletions(-) mode change 100755 => 100644 Application/Service/DataGateway.php rename {Application => Domain}/DataTransferObjectInterface.php (97%) rename {Application => Domain}/Event/CommandEventInterface.php (94%) mode change 100644 => 100755 rename {Application => Domain}/Event/CommandWasExecuted.php (98%) mode change 100644 => 100755 rename {Application => Domain}/ForeignKeyTransformerInterface.php (93%) rename {Application => Domain}/Helper/ArrayObjectHelper.php (94%) mode change 100644 => 100755 rename {Application => Domain}/Helper/EntityClassHelper.php (89%) rename {Application => Domain}/Helper/LifecycleServiceHelper.php (99%) rename {Application => Domain}/Model/DtoNormalizer.php (99%) mode change 100644 => 100755 rename {Application => Domain}/MutexInterface.php (87%) rename {Application => Domain}/RegisterCommandTrait.php (87%) mode change 100644 => 100755 rename {Application => Domain}/RequestId.php (90%) mode change 100644 => 100755 rename {Application => Domain}/Service/Assembler/CustomDtoAssemblerInterface.php (67%) mode change 100644 => 100755 rename {Application => Domain}/Service/Assembler/CustomEntityAssemblerInterface.php (61%) mode change 100644 => 100755 rename {Application => Domain}/Service/Assembler/DtoAssembler.php (95%) mode change 100644 => 100755 rename {Application => Domain}/Service/Assembler/EntityAssembler.php (91%) mode change 100644 => 100755 rename {Application => Domain}/Service/CommandEventSubscriber.php (94%) mode change 100644 => 100755 rename {Application => Domain}/Service/CommonStoragePathResolver.php (98%) mode change 100644 => 100755 rename {Application => Domain}/Service/CreateEntityFromDto.php (84%) mode change 100644 => 100755 rename {Application => Domain}/Service/EntityTools.php (97%) mode change 100644 => 100755 rename {Application => Domain}/Service/QueryBuilderFactory.php (97%) mode change 100644 => 100755 rename {Application => Domain}/Service/StoragePathResolverCollection.php (95%) mode change 100644 => 100755 rename {Application => Domain}/Service/StoragePathResolverInterface.php (93%) mode change 100644 => 100755 rename {Application => Domain}/Service/Traits/FileContainerEntityAssemblerTrait.php (93%) mode change 100644 => 100755 rename {Application => Domain}/Service/UpdateEntityFromDto.php (80%) mode change 100644 => 100755 diff --git a/Application/Service/DataGateway.php b/Application/Service/DataGateway.php old mode 100755 new mode 100644 index 07b585e..3212ecb --- a/Application/Service/DataGateway.php +++ b/Application/Service/DataGateway.php @@ -3,11 +3,12 @@ namespace Ivoz\Core\Application\Service; use Doctrine\ORM\EntityManagerInterface; -use Ivoz\Core\Application\DataTransferObjectInterface; -use Ivoz\Core\Application\Event\CommandWasExecuted; -use Ivoz\Core\Application\RequestId; -use Ivoz\Core\Application\Service\Assembler\DtoAssembler; +use Ivoz\Core\Domain\DataTransferObjectInterface; +use Ivoz\Core\Domain\Event\CommandWasExecuted; +use Ivoz\Core\Domain\RequestId; +use Ivoz\Core\Domain\Service\Assembler\DtoAssembler; use Ivoz\Core\Domain\Service\DomainEventPublisher; +use Ivoz\Core\Domain\Service\QueryBuilderFactory; use Ivoz\Core\Infrastructure\Domain\Service\DoctrineEntityPersister; /** @@ -52,9 +53,6 @@ class DataGateway */ public static $user = ''; - /** - * DataGateway constructor. - */ public function __construct( EntityManagerInterface $entityManager, QueryBuilderFactory $queryBuilderFactory, diff --git a/Application/DataTransferObjectInterface.php b/Domain/DataTransferObjectInterface.php similarity index 97% rename from Application/DataTransferObjectInterface.php rename to Domain/DataTransferObjectInterface.php index 33c19e1..1d34983 100755 --- a/Application/DataTransferObjectInterface.php +++ b/Domain/DataTransferObjectInterface.php @@ -1,6 +1,6 @@ em = $em; + public function __construct( + private EntityManagerInterface $em + ) { } /** diff --git a/Infrastructure/Domain/Service/Cgrates/FakeCgrRpcClient.php b/Infrastructure/Domain/Service/Cgrates/FakeCgrRpcClient.php index 284e24e..cb579e4 100644 --- a/Infrastructure/Domain/Service/Cgrates/FakeCgrRpcClient.php +++ b/Infrastructure/Domain/Service/Cgrates/FakeCgrRpcClient.php @@ -10,7 +10,6 @@ class FakeCgrRpcClient implements ClientInterface { - private $fixedResponse = '{"error": null}'; public function __construct( @@ -30,7 +29,7 @@ public function request($id, $method, array $params = null) 'POST', '/uri', [], - '[]' + $this->fixedResponse ); } @@ -39,7 +38,7 @@ public function send(RequestInterface $request) return new Response( 200, [], - $this->fixedResponse + '{"error": null}' ); } diff --git a/Infrastructure/Domain/Service/DoctrineEntityPersister.php b/Infrastructure/Domain/Service/DoctrineEntityPersister.php index 4d8d8f7..8e79541 100755 --- a/Infrastructure/Domain/Service/DoctrineEntityPersister.php +++ b/Infrastructure/Domain/Service/DoctrineEntityPersister.php @@ -5,10 +5,10 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\UnitOfWork; -use Ivoz\Core\Application\DataTransferObjectInterface; -use Ivoz\Core\Application\Helper\EntityClassHelper; -use Ivoz\Core\Application\Service\CreateEntityFromDto; -use Ivoz\Core\Application\Service\UpdateEntityFromDto; +use Ivoz\Core\Domain\DataTransferObjectInterface; +use Ivoz\Core\Domain\Helper\EntityClassHelper; +use Ivoz\Core\Domain\Service\CreateEntityFromDto; +use Ivoz\Core\Domain\Service\UpdateEntityFromDto; use Ivoz\Core\Domain\Model\EntityInterface; use Ivoz\Core\Domain\Service\EntityPersisterInterface; use Ivoz\Core\Infrastructure\Persistence\Doctrine\Events as CustomEvents; diff --git a/Infrastructure/Domain/Service/Lifecycle/CommandPersister.php b/Infrastructure/Domain/Service/Lifecycle/CommandPersister.php index e545c5a..f0e0d1a 100755 --- a/Infrastructure/Domain/Service/Lifecycle/CommandPersister.php +++ b/Infrastructure/Domain/Service/Lifecycle/CommandPersister.php @@ -2,8 +2,8 @@ namespace Ivoz\Core\Infrastructure\Domain\Service\Lifecycle; -use Ivoz\Core\Application\Event\CommandWasExecuted; -use Ivoz\Core\Application\Service\CommandEventSubscriber; +use Ivoz\Core\Domain\Event\CommandWasExecuted; +use Ivoz\Core\Domain\Service\CommandEventSubscriber; use Ivoz\Core\Domain\Event\EntityEventInterface; use Ivoz\Core\Domain\Service\EntityEventSubscriber; use Ivoz\Core\Domain\Service\EntityPersisterInterface; diff --git a/Infrastructure/Domain/Service/Lifecycle/DoctrineEventSubscriber.php b/Infrastructure/Domain/Service/Lifecycle/DoctrineEventSubscriber.php index 4771d33..f9a17e9 100755 --- a/Infrastructure/Domain/Service/Lifecycle/DoctrineEventSubscriber.php +++ b/Infrastructure/Domain/Service/Lifecycle/DoctrineEventSubscriber.php @@ -12,7 +12,7 @@ use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs; use Doctrine\ORM\Tools\ToolEvents; use Doctrine\Persistence\Event\LifecycleEventArgs; -use Ivoz\Core\Application\Helper\{EntityClassHelper, LifecycleServiceHelper,}; +use Ivoz\Core\Domain\Helper\{EntityClassHelper, LifecycleServiceHelper,}; use Ivoz\Core\Domain\Event\{EntityWasCreated, EntityWasDeleted, EntityWasUpdated,}; use Ivoz\Core\Domain\Model\{EntityInterface, LoggableEntityInterface, LoggerEntityInterface,}; use Ivoz\Core\Domain\Service\{CommonLifecycleServiceCollection, DomainEventPublisher,}; diff --git a/Infrastructure/Persistence/Doctrine/Hydration/DtoHydrator.php b/Infrastructure/Persistence/Doctrine/Hydration/DtoHydrator.php index 13a65a8..7979b74 100644 --- a/Infrastructure/Persistence/Doctrine/Hydration/DtoHydrator.php +++ b/Infrastructure/Persistence/Doctrine/Hydration/DtoHydrator.php @@ -2,7 +2,10 @@ namespace Ivoz\Core\Infrastructure\Persistence\Doctrine\Hydration; +use Doctrine\DBAL\Result; use Doctrine\ORM\Internal\Hydration\ArrayHydrator; +use Doctrine\ORM\Internal\Hydration\IterableResult; +use Doctrine\ORM\Query\ResultSetMapping; use Ivoz\Core\Domain\Model\EntityInterface; class DtoHydrator extends ArrayHydrator @@ -10,7 +13,15 @@ class DtoHydrator extends ArrayHydrator protected $loadedEntities = []; /** - * {@inheritdoc} + * Initiates a row-by-row hydration. + * + * @deprecated + * + * @param Result $stmt + * @param ResultSetMapping $resultSetMapping + * @psalm-param array $hints + * + * @return IterableResult|array */ public function hydrateAll($stmt, $resultSetMapping, array $hints = array()) { @@ -36,7 +47,7 @@ public function hydrateRow() ); } - private function mapToDto(array $rows) + private function mapToDto(array $rows): array { $aliasMap = $this->_rsm->getAliasMap(); diff --git a/Infrastructure/Persistence/Doctrine/LoggableMigration.php b/Infrastructure/Persistence/Doctrine/LoggableMigration.php index ed7c551..4907ef8 100644 --- a/Infrastructure/Persistence/Doctrine/LoggableMigration.php +++ b/Infrastructure/Persistence/Doctrine/LoggableMigration.php @@ -4,7 +4,7 @@ use Doctrine\Migrations\AbstractMigration;; use Doctrine\DBAL\Schema\Schema; -use Ivoz\Core\Application\Event\CommandWasExecuted; +use Ivoz\Core\Domain\Event\CommandWasExecuted; use Ivoz\Core\Domain\Event\EntityWasUpdated; use Ivoz\Core\Domain\Model\Changelog\Changelog; use Ivoz\Core\Domain\Model\Commandlog\Commandlog; diff --git a/Infrastructure/Persistence/Doctrine/Model/DBAL/Types/UtcDateTimeType.php b/Infrastructure/Persistence/Doctrine/Model/DBAL/Types/UtcDateTimeType.php index a41ea96..539276e 100755 --- a/Infrastructure/Persistence/Doctrine/Model/DBAL/Types/UtcDateTimeType.php +++ b/Infrastructure/Persistence/Doctrine/Model/DBAL/Types/UtcDateTimeType.php @@ -10,7 +10,10 @@ class UtcDateTimeType extends DateTimeType { static private $utc; - public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) { if (is_string($value)) { return $value; @@ -50,4 +53,4 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return $converted; } -} +} \ No newline at end of file diff --git a/Infrastructure/Persistence/Doctrine/ORM/EntityManager.php b/Infrastructure/Persistence/Doctrine/ORM/EntityManager.php index 1749c0a..17b65a6 100755 --- a/Infrastructure/Persistence/Doctrine/ORM/EntityManager.php +++ b/Infrastructure/Persistence/Doctrine/ORM/EntityManager.php @@ -152,4 +152,4 @@ public function createQueryBuilder() { return new QueryBuilder($this); } -} +} \ No newline at end of file diff --git a/Infrastructure/Persistence/Filesystem/ScheduleForRemove.php b/Infrastructure/Persistence/Filesystem/ScheduleForRemove.php index bc93a36..a74fe7d 100644 --- a/Infrastructure/Persistence/Filesystem/ScheduleForRemove.php +++ b/Infrastructure/Persistence/Filesystem/ScheduleForRemove.php @@ -2,7 +2,7 @@ namespace Ivoz\Core\Infrastructure\Persistence\Filesystem; -use Ivoz\Core\Application\Service\StoragePathResolverCollection; +use Ivoz\Core\Domain\Service\StoragePathResolverCollection; use Ivoz\Core\Domain\Model\EntityInterface; use Ivoz\Core\Domain\Service\CommonLifecycleEventHandlerInterface; use Ivoz\Core\Domain\Service\FileContainerInterface; diff --git a/Infrastructure/Persistence/Redis/Lock.php b/Infrastructure/Persistence/Redis/Lock.php index 1362360..fa536b0 100644 --- a/Infrastructure/Persistence/Redis/Lock.php +++ b/Infrastructure/Persistence/Redis/Lock.php @@ -2,7 +2,7 @@ namespace Ivoz\Core\Infrastructure\Persistence\Redis; -use Ivoz\Core\Application\MutexInterface; +use Ivoz\Core\Domain\MutexInterface; use Psr\Log\LoggerInterface; class Lock implements MutexInterface diff --git a/Infrastructure/Symfony/DependencyInjection/Compiler/DomainServiceCompiler.php b/Infrastructure/Symfony/DependencyInjection/Compiler/DomainServiceCompiler.php index f0f36b0..72d7cd5 100644 --- a/Infrastructure/Symfony/DependencyInjection/Compiler/DomainServiceCompiler.php +++ b/Infrastructure/Symfony/DependencyInjection/Compiler/DomainServiceCompiler.php @@ -2,7 +2,7 @@ namespace Ivoz\Core\Infrastructure\Symfony\DependencyInjection\Compiler; -use Ivoz\Core\Application\Helper\LifecycleServiceHelper; +use Ivoz\Core\Domain\Helper\LifecycleServiceHelper; use Ivoz\Core\Domain\Service\DomainEventSubscriberInterface; use Ivoz\Core\Domain\Service\LifecycleEventHandlerInterface; use Ivoz\Core\Domain\Service\LifecycleServiceCollectionInterface; diff --git a/phpstan.neon b/phpstan.neon index aacb9e6..e27b72d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,7 +3,6 @@ parameters: analyse: - vendor ignoreErrors: - - '#.*unknown class Ivoz\\Provider\\.*#' - - '#.*has invalid type Ivoz\\Provider\\.*#' - '#Unsafe usage of new static\(\)#' - '#.*has invalid type Doctrine\\DBAL\\Driver\\ResultStatement#' + - '#Conditional return type uses subject type T which is not part of PHPDoc @template tags#'