diff --git a/.github/workflows/analysis.yaml b/.github/workflows/analysis.yaml index d966d91..a7db376 100644 --- a/.github/workflows/analysis.yaml +++ b/.github/workflows/analysis.yaml @@ -2,7 +2,7 @@ name: Analysis 'on': push: branches: - - master + - main paths-ignore: - README.md pull_request: @@ -16,11 +16,10 @@ jobs: fail-fast: false matrix: php: - - 8.0 - 8.2 + - 8.3 symfony: - - '5.4.*' - - '6.2.*' + - '6.4.*' env: APP_ENV: test steps: diff --git a/.github/workflows/sylius.yaml b/.github/workflows/sylius.yaml index e0dc997..69d0863 100644 --- a/.github/workflows/sylius.yaml +++ b/.github/workflows/sylius.yaml @@ -16,23 +16,16 @@ jobs: fail-fast: false matrix: php: - - 8.0 - 8.2 + - 8.3 sylius: - - 1.10.0 - 1.12.0 + - 1.13.0 + - 1.14.0 symfony: - - 5.4 - - 6.2 + - 6.4 node: - 14.x - exclude: - - - sylius: 1.10.0 - symfony: 6.2 - - - php: '8.0' - symfony: 6.2 env: APP_ENV: test package-name: synolia/sylius-gdpr-plugin diff --git a/Makefile b/Makefile index cdfc9ee..5af0ba5 100644 --- a/Makefile +++ b/Makefile @@ -2,13 +2,14 @@ SHELL=/bin/bash COMPOSER_ROOT=composer TEST_DIRECTORY=tests/Application -CONSOLE=cd tests/Application && php bin/console -e test -COMPOSER=cd tests/Application && composer -YARN=cd tests/Application && yarn +INSTALL_DIRECTORY=install/Application +CONSOLE=cd ${TEST_DIRECTORY} && php bin/console -e test +COMPOSER=cd ${TEST_DIRECTORY} && composer +YARN=cd ${TEST_DIRECTORY} && yarn -SYLIUS_VERSION=1.12.0 -SYMFONY_VERSION=6.1 -PHP_VERSION=8.1 +SYLIUS_VERSION=1.14.0 +SYMFONY_VERSION=6.4 +PHP_VERSION=8.2 PLUGIN_NAME=synolia/sylius-gdpr-plugin ### @@ -19,10 +20,10 @@ install: sylius ## Install Plugin on Sylius [SYLIUS_VERSION=1.12.0] [SYMFONY_VER .PHONY: install reset: ## Remove dependencies -ifneq ("$(wildcard tests/Application/bin/console)","") +ifneq ("$(wildcard ${TEST_DIRECTORY}/bin/console)","") ${CONSOLE} doctrine:database:drop --force --if-exists || true endif - rm -rf tests/Application + rm -rf ${TEST_DIRECTORY} .PHONY: reset phpunit: phpunit-configure phpunit-run ## Run PHPUnit @@ -43,9 +44,6 @@ sylius-standard: update-dependencies: ${COMPOSER} config extra.symfony.require "~${SYMFONY_VERSION}" ${COMPOSER} require symfony/asset:~${SYMFONY_VERSION} --no-scripts --no-update -ifeq ($(SYLIUS_VERSION), 1.9.0) - ${COMPOSER} require laminas/laminas-stdlib:3.4.0 --no-scripts --no-update -endif ${COMPOSER} update --no-progress -n install-plugin: @@ -54,7 +52,7 @@ install-plugin: ${COMPOSER} config minimum-stability "dev" ${COMPOSER} config prefer-stable true ${COMPOSER} req ${PLUGIN_NAME}:* --prefer-source --no-scripts - cp -r install/Application tests + cp -r ${INSTALL_DIRECTORY} tests cp -r tests/data/* ${TEST_DIRECTORY}/ install-sylius: diff --git a/README.md b/README.md index 02e07c1..2cf13e0 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,8 @@ | | Version | |:-------|:--------| -| PHP | ^8.0 | -| Sylius | ^1.10 | +| PHP | ^8.2 | +| Sylius | ^1.12 | ## Installation @@ -44,18 +44,19 @@ composer require synolia/sylius-gdpr-plugin --no-scripts ``` -2. Import required config in your `config/packages/_sylius.yaml` file: +2. Create required config in `config/packages/gdpr.yaml` file: ```yaml imports: - - { resource: "@SynoliaSyliusGDPRPlugin/Resources/config/app/config.yaml" } + - { resource: "@SynoliaSyliusGDPRPlugin/config/gdpr.yaml" } ``` -3. Import routing in your `config/routes.yaml` file: +3. Create routing in `config/routes/gdpr.yaml` file: ```yaml synolia_gdpr: - resource: "@SynoliaSyliusGDPRPlugin/Resources/config/routes.yaml" + resource: "@SynoliaSyliusGDPRPlugin/config/routes/attributes.yaml" + prefix: '/%sylius_admin.path_name%' ``` 4. Process translations @@ -108,7 +109,7 @@ Sylius\Component\Core\Model\Customer: ### Note: > your expression language must starts with `@=` to be evaluated properly - > variable `object` is the current entity your are dealing with (eg. in that case `Sylius\Component\Core\Model\Customer`) + > variable `object` is the current entity you are dealing with (e.g. in that case `Sylius\Component\Core\Model\Customer`) ## Add form in advanced actions page @@ -123,6 +124,8 @@ There's two steps to add your custom form into the page: - 'Synolia\SyliusGDPRPlugin\Form\Type\Actions\AnonymizeCustomerNotLoggedSinceType' tags: ['controller.service_arguments'] ``` + + > or use php attributes `#[AsController]` on your controller and `#[Autowire(AnonymizeCustomerNotLoggedSinceType::class)]` in your constructor for `$formsType` parameter - Then create your form processor by implementing Synolia\SyliusGDPRPlugin\Processor\AnonymizerProcessor\AdvancedActionsFormDataProcessorInterface diff --git a/UPGRATE_1.2.md b/UPGRADE-1.2.md similarity index 100% rename from UPGRATE_1.2.md rename to UPGRADE-1.2.md diff --git a/composer.json b/composer.json index fa67142..0fe013e 100644 --- a/composer.json +++ b/composer.json @@ -11,33 +11,33 @@ ], "license": "EUPL-1.2", "require": { - "php": "^8.0", + "php": "^8.2", "php-http/message-factory": "^1.1", "phpdocumentor/reflection-docblock": "^5.3", - "sylius/sylius": "^1.10", - "symfony/property-info": "^5.4|^6.0" + "sylius/sylius": "^1.12", + "symfony/property-info": "^6.4" }, "require-dev": { - "j13k/yaml-lint": "1.1.4", - "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpmd/phpmd": "2.13.0", - "phpro/grumphp": "1.15.0", - "phpstan/extension-installer": "1.2.0", - "phpstan/phpstan": "1.9.7", - "phpstan/phpstan-doctrine": "1.3.29", - "phpstan/phpstan-strict-rules": "1.4.4", - "phpstan/phpstan-webmozart-assert": "1.2.2", - "phpunit/phpunit": "9.5.27", - "povils/phpmnd": "3.0.1", - "rector/rector": "^0.15.2", - "seld/jsonlint": "1.9.0", - "sylius-labs/coding-standard": "4.3.0", - "symfony/browser-kit": "6.0.11", - "symfony/debug-bundle": "6.0.11", - "symfony/dotenv": "6.0.5", - "symfony/intl": "6.0.15", - "symfony/web-profiler-bundle": "6.0.17", - "thecodingmachine/phpstan-strict-rules": "1.0.0" + "j13k/yaml-lint": "^1.1", + "php-parallel-lint/php-parallel-lint": "^1.4", + "phpmd/phpmd": "^2.15.0", + "phpro/grumphp": "^2.9", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-doctrine": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpstan/phpstan-webmozart-assert": "^2.0", + "phpunit/phpunit": "^9.5", + "povils/phpmnd": "^3.0", + "rector/rector": "^2.0", + "seld/jsonlint": "^1.11", + "squizlabs/php_codesniffer": "^3.11", + "sylius-labs/coding-standard": "^4.3", + "symfony/browser-kit": "^6.4", + "symfony/debug-bundle": "^6.4", + "symfony/dotenv": "^6.4", + "symfony/intl": "^6.4", + "symfony/web-profiler-bundle": "^6.4" }, "config": { "sort-packages": true, diff --git a/config/gdpr.yaml b/config/gdpr.yaml new file mode 100644 index 0000000..51d847a --- /dev/null +++ b/config/gdpr.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: "@SynoliaSyliusGDPRPlugin/config/packages/ui.yaml" } \ No newline at end of file diff --git a/src/Resources/config/mappings/Address.yaml b/config/mappings/Address.yaml similarity index 100% rename from src/Resources/config/mappings/Address.yaml rename to config/mappings/Address.yaml diff --git a/src/Resources/config/mappings/AddressLogEntry.yaml b/config/mappings/AddressLogEntry.yaml similarity index 100% rename from src/Resources/config/mappings/AddressLogEntry.yaml rename to config/mappings/AddressLogEntry.yaml diff --git a/src/Resources/config/mappings/Customer.yaml b/config/mappings/Customer.yaml similarity index 100% rename from src/Resources/config/mappings/Customer.yaml rename to config/mappings/Customer.yaml diff --git a/src/Resources/config/mappings/Order.yaml b/config/mappings/Order.yaml similarity index 100% rename from src/Resources/config/mappings/Order.yaml rename to config/mappings/Order.yaml diff --git a/src/Resources/config/mappings/Payments.yaml b/config/mappings/Payments.yaml similarity index 100% rename from src/Resources/config/mappings/Payments.yaml rename to config/mappings/Payments.yaml diff --git a/src/Resources/config/mappings/ShopUser.yaml b/config/mappings/ShopUser.yaml similarity index 100% rename from src/Resources/config/mappings/ShopUser.yaml rename to config/mappings/ShopUser.yaml diff --git a/src/Resources/config/packages/ui.yaml b/config/packages/ui.yaml similarity index 100% rename from src/Resources/config/packages/ui.yaml rename to config/packages/ui.yaml diff --git a/config/routes/attributes.yaml b/config/routes/attributes.yaml new file mode 100644 index 0000000..5ec5e6e --- /dev/null +++ b/config/routes/attributes.yaml @@ -0,0 +1,5 @@ +controllers: + resource: + path: ../../src/Controller/ + namespace: Synolia\SyliusGDPRPlugin\Controller + type: attribute diff --git a/src/Resources/config/serialization/Address.yaml b/config/serialization/Address.yaml similarity index 100% rename from src/Resources/config/serialization/Address.yaml rename to config/serialization/Address.yaml diff --git a/src/Resources/config/serialization/Adjustment.yaml b/config/serialization/Adjustment.yaml similarity index 100% rename from src/Resources/config/serialization/Adjustment.yaml rename to config/serialization/Adjustment.yaml diff --git a/src/Resources/config/serialization/Customer.yaml b/config/serialization/Customer.yaml similarity index 100% rename from src/Resources/config/serialization/Customer.yaml rename to config/serialization/Customer.yaml diff --git a/src/Resources/config/serialization/Order.yaml b/config/serialization/Order.yaml similarity index 100% rename from src/Resources/config/serialization/Order.yaml rename to config/serialization/Order.yaml diff --git a/src/Resources/config/serialization/OrderItem.yaml b/config/serialization/OrderItem.yaml similarity index 100% rename from src/Resources/config/serialization/OrderItem.yaml rename to config/serialization/OrderItem.yaml diff --git a/src/Resources/config/serialization/Payment.yaml b/config/serialization/Payment.yaml similarity index 100% rename from src/Resources/config/serialization/Payment.yaml rename to config/serialization/Payment.yaml diff --git a/src/Resources/config/serialization/PaymentMethod.yaml b/config/serialization/PaymentMethod.yaml similarity index 100% rename from src/Resources/config/serialization/PaymentMethod.yaml rename to config/serialization/PaymentMethod.yaml diff --git a/src/Resources/config/serialization/Promotions.yaml b/config/serialization/Promotions.yaml similarity index 100% rename from src/Resources/config/serialization/Promotions.yaml rename to config/serialization/Promotions.yaml diff --git a/src/Resources/config/serialization/Shipment.yaml b/config/serialization/Shipment.yaml similarity index 100% rename from src/Resources/config/serialization/Shipment.yaml rename to config/serialization/Shipment.yaml diff --git a/src/Resources/config/serialization/ShippingMethod.yaml b/config/serialization/ShippingMethod.yaml similarity index 100% rename from src/Resources/config/serialization/ShippingMethod.yaml rename to config/serialization/ShippingMethod.yaml diff --git a/src/Resources/config/serialization/ShopUser.yaml b/config/serialization/ShopUser.yaml similarity index 100% rename from src/Resources/config/serialization/ShopUser.yaml rename to config/serialization/ShopUser.yaml diff --git a/config/services.yaml b/config/services.yaml new file mode 100644 index 0000000..e6f8685 --- /dev/null +++ b/config/services.yaml @@ -0,0 +1,8 @@ +services: + _defaults: + autowire: true + autoconfigure: true + + Synolia\SyliusGDPRPlugin\: + resource: '../src/*' + exclude: '../src/{SynoliaSyliusGDPRPlugin.php}' diff --git a/grumphp.yml b/grumphp.yml index f9e7b99..6aae165 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -2,18 +2,9 @@ grumphp: ascii: failed: ~ succeeded: ~ - ignore_unstaged_changes: true tasks: composer: - file: "composer.json" no_check_all: true - git_blacklist: - keywords: - - "var_dump" - - "dump(" - - "print_r" - - "die(" - triggered_by: [php, twig] jsonlint: detect_key_conflicts: true phplint: @@ -21,10 +12,10 @@ grumphp: triggered_by: ['php'] phpmd: ruleset: ["ruleset/.php_md.xml"] - exclude: ["src/Migrations/*"] phpstan: - configuration: "ruleset/phpstan.neon" level: ~ + configuration: "ruleset/phpstan.neon" + use_grumphp_paths: false xmllint: ~ yamllint: ~ ecs: @@ -32,16 +23,10 @@ grumphp: no-progress-bar: true phpmnd: directory: src - testsuites: - git_pre_commit: - tasks: - - composer - - git_blacklist - - jsonlint - - phplint - - phpmd - - phpstan - - xmllint - - yamllint - - ecs - - phpmnd + phpcs: + standard: "ruleset" + warning_severity: 0 + whitelist_patterns: + - 'src' + exclude: + - 'PSR12.Files.FileHeader' diff --git a/install/Application/config/packages/gdpr.yaml b/install/Application/config/packages/gdpr.yaml index afabb9e..9f2d396 100644 --- a/install/Application/config/packages/gdpr.yaml +++ b/install/Application/config/packages/gdpr.yaml @@ -1,2 +1,2 @@ imports: - - { resource: "@SynoliaSyliusGDPRPlugin/Resources/config/app/config.yaml" } + - { resource: "@SynoliaSyliusGDPRPlugin/config/gdpr.yaml" } diff --git a/install/Application/config/routes/gdpr.yaml b/install/Application/config/routes/gdpr.yaml index dc4f887..daf3149 100644 --- a/install/Application/config/routes/gdpr.yaml +++ b/install/Application/config/routes/gdpr.yaml @@ -1,2 +1,3 @@ synolia_gdpr: - resource: "@SynoliaSyliusGDPRPlugin/Resources/config/routes.yaml" + resource: "@SynoliaSyliusGDPRPlugin/config/routes/attributes.yaml" + prefix: '/%sylius_admin.path_name%' \ No newline at end of file diff --git a/ruleset/phpstan.neon b/ruleset/phpstan.neon index 769dc4d..d3ec2e9 100644 --- a/ruleset/phpstan.neon +++ b/ruleset/phpstan.neon @@ -1,20 +1,19 @@ parameters: - level: max + level: 8 reportUnmatchedIgnoredErrors: false - checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false + paths: + - ../src bootstrapFiles: - '../vendor/autoload.php' excludePaths: - '../vendor/' - - '../src/Migrations/' - - '../source/src/Kernel.php' - - '../dev' - '../bin' - '../tests' - '../src/DependencyInjection' - '../src/SynoliaSyliusGDPRPlugin.php' ignoreErrors: + - identifier: missingType.iterableValue + - identifier: missingType.generics - '#Parameter \#1 \$className of static method Doctrine\\Common\\Util\\ClassUtils::newReflectionClass\(\) expects class-string, string given.#' - '#Variable method call on object.#' - '#Variable method call on mixed.#' diff --git a/ruleset/rector.php b/ruleset/rector.php index 8a57164..e793608 100644 --- a/ruleset/rector.php +++ b/ruleset/rector.php @@ -2,19 +2,31 @@ declare(strict_types=1); -use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; -use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; +use Rector\Symfony\Set\SymfonySetList; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([ - dirname(__DIR__) . '/src', - dirname(__DIR__) . '/tests/PHPUnit', +return RectorConfig::configure() + ->withPaths([ + \dirname(__DIR__, 1) . '/src', + \dirname(__DIR__, 1) . '/tests/PHPUnit', + ]) + ->withPHPStanConfigs([__DIR__ . '/phpstan.neon']) + ->withPhpSets(php82: true) + ->withAttributesSets(symfony: true, doctrine: true) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + doctrineCodeQuality: true, + symfonyConfigs: true, + ) + ->withTypeCoverageLevel(0) + ->withSets([ + SymfonySetList::SYMFONY_60, + SymfonySetList::SYMFONY_61, + SymfonySetList::SYMFONY_62, + SymfonySetList::SYMFONY_63, + SymfonySetList::SYMFONY_64, + SetList::CODE_QUALITY, + SetList::DEAD_CODE, ]); - - $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_74, - LevelSetList::UP_TO_PHP_80 - ]); -}; diff --git a/ruleset/ruleset.xml b/ruleset/ruleset.xml new file mode 100644 index 0000000..3008a56 --- /dev/null +++ b/ruleset/ruleset.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/Annotation/Anonymize.php b/src/Annotation/Anonymize.php index 5cc726a..ffefa31 100644 --- a/src/Annotation/Anonymize.php +++ b/src/Annotation/Anonymize.php @@ -4,7 +4,7 @@ namespace Synolia\SyliusGDPRPlugin\Annotation; -use Doctrine\ORM\Mapping\Annotation; +use Doctrine\ORM\Mapping\MappingAttribute; use Synolia\SyliusGDPRPlugin\Validator\FakerOptionsValidator; /** @@ -12,7 +12,7 @@ * * @Target({"PROPERTY","ANNOTATION"}) */ -final class Anonymize implements Annotation +final class Anonymize implements MappingAttribute { public ?string $faker; diff --git a/src/Command/AnonymizeProcessCommand.php b/src/Command/AnonymizeProcessCommand.php index c84b3ad..492183f 100644 --- a/src/Command/AnonymizeProcessCommand.php +++ b/src/Command/AnonymizeProcessCommand.php @@ -6,6 +6,7 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\Mapping\ClassMetadata; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -13,12 +14,11 @@ use Symfony\Component\Console\Style\SymfonyStyle; use Synolia\SyliusGDPRPlugin\Processor\AnonymizerProcessor; +#[AsCommand(name: 'synolia:gdpr:anonymize', description: 'Change properties of data entity which have the `Anonymize` annotation.')] final class AnonymizeProcessCommand extends Command { private const MAX_RETRIES = 10000; - protected static $defaultName = 'synolia:gdpr:anonymize'; - private SymfonyStyle $io; private bool $reset; @@ -26,8 +26,8 @@ final class AnonymizeProcessCommand extends Command private int $maxRetries; public function __construct( - private AnonymizerProcessor $anonymizerProcessor, - private EntityManagerInterface $entityManager, + private readonly AnonymizerProcessor $anonymizerProcessor, + private readonly EntityManagerInterface $entityManager, string $name = null, ) { parent::__construct($name); @@ -36,7 +36,6 @@ public function __construct( protected function configure(): void { $this - ->setDescription('Change proprieties data entity which have the annotation anonymize.') ->addOption('entity', 'E', InputOption::VALUE_REQUIRED, 'Entity full qualified class name') ->addOption('id', 'i', InputOption::VALUE_REQUIRED, 'Object ID') ->addOption('force', null, InputOption::VALUE_NONE, 'Force command') @@ -64,19 +63,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (null === $id) { $this->anonymizeEntityForClassName($className, $force, null); - return 0; + return Command::SUCCESS; } $this->anonymizeEntityForClassName($className, $force, (string) $id); - return 0; + return Command::SUCCESS; } $this->io->error('Options are empty. Use --help to get the doc.'); - return 0; + return Command::SUCCESS; } catch (\LogicException $exception) { $this->io->error($exception->getMessage()); - return 1; + return Command::FAILURE; } } @@ -94,7 +93,7 @@ private function anonymizeEntityForClassName(string $className, bool $force, ?st 'Are you sure to anonymize this entity (' . $className . ') ? Data will be changed without back-up.', false, ); - if (true !== $response) { + if (!$response) { throw new \LogicException('No data has been changed.'); } } diff --git a/src/Controller/AdvancedActionsController.php b/src/Controller/AdvancedActionsController.php index 1501589..e6b15f6 100644 --- a/src/Controller/AdvancedActionsController.php +++ b/src/Controller/AdvancedActionsController.php @@ -7,11 +7,14 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Attribute\AsController; +use Symfony\Component\Routing\Attribute\Route; use function Symfony\Component\String\u; use Synolia\SyliusGDPRPlugin\Form\Type\Actions\AnonymizeCustomersNotLoggedBeforeType; use Synolia\SyliusGDPRPlugin\Form\Type\Actions\AnonymizeCustomersWithoutAnyOrdersBeforeType; use Synolia\SyliusGDPRPlugin\Processor\AdvancedActions\CompositeAdvancedActionsFormDataProcessor; +#[AsController] class AdvancedActionsController extends AbstractController { private const FORMS = [ @@ -20,11 +23,12 @@ class AdvancedActionsController extends AbstractController ]; public function __construct( - private CompositeAdvancedActionsFormDataProcessor $compositeAdvancedActionsFormDataProcessor, - private array $formsType = [], + private readonly CompositeAdvancedActionsFormDataProcessor $compositeAdvancedActionsFormDataProcessor, + private readonly array $formsType = [], ) { } + #[Route('/gdpr/actions', name: 'synolia_sylius_gdpr_admin_advanced_actions', defaults: ['_sylius' => ['permission' => true, 'section' => 'admin', 'alias' => 'plugin_synolia_gdpr']])] public function __invoke(Request $request): Response { $formViews = array_merge( @@ -46,7 +50,7 @@ private function generateAndProcessFormsType(Request $request, array $formsType) $form->handleRequest($request); /** @var string $classNameToClean */ - $classNameToClean = strrchr($formType, '\\'); + $classNameToClean = strrchr((string) $formType, '\\'); /** @var string $className */ $className = substr($classNameToClean, 1); $formTypeViews[u($className)->snake()->toString()] = $form->createView(); diff --git a/src/Controller/AnonymizationController.php b/src/Controller/AnonymizationController.php index 02673c0..5642f4a 100644 --- a/src/Controller/AnonymizationController.php +++ b/src/Controller/AnonymizationController.php @@ -10,21 +10,25 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Attribute\AsController; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Synolia\SyliusGDPRPlugin\Event\AfterCustomerAnonymize; use Synolia\SyliusGDPRPlugin\Event\BeforeCustomerAnonymize; use Synolia\SyliusGDPRPlugin\Provider\AnonymizerInterface; +#[AsController] class AnonymizationController extends AbstractController { public function __construct( - private EntityManagerInterface $entityManager, - private CustomerRepositoryInterface $customerRepository, - private AnonymizerInterface $anonymizer, - private EventDispatcherInterface $eventDispatcher, + private readonly EntityManagerInterface $entityManager, + private readonly CustomerRepositoryInterface $customerRepository, + private readonly AnonymizerInterface $anonymizer, + private readonly EventDispatcherInterface $eventDispatcher, ) { } + #[Route('/customers/{id}/anonymize', name: 'synolia_sylius_gdpr_admin_anonymize_customer', defaults: ['_sylius' => ['permission' => true, 'section' => 'admin', 'alias' => 'plugin_synolia_gdpr']], methods: ['GET|POST'])] public function __invoke(Request $request, string $id): Response { $customer = $this->customerRepository->find($id); @@ -35,16 +39,11 @@ public function __invoke(Request $request, string $id): Response } $this->eventDispatcher->dispatch(new BeforeCustomerAnonymize($customer)); - /** @var string $email */ $email = $customer->getEmail(); - $this->anonymizer->anonymize($customer); - $this->entityManager->flush(); - $this->eventDispatcher->dispatch(new AfterCustomerAnonymize($customer, $email)); - $request->getSession()->getFlashBag()->add('success', 'sylius.ui.admin.synolia_gdpr.success'); return $this->redirectToRoute('sylius_admin_customer_show', ['id' => $customer->getId()]); diff --git a/src/Controller/ExportDataController.php b/src/Controller/ExportDataController.php index 076567e..2a7e0a1 100644 --- a/src/Controller/ExportDataController.php +++ b/src/Controller/ExportDataController.php @@ -10,23 +10,27 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\HttpFoundation\HeaderUtils; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Attribute\AsController; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Synolia\SyliusGDPRPlugin\Enum\GDPRSerializationKeyEnum; use Synolia\SyliusGDPRPlugin\Event\BeforeExportCustomerData; +#[AsController] class ExportDataController extends AbstractController { protected const FILE_NAME = 'export_data'; public function __construct( - private CustomerRepositoryInterface $customerRepository, - private ParameterBagInterface $parameterBag, - private EventDispatcherInterface $eventDispatcher, - private SerializerInterface $serializer, + private readonly CustomerRepositoryInterface $customerRepository, + private readonly ParameterBagInterface $parameterBag, + private readonly EventDispatcherInterface $eventDispatcher, + private readonly SerializerInterface $serializer, ) { } + #[Route('/customers/{id}/export-data', name: 'synolia_sylius_gdpr_admin_export_customer_data', defaults: ['_sylius' => ['permission' => true, 'section' => 'admin', 'alias' => 'plugin_synolia_gdpr']], methods: ['GET|POST'])] public function __invoke(string $id): Response { $customer = $this->customerRepository->find($id); diff --git a/src/DependencyInjection/CompilerPass/RegisterAdvancedActionsFormDataProcessorsPass.php b/src/DependencyInjection/CompilerPass/RegisterAdvancedActionsFormDataProcessorsPass.php index 84689c5..75afbf4 100644 --- a/src/DependencyInjection/CompilerPass/RegisterAdvancedActionsFormDataProcessorsPass.php +++ b/src/DependencyInjection/CompilerPass/RegisterAdvancedActionsFormDataProcessorsPass.php @@ -7,6 +7,7 @@ use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\PrioritizedCompositeServicePass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Synolia\SyliusGDPRPlugin\Processor\AdvancedActions\AdvancedActionsFormDataProcessorInterface; +use Synolia\SyliusGDPRPlugin\Processor\AdvancedActions\CompositeAdvancedActionsFormDataProcessor; final class RegisterAdvancedActionsFormDataProcessorsPass extends PrioritizedCompositeServicePass { @@ -16,7 +17,7 @@ public function __construct() { parent::__construct( 'synolia.gdpr_processing.advanced_actions_form_data_processor', - \Synolia\SyliusGDPRPlugin\Processor\AdvancedActions\CompositeAdvancedActionsFormDataProcessor::class, + CompositeAdvancedActionsFormDataProcessor::class, self::PROCESSOR_SERVICE_TAG, 'addProcessor', ); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 2a74806..fe23cf9 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -17,14 +17,14 @@ public function getConfigTreeBuilder(): TreeBuilder ->booleanNode('disable_default_mappings') ->defaultFalse() ->end() - ->arrayNode('anonymization') - ->children() - ->arrayNode('mappings') - ->children() - ->arrayNode('paths') - ->scalarPrototype() - ->end() + ->arrayNode('anonymization') + ->children() + ->arrayNode('mappings') + ->children() + ->arrayNode('paths') + ->scalarPrototype() ->end() + ->end() ->end() ->end() ->end() diff --git a/src/DependencyInjection/SynoliaSyliusGDPRExtension.php b/src/DependencyInjection/SynoliaSyliusGDPRExtension.php index 59c190c..eda728e 100644 --- a/src/DependencyInjection/SynoliaSyliusGDPRExtension.php +++ b/src/DependencyInjection/SynoliaSyliusGDPRExtension.php @@ -21,7 +21,7 @@ final class SynoliaSyliusGDPRExtension extends Extension public function load(array $configs, ContainerBuilder $container): void { $config = $this->processConfiguration($this->getConfiguration([], $container), $configs); - $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader = new YamlFileLoader($container, new FileLocator(\dirname(__DIR__, 2) . '/config')); $loader->load('services.yaml'); @@ -79,7 +79,7 @@ private function retrieveMappings(array $configs, bool $disableDefaultMappings = 'anonymization' => [ 'mappings' => [ 'paths' => [ - __DIR__ . '/../Resources/config/mappings/', + \dirname(__DIR__, 2) . '/config/mappings/', ], ], ], diff --git a/src/Event/AfterAnonymize.php b/src/Event/AfterAnonymize.php index 3d76dbb..ed1de62 100644 --- a/src/Event/AfterAnonymize.php +++ b/src/Event/AfterAnonymize.php @@ -8,11 +8,11 @@ class AfterAnonymize extends Event { - public function __construct(private Object $entity, private array $oldData = []) + public function __construct(private readonly object $entity, private readonly array $oldData = []) { } - public function getEntity(): Object + public function getEntity(): object { return $this->entity; } diff --git a/src/Event/AfterCustomerAnonymize.php b/src/Event/AfterCustomerAnonymize.php index 8793753..5327530 100644 --- a/src/Event/AfterCustomerAnonymize.php +++ b/src/Event/AfterCustomerAnonymize.php @@ -9,7 +9,7 @@ class AfterCustomerAnonymize extends Event { - public function __construct(private CustomerInterface $customer, private string $oldEmail) + public function __construct(private readonly CustomerInterface $customer, private readonly string $oldEmail) { } diff --git a/src/Event/BeforeAnonymize.php b/src/Event/BeforeAnonymize.php index c6c56d6..106be24 100644 --- a/src/Event/BeforeAnonymize.php +++ b/src/Event/BeforeAnonymize.php @@ -8,11 +8,11 @@ class BeforeAnonymize extends Event { - public function __construct(private Object $entity) + public function __construct(private readonly object $entity) { } - public function getEntity(): Object + public function getEntity(): object { return $this->entity; } diff --git a/src/Event/BeforeCustomerAnonymize.php b/src/Event/BeforeCustomerAnonymize.php index 70dab11..c34db78 100644 --- a/src/Event/BeforeCustomerAnonymize.php +++ b/src/Event/BeforeCustomerAnonymize.php @@ -9,7 +9,7 @@ class BeforeCustomerAnonymize extends Event { - public function __construct(private CustomerInterface $customer) + public function __construct(private readonly CustomerInterface $customer) { } diff --git a/src/Event/BeforeExportCustomerData.php b/src/Event/BeforeExportCustomerData.php index 928f6da..f7fdeae 100644 --- a/src/Event/BeforeExportCustomerData.php +++ b/src/Event/BeforeExportCustomerData.php @@ -9,7 +9,7 @@ class BeforeExportCustomerData extends Event { - public function __construct(private CustomerInterface $customer) + public function __construct(private readonly CustomerInterface $customer) { } diff --git a/src/EventSubscriber/AnonymizeAddressLogEntrySubscriber.php b/src/EventSubscriber/AnonymizeAddressLogEntrySubscriber.php index 52e2086..66b0c8b 100644 --- a/src/EventSubscriber/AnonymizeAddressLogEntrySubscriber.php +++ b/src/EventSubscriber/AnonymizeAddressLogEntrySubscriber.php @@ -13,8 +13,8 @@ class AnonymizeAddressLogEntrySubscriber implements EventSubscriberInterface { public function __construct( - private AnonymizerInterface $anonymizer, - private RepositoryInterface $addressLogEntryRepository, + private readonly AnonymizerInterface $anonymizer, + private readonly RepositoryInterface $addressLogEntryRepository, ) { } diff --git a/src/EventSubscriber/RemoveCartBeforeExportCustomerSubscriber.php b/src/EventSubscriber/RemoveCartBeforeExportCustomerSubscriber.php index 211e003..38f1b26 100644 --- a/src/EventSubscriber/RemoveCartBeforeExportCustomerSubscriber.php +++ b/src/EventSubscriber/RemoveCartBeforeExportCustomerSubscriber.php @@ -13,7 +13,7 @@ class RemoveCartBeforeExportCustomerSubscriber implements EventSubscriberInterface { public function __construct( - private OrderRepositoryInterface $orderRepository, + private readonly OrderRepositoryInterface $orderRepository, ) { } diff --git a/src/Loader/AnnotationLoader.php b/src/Loader/AnnotationLoader.php index f7db497..862e040 100644 --- a/src/Loader/AnnotationLoader.php +++ b/src/Loader/AnnotationLoader.php @@ -10,7 +10,7 @@ use Synolia\SyliusGDPRPlugin\Loader\Mapping\AttributeMetaData; use Synolia\SyliusGDPRPlugin\Loader\Mapping\AttributeMetadataCollection; -final class AnnotationLoader implements LoaderInterface +final readonly class AnnotationLoader implements LoaderInterface { public function __construct(private Reader $annotationReader) { diff --git a/src/Loader/ArrayLoader.php b/src/Loader/ArrayLoader.php index 8e28ce1..89eddff 100644 --- a/src/Loader/ArrayLoader.php +++ b/src/Loader/ArrayLoader.php @@ -9,7 +9,7 @@ use Synolia\SyliusGDPRPlugin\Loader\Mapping\AttributeMetadataCollection; use Synolia\SyliusGDPRPlugin\Validator\FakerOptionsValidator; -final class ArrayLoader implements LoaderInterface +final readonly class ArrayLoader implements LoaderInterface { public function __construct(private array $mappings = []) { diff --git a/src/Loader/Mapping/AttributeMetaData.php b/src/Loader/Mapping/AttributeMetaData.php index d3c0eda..4f86280 100644 --- a/src/Loader/Mapping/AttributeMetaData.php +++ b/src/Loader/Mapping/AttributeMetaData.php @@ -6,7 +6,7 @@ use Synolia\SyliusGDPRPlugin\Validator\FakerOptionsValidator; -final class AttributeMetaData implements AttributeMetaDataInterface +final readonly class AttributeMetaData implements AttributeMetaDataInterface { public function __construct( private ?string $faker = null, diff --git a/src/Menu/GDPRMenuListener.php b/src/Menu/AdminMenuListener.php similarity index 52% rename from src/Menu/GDPRMenuListener.php rename to src/Menu/AdminMenuListener.php index fead20e..9a592ea 100644 --- a/src/Menu/GDPRMenuListener.php +++ b/src/Menu/AdminMenuListener.php @@ -5,17 +5,19 @@ namespace Synolia\SyliusGDPRPlugin\Menu; use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent; +use Symfony\Component\EventDispatcher\Attribute\AsEventListener; -final class GDPRMenuListener +#[AsEventListener(event: 'sylius.menu.admin.main', method: 'addAdminMenuItems')] +final class AdminMenuListener { - public function addGDPRMenuItems(MenuBuilderEvent $event): void + public function addAdminMenuItems(MenuBuilderEvent $event): void { $menu = $event->getMenu(); $gdprMenu = $menu->addChild('gdpr'); $gdprMenu ->addChild('sylius.ui.admin.synolia_gdpr.advanced_actions.title', [ - 'route' => 'sylius_gdpr_advanced_actions', + 'route' => 'synolia_sylius_gdpr_admin_advanced_actions', ]) ; } diff --git a/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php b/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php index 18f94bc..196e1ed 100644 --- a/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php +++ b/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php @@ -14,24 +14,12 @@ class AnonymizeCustomersNotLoggedBeforeProcessor implements AdvancedActionsFormDataProcessorInterface { - private EntityManagerInterface $entityManager; - - private AnonymizerProcessor $anonymizerProcessor; - - private ParameterBagInterface $parameterBag; - - private RequestStack $requestStack; - public function __construct( - EntityManagerInterface $entityManager, - AnonymizerProcessor $anonymizerProcessor, - ParameterBagInterface $parameterBag, - RequestStack $requestStack, + private readonly EntityManagerInterface $entityManager, + private readonly AnonymizerProcessor $anonymizerProcessor, + private readonly ParameterBagInterface $parameterBag, + private readonly RequestStack $requestStack, ) { - $this->entityManager = $entityManager; - $this->anonymizerProcessor = $anonymizerProcessor; - $this->parameterBag = $parameterBag; - $this->requestStack = $requestStack; } /** @inheritdoc */ @@ -80,6 +68,6 @@ private function getCustomersFromShopUsers(array $shopUsers): array public function getFormTypesClass(): array { - return ['Synolia\SyliusGDPRPlugin\Form\Type\Actions\AnonymizeCustomersNotLoggedBeforeType']; + return [\Synolia\SyliusGDPRPlugin\Form\Type\Actions\AnonymizeCustomersNotLoggedBeforeType::class]; } } diff --git a/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php b/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php index c075987..ab6058f 100644 --- a/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php +++ b/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php @@ -11,31 +11,19 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\RequestStack; +use Synolia\SyliusGDPRPlugin\Form\Type\Actions\AnonymizeCustomersWithoutAnyOrdersBeforeType; use Synolia\SyliusGDPRPlugin\Processor\AnonymizerProcessor; class AnonymizeCustomersWithoutAnyOrdersBeforeProcessor implements AdvancedActionsFormDataProcessorInterface { - private EntityManagerInterface $entityManager; - - private AnonymizerProcessor $anonymizerProcessor; - - private ParameterBagInterface $parameterBag; - - private RequestStack $requestStack; - public function __construct( - EntityManagerInterface $entityManager, - AnonymizerProcessor $anonymizerProcessor, - ParameterBagInterface $parameterBag, - RequestStack $requestStack, + private readonly EntityManagerInterface $entityManager, + private readonly AnonymizerProcessor $anonymizerProcessor, + private readonly ParameterBagInterface $parameterBag, + private readonly RequestStack $requestStack, ) { - $this->entityManager = $entityManager; - $this->anonymizerProcessor = $anonymizerProcessor; - $this->parameterBag = $parameterBag; - $this->requestStack = $requestStack; } - /** @inheritdoc */ public function process(string $formTypeClass, FormInterface $form): void { /** @var string $customer */ @@ -84,6 +72,6 @@ private function removeNoneEligibleCustomers(array &$customers): array public function getFormTypesClass(): array { - return ['Synolia\SyliusGDPRPlugin\Form\Type\Actions\AnonymizeCustomersWithoutAnyOrdersBeforeType']; + return [AnonymizeCustomersWithoutAnyOrdersBeforeType::class]; } } diff --git a/src/Processor/AdvancedActions/CompositeAdvancedActionsFormDataProcessor.php b/src/Processor/AdvancedActions/CompositeAdvancedActionsFormDataProcessor.php index 9dce947..d67cf05 100644 --- a/src/Processor/AdvancedActions/CompositeAdvancedActionsFormDataProcessor.php +++ b/src/Processor/AdvancedActions/CompositeAdvancedActionsFormDataProcessor.php @@ -11,10 +11,9 @@ class CompositeAdvancedActionsFormDataProcessor implements AdvancedActionsFormDa { /** * @var PriorityQueue|AdvancedActionsFormDataProcessorInterface[] - * * @psalm-var PriorityQueue */ - private \Laminas\Stdlib\PriorityQueue $advancedActionsFormDataProcessor; + private readonly \Laminas\Stdlib\PriorityQueue $advancedActionsFormDataProcessor; public function __construct() { diff --git a/src/Processor/AnonymizerProcessor.php b/src/Processor/AnonymizerProcessor.php index a562da5..9a1eaa5 100644 --- a/src/Processor/AnonymizerProcessor.php +++ b/src/Processor/AnonymizerProcessor.php @@ -13,26 +13,14 @@ final class AnonymizerProcessor { private const MODULO_FLUSH = 50; - private AnonymizerInterface $anonymizer; - - private EntityManagerInterface $entityManager; - - private TranslatorInterface $translator; - - private LoggerInterface $logger; - private int $anonymizedEntity = 0; public function __construct( - AnonymizerInterface $anonymizer, - EntityManagerInterface $entityManager, - TranslatorInterface $translator, - LoggerInterface $logger, + private readonly AnonymizerInterface $anonymizer, + private readonly EntityManagerInterface $entityManager, + private readonly TranslatorInterface $translator, + private readonly LoggerInterface $logger, ) { - $this->anonymizer = $anonymizer; - $this->entityManager = $entityManager; - $this->translator = $translator; - $this->logger = $logger; } public function anonymizeEntities(array $entities, bool $reset = false, int $maxRetries = 50): void @@ -59,7 +47,7 @@ public function getAnonymizedEntityCount(): int return $this->anonymizedEntity; } - private function anonymizeEntity(Object $entity, bool $reset = false, int $maxRetries = 50): void + private function anonymizeEntity(object $entity, bool $reset = false, int $maxRetries = 50): void { $this->anonymizer->anonymize($entity, $reset, $maxRetries); diff --git a/src/Provider/Anonymizer.php b/src/Provider/Anonymizer.php index 6e8c0fd..4077eff 100644 --- a/src/Provider/Anonymizer.php +++ b/src/Provider/Anonymizer.php @@ -24,7 +24,7 @@ use Synolia\SyliusGDPRPlugin\Loader\Mapping\AttributeMetaDataInterface; use Synolia\SyliusGDPRPlugin\Validator\FakerOptionsValidator; -final class Anonymizer implements AnonymizerInterface +final readonly class Anonymizer implements AnonymizerInterface { private const TYPE_VALUES = [ 'bool', @@ -52,7 +52,7 @@ public function __construct( $this->expressionLanguage = new ExpressionLanguage(); } - public function anonymize(Object $entity, bool $reset = false, int $maxRetries = 10000): void + public function anonymize(object $entity, bool $reset = false, int $maxRetries = 10000): void { $this->eventDispatcher->dispatch(new BeforeAnonymize($entity)); @@ -107,7 +107,7 @@ public function anonymize(Object $entity, bool $reset = false, int $maxRetries = } private function anonymizeProcess( - Object $entity, + object $entity, bool $reset, int $maxRetries, string $className, @@ -127,7 +127,7 @@ private function anonymizeProcess( return; } - if (true === $attributeMetaData->isUnique()) { + if ($attributeMetaData->isUnique()) { $value = $this->faker->unique($reset, $maxRetries)->format($attributeMetaData->getFaker(), $attributeMetaData->getArgs()); $this->setUniqueValue($entity, $value, $type, $propertyName, $attributeMetaData); @@ -169,7 +169,7 @@ private function anonymizeProcess( } private function setUniqueValue( - Object $entity, + object $entity, mixed $value, string $type, string $propertyName, @@ -286,7 +286,7 @@ private function isValueProvided(mixed $value): bool /** @param array|bool|int|string|null $value */ private function handleValue( - Object $entity, + object $entity, $value, string $type, string $propertyName, diff --git a/src/Provider/AnonymizerInterface.php b/src/Provider/AnonymizerInterface.php index 16d5807..4b50175 100644 --- a/src/Provider/AnonymizerInterface.php +++ b/src/Provider/AnonymizerInterface.php @@ -6,5 +6,5 @@ interface AnonymizerInterface { - public function anonymize(Object $entity, bool $reset = false, int $maxRetries = 10000): void; + public function anonymize(object $entity, bool $reset = false, int $maxRetries = 10000): void; } diff --git a/src/Resources/config/app/config.yaml b/src/Resources/config/app/config.yaml deleted file mode 100644 index e6d7c6c..0000000 --- a/src/Resources/config/app/config.yaml +++ /dev/null @@ -1,2 +0,0 @@ -imports: - - { resource: "@SynoliaSyliusGDPRPlugin/Resources/config/packages/ui.yaml" } diff --git a/src/Resources/config/routes.yaml b/src/Resources/config/routes.yaml deleted file mode 100644 index 8365d5c..0000000 --- a/src/Resources/config/routes.yaml +++ /dev/null @@ -1,8 +0,0 @@ -synolia_gdpr: - resource: "@SynoliaSyliusGDPRPlugin/Resources/config/routes/admin/customer.yaml" - prefix: '%sylius_admin.path_name%' - -sylius_gdpr_controllers: - resource: '@SynoliaSyliusGDPRPlugin/Resources/config/routes/admin/gdpr.yaml' - prefix: '%sylius_admin.path_name%/gdpr/' - name_prefix: 'sylius_gdpr_' diff --git a/src/Resources/config/routes/admin/customer.yaml b/src/Resources/config/routes/admin/customer.yaml deleted file mode 100644 index d70e718..0000000 --- a/src/Resources/config/routes/admin/customer.yaml +++ /dev/null @@ -1,19 +0,0 @@ -synolia_sylius_gdpr_admin_anonymize_customer: - path: /customers/{id}/anonymize - methods: POST|GET - controller: Synolia\SyliusGDPRPlugin\Controller\AnonymizationController - defaults: - _sylius: - permission: true - section: admin - alias: plugin_synolia_gdpr - -synolia_sylius_gdpr_admin_export_customer_datas: - path: /customers/{id}/export-data - methods: POST|GET - controller: Synolia\SyliusGDPRPlugin\Controller\ExportDataController - defaults: - _sylius: - permission: true - section: admin - alias: plugin_synolia_gdpr diff --git a/src/Resources/config/routes/admin/gdpr.yaml b/src/Resources/config/routes/admin/gdpr.yaml deleted file mode 100644 index 41e09ee..0000000 --- a/src/Resources/config/routes/admin/gdpr.yaml +++ /dev/null @@ -1,8 +0,0 @@ -advanced_actions: - path: /actions - controller: Synolia\SyliusGDPRPlugin\Controller\AdvancedActionsController - defaults: - _sylius: - permission: true - section: admin - alias: plugin_synolia_gdpr diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml deleted file mode 100644 index 99a01a0..0000000 --- a/src/Resources/config/services.yaml +++ /dev/null @@ -1,13 +0,0 @@ -services: - _defaults: - autowire: true - autoconfigure: true - public: false - - Synolia\SyliusGDPRPlugin\: - resource: '../../*' - exclude: '../../{Entity,SynoliaSyliusGDPRPlugin.php}' - - Synolia\SyliusGDPRPlugin\Menu\GDPRMenuListener: - tags: - - { name: kernel.event_listener, event: sylius.menu.admin.main, method: addGDPRMenuItems } diff --git a/src/Resources/public/greeting.js b/src/Resources/public/greeting.js deleted file mode 100644 index 3d7adfd..0000000 --- a/src/Resources/public/greeting.js +++ /dev/null @@ -1,3 +0,0 @@ -setTimeout(function () { - document.getElementById('greeting').innerHTML = document.getElementById('greeting').dataset.greeting; -}, 1000); diff --git a/src/SynoliaSyliusGDPRPlugin.php b/src/SynoliaSyliusGDPRPlugin.php index ee690ca..fa5e125 100644 --- a/src/SynoliaSyliusGDPRPlugin.php +++ b/src/SynoliaSyliusGDPRPlugin.php @@ -21,4 +21,9 @@ public function build(ContainerBuilder $container): void $container->addCompilerPass(new RegisterAnonymizationLoader()); $container->addCompilerPass(new RegisterAdvancedActionsFormDataProcessorsPass()); } + + public function getPath(): string + { + return \dirname(__DIR__); + } } diff --git a/src/Twig/GdprExtension.php b/src/Twig/GdprExtension.php index c2a1116..3d48d03 100644 --- a/src/Twig/GdprExtension.php +++ b/src/Twig/GdprExtension.php @@ -13,7 +13,7 @@ final class GdprExtension extends AbstractExtension public function getFunctions() { return [ - new TwigFunction('sylius_plus_rbac_gdpr_has_permission', [$this, 'hasPermission'], ['needs_environment' => true]), + new TwigFunction('sylius_plus_rbac_gdpr_has_permission', $this->hasPermission(...), ['needs_environment' => true]), ]; } diff --git a/src/Validator/ArrayMappingValidator.php b/src/Validator/ArrayMappingValidator.php index 55f8f74..e52ee20 100644 --- a/src/Validator/ArrayMappingValidator.php +++ b/src/Validator/ArrayMappingValidator.php @@ -54,14 +54,12 @@ private function checkProperty(array $mapping, string $className): void $exception, ); } - - continue; } } private function checkPropertyOptions(array $options): void { - if (self::OPTIONS_LENGTH < \count($options) || 0 === \count($options)) { + if (self::OPTIONS_LENGTH < \count($options) || [] === $options) { throw new \LogicException('Anonymization expected 1 to 5 properties ' . \count($options) . ' given.'); } diff --git a/src/Resources/views/Admin/Customer/Show/gdpr.html.twig b/templates/Admin/Customer/Show/gdpr.html.twig similarity index 57% rename from src/Resources/views/Admin/Customer/Show/gdpr.html.twig rename to templates/Admin/Customer/Show/gdpr.html.twig index 3880f0e..fd4c68a 100644 --- a/src/Resources/views/Admin/Customer/Show/gdpr.html.twig +++ b/templates/Admin/Customer/Show/gdpr.html.twig @@ -1,18 +1,19 @@ -{% if sylius_plus_rbac_gdpr_has_permission("synolia_sylius_gdpr_admin_anonymize_customer") or - sylius_plus_rbac_gdpr_has_permission("synolia_sylius_gdpr_admin_export_customer_datas") %} +{% if + sylius_plus_rbac_gdpr_has_permission("synolia_sylius_gdpr_admin_anonymize_customer") or + sylius_plus_rbac_gdpr_has_permission("synolia_sylius_gdpr_admin_export_customer_data") +%}

