Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-201: Refactored ExportCommand #67

Merged
merged 11 commits into from
Aug 6, 2021
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"EzSystems\\EzRecommendationClientBundle\\": "src/bundle/",
"EzSystems\\EzRecommendationClient\\": "src/lib/",
"Ibexa\\Contracts\\Personalization\\": "src/contracts/",
"Ibexa\\Personalization\\": "src/lib/"
"Ibexa\\Personalization\\": "src/lib/",
"Ibexa\\Bundle\\Personalization\\": "src/bundle/"
}
},
"autoload-dev": {
Expand Down
143 changes: 14 additions & 129 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Cannot call method getDefinition\\(\\) on Symfony\\\\Component\\\\Console\\\\Application\\|null\\.$#"
count: 1
path: src/bundle/Command/ExportCommand.php

-
message: "#^Method EzSystems\\\\EzRecommendationClientBundle\\\\Command\\\\ExportCommand\\:\\:configure\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/bundle/Command/ExportCommand.php

-
message: "#^Parameter \\#5 \\$default of method Symfony\\\\Component\\\\Console\\\\Command\\\\Command\\:\\:addOption\\(\\) expects array\\<string\\>\\|bool\\|string\\|null, int given\\.$#"
count: 3
path: src/bundle/Command/ExportCommand.php

-
message: "#^Left side of && is always true\\.$#"
count: 1
Expand Down Expand Up @@ -95,11 +80,6 @@ parameters:
count: 1
path: src/bundle/Controller/ExportController.php

-
message: "#^Parameter \\#2 \\$values of method Symfony\\\\Component\\\\HttpFoundation\\\\ResponseHeaderBag\\:\\:set\\(\\) expects array\\<string\\>\\|string, int\\|false given\\.$#"
count: 1
path: src/bundle/Controller/ExportController.php

-
message: "#^Method EzSystems\\\\EzRecommendationClientBundle\\\\Controller\\\\RecommendationController\\:\\:getTemplate\\(\\) should return string but returns string\\|null\\.$#"
count: 1
Expand Down Expand Up @@ -390,16 +370,6 @@ parameters:
count: 1
path: src/lib/Event/Subscriber/AbstractCoreEventSubscriber.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\ContentEventSubscriber\\:\\:getSubscribedEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Event/Subscriber/ContentEventSubscriber.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\LocationEventSubscriber\\:\\:getSubscribedEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Event/Subscriber/LocationEventSubscriber.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\LocationEventSubscriber\\:\\:swapLocation\\(\\) has parameter \\$locations with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -410,11 +380,6 @@ parameters:
count: 1
path: src/lib/Event/Subscriber/LocationEventSubscriber.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\ObjectStateEventSubscriber\\:\\:getSubscribedEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Event/Subscriber/ObjectStateEventSubscriber.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\RecommendationEventSubscriber\\:\\:extractRecommendationItems\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -425,11 +390,6 @@ parameters:
count: 1
path: src/lib/Event/Subscriber/RecommendationEventSubscriber.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\RecommendationEventSubscriber\\:\\:getSubscribedEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Event/Subscriber/RecommendationEventSubscriber.php

-
message: "#^Parameter \\#1 \\$parameters of class EzSystems\\\\EzRecommendationClient\\\\Request\\\\BasicRecommendationRequest constructor expects array\\<string\\>, array\\<string, mixed\\> given\\.$#"
count: 1
Expand Down Expand Up @@ -475,11 +435,6 @@ parameters:
count: 1
path: src/lib/Event/Subscriber/RecommendationRandomContentEventSubscriber.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\RecommendationRandomContentEventSubscriber\\:\\:getSubscribedEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Event/Subscriber/RecommendationRandomContentEventSubscriber.php

-
message: "#^PHPDoc tag @param for parameter \\$contentService with type eZ\\\\Publish\\\\API\\\\Repository\\\\SearchService is not subtype of native type eZ\\\\Publish\\\\API\\\\Repository\\\\ContentService\\.$#"
count: 1
Expand All @@ -505,16 +460,6 @@ parameters:
count: 1
path: src/lib/Event/Subscriber/RecommendationRandomContentEventSubscriber.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\TrashEventSubscriber\\:\\:getSubscribedEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Event/Subscriber/TrashEventSubscriber.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\UserAPIRequestDefaultSourceEventSubscriber\\:\\:getSubscribedEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Event/Subscriber/UserAPIRequestDefaultSourceEventSubscriber.php

-
message: "#^Cannot access property \\$source on EzSystems\\\\EzRecommendationClient\\\\SPI\\\\UserAPIRequest\\|null\\.$#"
count: 1
Expand All @@ -525,11 +470,6 @@ parameters:
count: 1
path: src/lib/Event/Subscriber/UserCollectionGeneratorEventSubscriber.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\UserCollectionGeneratorEventSubscriber\\:\\:getSubscribedEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Event/Subscriber/UserCollectionGeneratorEventSubscriber.php

-
message: "#^Property EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\UserCollectionGeneratorEventSubscriber\\:\\:\\$eventDispatcher \\(Symfony\\\\Component\\\\EventDispatcher\\\\EventDispatcher\\) does not accept Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\.$#"
count: 1
Expand All @@ -555,16 +495,6 @@ parameters:
count: 1
path: src/lib/Exception/BadResponseException.php

-
message: "#^Parameter \\#3 \\$previous of method Exception\\:\\:__construct\\(\\) expects Throwable\\|null, EzSystems\\\\EzRecommendationClient\\\\Exception\\\\Throwable\\|null given\\.$#"
count: 1
path: src/lib/Exception/CredentialsNotFoundException.php

-
message: "#^Parameter \\$previous of method EzSystems\\\\EzRecommendationClient\\\\Exception\\\\CredentialsNotFoundException\\:\\:__construct\\(\\) has invalid typehint type EzSystems\\\\EzRecommendationClient\\\\Exception\\\\Throwable\\.$#"
count: 1
path: src/lib/Exception/CredentialsNotFoundException.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exception\\\\FileNotFoundException\\:\\:__construct\\(\\) has parameter \\$code with no typehint specified\\.$#"
count: 1
Expand Down Expand Up @@ -611,54 +541,44 @@ parameters:
path: src/lib/Exception/InvalidRelationException.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:generateUrlList\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
message: "#^Access to an undefined property Ibexa\\\\Personalization\\\\Value\\\\Export\\\\Parameters\\:\\:\\$lang\\.$#"
count: 3
path: src/lib/Exporter/Exporter.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:getContentForGivenLanguages\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
message: "#^Access to an undefined property Ibexa\\\\Personalization\\\\Value\\\\Export\\\\Parameters\\:\\:\\$page\\.$#"
count: 2
path: src/lib/Exporter/Exporter.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:run\\(\\) return type has no value type specified in iterable type array\\.$#"
message: "#^Call to an undefined method Ibexa\\\\Personalization\\\\Value\\\\Export\\\\Parameters\\:\\:getProperties\\(\\)\\.$#"
count: 1
path: src/lib/Exporter/Exporter.php

-
message: "#^Parameter \\#2 \\$lang of method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:generateUrlList\\(\\) expects string, string\\|null given\\.$#"
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:generateUrlList\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Exporter/Exporter.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\ExporterInterface\\:\\:run\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Exporter/ExporterInterface.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Factory\\\\ConfigurableExportParametersFactory\\:\\:create\\(\\) has parameter \\$properties with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Factory/ConfigurableExportParametersFactory.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Factory\\\\ConfigurableExportParametersFactory\\:\\:getMissingRequiredOptions\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:getContentForGivenLanguages\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Factory/ConfigurableExportParametersFactory.php
path: src/lib/Exporter/Exporter.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Factory\\\\ConfigurableExportParametersFactory\\:\\:getMissingRequiredOptions\\(\\) return type has no value type specified in iterable type array\\.$#"
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\Exporter\\:\\:run\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Factory/ConfigurableExportParametersFactory.php
path: src/lib/Exporter/Exporter.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Factory\\\\ExportParametersFactory\\:\\:create\\(\\) has parameter \\$properties with no value type specified in iterable type array\\.$#"
message: "#^Parameter \\#2 \\$parameters of method EzSystems\\\\EzRecommendationClient\\\\Service\\\\ContentServiceInterface\\:\\:fetchContent\\(\\) expects EzSystems\\\\EzRecommendationClient\\\\Value\\\\ExportParameters, Ibexa\\\\Personalization\\\\Value\\\\Export\\\\Parameters given\\.$#"
count: 1
path: src/lib/Factory/ExportParametersFactory.php
path: src/lib/Exporter/Exporter.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Factory\\\\ExportParametersFactoryInterface\\:\\:create\\(\\) has parameter \\$properties with no value type specified in iterable type array\\.$#"
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Exporter\\\\ExporterInterface\\:\\:run\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Factory/ExportParametersFactoryInterface.php
path: src/lib/Exporter/ExporterInterface.php

-
message: "#^Parameter \\#1 \\$str of function strtolower expects string, string\\|null given\\.$#"
Expand Down Expand Up @@ -1100,11 +1020,6 @@ parameters:
count: 1
path: src/lib/SPI/Content.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\SPI\\\\ExportParametersFactoryDecorator\\:\\:create\\(\\) has parameter \\$properties with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/SPI/ExportParametersFactoryDecorator.php

-
message: "#^Property EzSystems\\\\EzRecommendationClient\\\\SPI\\\\Notification\\:\\:\\$events type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1280,11 +1195,6 @@ parameters:
count: 1
path: src/lib/Service/ExportNotificationService.php

-
message: "#^Cannot cast Symfony\\\\Component\\\\Validator\\\\ConstraintViolationListInterface to string\\.$#"
count: 1
path: src/lib/Service/ExportService.php

-
message: "#^Property EzSystems\\\\EzRecommendationClient\\\\Service\\\\ExportService\\:\\:\\$notificationService \\(EzSystems\\\\EzRecommendationClient\\\\Service\\\\ExportNotificationService\\) does not accept EzSystems\\\\EzRecommendationClient\\\\Service\\\\NotificationService\\.$#"
count: 1
Expand Down Expand Up @@ -2005,31 +1915,6 @@ parameters:
count: 1
path: tests/lib/Service/EventNotificationServiceTest.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Service\\\\ExportNotificationServiceTest\\:\\:testCreateExportNotification\\(\\) has no return typehint specified\\.$#"
count: 1
path: tests/lib/Service/ExportNotificationServiceTest.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Service\\\\ExportNotificationServiceTest\\:\\:testCreateInstanceOfEventNotificationService\\(\\) has no return typehint specified\\.$#"
count: 1
path: tests/lib/Service/ExportNotificationServiceTest.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Service\\\\ExportNotificationServiceTest\\:\\:testSendNotification\\(\\) has no return typehint specified\\.$#"
count: 1
path: tests/lib/Service/ExportNotificationServiceTest.php

-
message: "#^Property EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Service\\\\ExportNotificationServiceTest\\:\\:\\$notificationOptions type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/lib/Service/ExportNotificationServiceTest.php

-
message: "#^Property EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Service\\\\ExportNotificationServiceTest\\:\\:\\$urls type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/lib/Service/ExportNotificationServiceTest.php

-
message: "#^Property EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Service\\\\NotificationServiceTest\\:\\:\\$basicNotificationOptions type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
5 changes: 5 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@
<extensions>
<extension class="EzSystems\EzRecommendationClient\PHPUnit\BypassFinalHook"/>
</extensions>
<php>
<env name="RECOMMENDATION_CUSTOMER_ID" value="0" />
<env name="RECOMMENDATION_LICENSE_KEY" value="" />
<env name="RECOMMENDATION_HOST_URI" value="" />
</php>
</phpunit>
60 changes: 26 additions & 34 deletions src/bundle/Command/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*/
declare(strict_types=1);

namespace EzSystems\EzRecommendationClientBundle\Command;
namespace Ibexa\Bundle\Personalization\Command;

use eZ\Bundle\EzPublishCoreBundle\Command\BackwardCompatibleCommand;
use EzSystems\EzRecommendationClient\Factory\ExportParametersFactoryInterface;
use EzSystems\EzRecommendationClient\Http\HttpEnvironmentInterface;
use EzSystems\EzRecommendationClient\Service\ExportServiceInterface;
use Ibexa\Personalization\Export\Input\CommandInputResolverInterface;
use Ibexa\Personalization\Factory\Export\ParametersFactoryInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -25,53 +26,45 @@ final class ExportCommand extends Command implements BackwardCompatibleCommand
{
public const SUCCESS = 0;

/** @var \EzSystems\EzRecommendationClient\Service\ExportServiceInterface */
private $exportService;
private ExportServiceInterface $exportService;

/** @var \EzSystems\EzRecommendationClient\Http\HttpEnvironmentInterface */
private $httpEnvironment;
private HttpEnvironmentInterface $httpEnvironment;

/** @var \Psr\Log\LoggerInterface */
private $logger;
private LoggerInterface $logger;

/** @var \EzSystems\EzRecommendationClient\Factory\ExportParametersFactoryInterface */
private $exportParametersFactory;
private CommandInputResolverInterface $inputResolver;

private ParametersFactoryInterface $exportParametersFactory;

public function __construct(
ExportServiceInterface $exportService,
HttpEnvironmentInterface $httpEnvironment,
LoggerInterface $logger,
ExportParametersFactoryInterface $exportParametersFactory
CommandInputResolverInterface $inputResolver,
ParametersFactoryInterface $exportParametersFactory
) {
parent::__construct();

$this->exportService = $exportService;
$this->httpEnvironment = $httpEnvironment;
$this->logger = $logger;
$this->inputResolver = $inputResolver;
$this->exportParametersFactory = $exportParametersFactory;
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('ibexa:recommendation:run-export')
->setAliases(['ezrecommendation:export:run'])
->setDescription('Run export to files.')
->addOption('webHook', null, InputOption::VALUE_OPTIONAL, 'Guzzle Client base_uri parameter, will be used to send recommendation data')
->addOption('customer-id', null, InputOption::VALUE_REQUIRED, 'Personalization customer id')
->addOption('license-key', null, InputOption::VALUE_REQUIRED, 'Personalization license key')
->addOption('web-hook', null, InputOption::VALUE_OPTIONAL, 'Recommendation engine URI used to send recommendation data')
->addOption('host', null, InputOption::VALUE_OPTIONAL, 'Host used in exportDownload url for notifier in export feature')
->addOption('customerId', null, InputOption::VALUE_OPTIONAL, 'Your eZ Recommendation customer ID')
->addOption('licenseKey', null, InputOption::VALUE_OPTIONAL, 'Your eZ Recommendation license key')
->addOption('pageSize', null, InputOption::VALUE_OPTIONAL, '', 500)
->addOption('page', null, InputOption::VALUE_OPTIONAL, '', 1)
->addOption('path', null, InputOption::VALUE_OPTIONAL, 'A string of subtree path, eg: /1/2/')
->addOption('hidden', null, InputOption::VALUE_OPTIONAL, 'If set to 1 - Criterion Visibility: VISIBLE will be used', 0)
->addOption('image', null, InputOption::VALUE_OPTIONAL, 'Image_variations used for images')
->addOption('contentTypeIdList', null, InputOption::VALUE_REQUIRED, 'List of Content Types ID')
->addOption('fields', null, InputOption::VALUE_OPTIONAL, 'List of the fields, eg: title, description')
;
->addOption('item-type-identifier-list', null, InputOption::VALUE_REQUIRED, 'List of item types identifiers')
->addOption('languages', null, InputOption::VALUE_REQUIRED, 'List of items languages')
->addOption('page-size', null, InputOption::VALUE_OPTIONAL, '', '500');
}

/**
Expand All @@ -84,14 +77,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

date_default_timezone_set('UTC');

$options = array_diff_key(
$input->getOptions(),
$this->getApplication()->getDefinition()->getOptions()
);
$options['siteaccess'] = $input->getOption('siteaccess');

$this->exportService->process(
$this->exportParametersFactory->create($options),
$this->exportService->runExport(
$this->exportParametersFactory->create(
$this->inputResolver->resolve(
$input, $this->getApplication()
),
ParametersFactoryInterface::COMMAND_TYPE
),
$output
);

Expand Down
Loading