{{ 'sylius.ui.admin.synolia_gdpr.customer.gdpr_title'|trans }}

{% endif %} diff --git a/src/Resources/views/Admin/layout.html.twig b/templates/Admin/layout.html.twig similarity index 100% rename from src/Resources/views/Admin/layout.html.twig rename to templates/Admin/layout.html.twig diff --git a/src/Resources/views/Gdpr/Actions.html.twig b/templates/Gdpr/Actions.html.twig similarity index 100% rename from src/Resources/views/Gdpr/Actions.html.twig rename to templates/Gdpr/Actions.html.twig diff --git a/tests/PHPUnit/Controller/ExportDataControllerTest.php b/tests/PHPUnit/Controller/ExportDataControllerTest.php index 480cb84..35fd207 100644 --- a/tests/PHPUnit/Controller/ExportDataControllerTest.php +++ b/tests/PHPUnit/Controller/ExportDataControllerTest.php @@ -36,7 +36,7 @@ public function testExportDataWithCart(): void $client->request('GET', sprintf('/admin/customers/%s', $shopUser->getId())); // export data for this user - $client->clickLink('Export data'); + $client->clickLink(self::getContainer()->get('translator')->trans('sylius.ui.admin.synolia_gdpr.customer.export_data')); $this->assertResponseIsSuccessful(); } } diff --git a/src/Resources/translations/flashes.en.yaml b/translations/flashes.en.yaml similarity index 100% rename from src/Resources/translations/flashes.en.yaml rename to translations/flashes.en.yaml diff --git a/src/Resources/translations/flashes.fr.yaml b/translations/flashes.fr.yaml similarity index 100% rename from src/Resources/translations/flashes.fr.yaml rename to translations/flashes.fr.yaml diff --git a/src/Resources/translations/messages.en.yaml b/translations/messages.en.yaml similarity index 100% rename from src/Resources/translations/messages.en.yaml rename to translations/messages.en.yaml diff --git a/src/Resources/translations/messages.fr.yaml b/translations/messages.fr.yaml similarity index 100% rename from src/Resources/translations/messages.fr.yaml rename to translations/messages.fr.yaml