diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 02265f6e9..669f6bb26 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,9 @@ on: - '[0-9]+\.[0-9]+' - development - beta + - 'fix/**' pull_request: + workflow_dispatch: env: PLUGIN_DIR: plugins/CustomObjectsBundle # Same as extra.install-directory-name in composer.json @@ -18,9 +20,9 @@ jobs: strategy: matrix: - php-versions: ['8.0'] # The supported PHP versions + php-versions: ['8.2'] # The supported PHP versions db-types: ['mysql'] # can be: ['mysql', 'mariadb'] but not necessary for this plugin that does not add any DB schema - mautic-versions: ['5.1'] # The supported Mautic versions + mautic-versions: ['6.x'] # The supported Mautic versions name: Tests on PHP ${{ matrix.php-versions }}, ${{ matrix.db-types }}, Mautic ${{ matrix.mautic-versions }} diff --git a/Command/CustomItemsScheduledExportCommand.php b/Command/CustomItemsScheduledExportCommand.php index 3212ccc15..eed35b961 100644 --- a/Command/CustomItemsScheduledExportCommand.php +++ b/Command/CustomItemsScheduledExportCommand.php @@ -21,7 +21,7 @@ class CustomItemsScheduledExportCommand extends Command public function __construct( private CustomItemExportSchedulerModel $customItemExportSchedulerModel, private EventDispatcherInterface $eventDispatcher, - private FormatterHelper $formatterHelper + private FormatterHelper $formatterHelper, ) { parent::__construct(); } diff --git a/Command/GenerateSampleDataCommand.php b/Command/GenerateSampleDataCommand.php index ceb815d44..c704f81a5 100644 --- a/Command/GenerateSampleDataCommand.php +++ b/Command/GenerateSampleDataCommand.php @@ -22,7 +22,7 @@ class GenerateSampleDataCommand extends Command public function __construct( private EntityManager $entityManager, - private RandomHelper $randomHelper + private RandomHelper $randomHelper, ) { parent::__construct(); diff --git a/Config/config.php b/Config/config.php index c5763ff08..755b4473f 100644 --- a/Config/config.php +++ b/Config/config.php @@ -635,6 +635,7 @@ 'custom_object.helper.token_formatter' => [ 'class' => MauticPlugin\CustomObjectsBundle\Helper\TokenFormatter::class, ], + 'custom_object.data_persister.custom_item' => [ 'class' => MauticPlugin\CustomObjectsBundle\DataPersister\CustomItemDataPersister::class, 'tag' => 'api_platform.data_persister', @@ -643,7 +644,7 @@ ], ], 'custom_object.helper.contact_filter_matcher' => [ - 'class' => \MauticPlugin\CustomObjectsBundle\Helper\ContactFilterMatcher::class, + 'class' => MauticPlugin\CustomObjectsBundle\Helper\ContactFilterMatcher::class, 'arguments' => [ 'mautic.custom.model.field', 'mautic.custom.model.object', diff --git a/Config/services.php b/Config/services.php index 2f7e94f21..38dcbff95 100644 --- a/Config/services.php +++ b/Config/services.php @@ -17,6 +17,8 @@ 'Report/ReportColumnsBuilder.php', 'Serializer/ApiNormalizer.php', 'Extension/CustomItemListeningExtension.php', + // Registered explicitly in config.php with a non-autowirable int argument + 'Helper/ContactFilterMatcher.php', ]; $services->load('MauticPlugin\\CustomObjectsBundle\\', '../') diff --git a/Controller/CustomField/FormController.php b/Controller/CustomField/FormController.php index cc2e8a2cd..0c552cca2 100644 --- a/Controller/CustomField/FormController.php +++ b/Controller/CustomField/FormController.php @@ -27,7 +27,7 @@ public function renderFormAction( CustomFieldPermissionProvider $permissionProvider, CustomFieldRouteProvider $fieldRouteProvider, CustomObjectModel $customObjectModel, - CustomObjectRouteProvider $objectRouteProvider + CustomObjectRouteProvider $objectRouteProvider, ): Response { $request = $this->getCurrentRequest(); $objectId = (int) $request->get('objectId'); diff --git a/Controller/CustomField/SaveController.php b/Controller/CustomField/SaveController.php index 7d91b2790..49079fc3b 100644 --- a/Controller/CustomField/SaveController.php +++ b/Controller/CustomField/SaveController.php @@ -41,7 +41,7 @@ public function saveAction( CustomFieldFactory $customFieldFactory, CustomFieldPermissionProvider $permissionProvider, CustomFieldRouteProvider $fieldRouteProvider, - CustomObjectModel $customObjectModel + CustomObjectModel $customObjectModel, ) { $request = $this->getCurrentRequest(); @@ -111,7 +111,7 @@ private function buildSuccessForm( CustomField $customField, Request $request, CustomFieldModel $customFieldModel, - FormFactoryInterface $formFactory + FormFactoryInterface $formFactory, ): JsonResponse { $panelId = is_numeric($request->get('panelId')) ? (int) $request->get('panelId') : null; // Is edit of existing panel in view diff --git a/Controller/CustomItem/BatchDeleteController.php b/Controller/CustomItem/BatchDeleteController.php index f4b41e0ca..f9b1cce7c 100644 --- a/Controller/CustomItem/BatchDeleteController.php +++ b/Controller/CustomItem/BatchDeleteController.php @@ -22,7 +22,7 @@ public function deleteAction( CustomItemPermissionProvider $permissionProvider, CustomItemRouteProvider $routeProvider, FlashBag $flashBag, - int $objectId + int $objectId, ): Response { $request = $this->getCurrentRequest(); diff --git a/Controller/CustomItem/CancelController.php b/Controller/CustomItem/CancelController.php index 49e211e38..fc5a92492 100644 --- a/Controller/CustomItem/CancelController.php +++ b/Controller/CustomItem/CancelController.php @@ -21,7 +21,7 @@ public function cancelAction( CustomItemRouteProvider $routeProvider, CustomItemModel $customItemModel, int $objectId, - ?int $itemId = null + ?int $itemId = null, ): Response { $page = $sessionProviderFactory->createItemProvider($objectId)->getPage(); diff --git a/Controller/CustomItem/ContactListController.php b/Controller/CustomItem/ContactListController.php index a1af5def4..55e9faa77 100644 --- a/Controller/CustomItem/ContactListController.php +++ b/Controller/CustomItem/ContactListController.php @@ -21,7 +21,7 @@ public function listAction( Request $request, PageHelperFactoryInterface $pageHelperFactory, int $objectId, - int $page = 1 + int $page = 1, ): Response { return $this->generateContactsGrid( $request, diff --git a/Controller/CustomItem/DeleteController.php b/Controller/CustomItem/DeleteController.php index 651f86abf..678d42745 100644 --- a/Controller/CustomItem/DeleteController.php +++ b/Controller/CustomItem/DeleteController.php @@ -23,7 +23,7 @@ public function deleteAction( CustomItemPermissionProvider $permissionProvider, CustomItemRouteProvider $routeProvider, int $objectId, - int $itemId + int $itemId, ): Response { try { $customItem = $customItemModel->fetchEntity($itemId); diff --git a/Controller/CustomItem/ExportController.php b/Controller/CustomItem/ExportController.php index 0f9a1b05e..9dc965ba7 100644 --- a/Controller/CustomItem/ExportController.php +++ b/Controller/CustomItem/ExportController.php @@ -26,7 +26,7 @@ class ExportController extends AbstractFormController public function exportAction( CustomItemPermissionProvider $permissionProvider, CustomItemExportSchedulerModel $model, - int $object + int $object, ): Response { $permissionProvider->canCreate($object); diff --git a/Controller/CustomItem/FormController.php b/Controller/CustomItem/FormController.php index 74873f61b..1622c62b9 100644 --- a/Controller/CustomItem/FormController.php +++ b/Controller/CustomItem/FormController.php @@ -25,7 +25,7 @@ public function newAction( CustomItemModel $customItemModel, CustomObjectModel $customObjectModel, CustomItemPermissionProvider $permissionProvider, - int $objectId + int $objectId, ): Response { try { $customItem = $this->performNewAction($customObjectModel, $customItemModel, $permissionProvider, $objectId); @@ -48,7 +48,7 @@ public function newWithRedirectToContactAction( CustomObjectModel $customObjectModel, CustomItemPermissionProvider $permissionProvider, int $objectId, - int $contactId + int $contactId, ): Response { try { $customItem = $this->performNewAction($customObjectModel, $customItemModel, $permissionProvider, $objectId); @@ -77,7 +77,7 @@ private function performNewAction( CustomObjectModel $customObjectModel, CustomItemModel $customItemModel, CustomItemPermissionProvider $permissionProvider, - int $objectId + int $objectId, ): CustomItem { $permissionProvider->canCreate($objectId); @@ -95,7 +95,7 @@ public function editAction( LockFlashMessageHelper $lockFlashMessageHelper, CustomItemPermissionProvider $permissionProvider, int $objectId, - int $itemId + int $itemId, ): Response { try { $customItem = $this->performEditAction($customItemModel, $permissionProvider, $itemId); @@ -134,7 +134,7 @@ public function editWithRedirectToContactAction( CustomItemPermissionProvider $permissionProvider, int $objectId, int $itemId, - int $contactId + int $contactId, ): Response { try { $customItem = $this->performEditAction($customItemModel, $permissionProvider, $itemId); @@ -180,7 +180,7 @@ public function cloneAction( CustomItemModel $customItemModel, CustomItemPermissionProvider $permissionProvider, int $objectId, - int $itemId + int $itemId, ): Response { try { $customItem = clone $customItemModel->fetchEntity($itemId); @@ -204,7 +204,7 @@ public function cloneAction( private function performEditAction( CustomItemModel $customItemModel, CustomItemPermissionProvider $permissionProvider, - int $itemId + int $itemId, ): CustomItem { $customItem = $customItemModel->fetchEntity($itemId); $permissionProvider->canEdit($customItem); @@ -217,7 +217,7 @@ private function renderFormForItem( CustomItemRouteProvider $routeProvider, CustomItem $customItem, string $route, - ?int $contactId = null + ?int $contactId = null, ): Response { $action = $routeProvider->buildSaveRoute($customItem->getCustomObject()->getId(), $customItem->getId()); $options = [ diff --git a/Controller/CustomItem/LinkController.php b/Controller/CustomItem/LinkController.php index 6b4e33607..9080db4d1 100644 --- a/Controller/CustomItem/LinkController.php +++ b/Controller/CustomItem/LinkController.php @@ -21,7 +21,7 @@ public function saveAction( FlashBag $flashBag, int $itemId, string $entityType, - int $entityId + int $entityId, ): JsonResponse { try { $customItem = $customItemModel->fetchEntity($itemId); diff --git a/Controller/CustomItem/LinkFormController.php b/Controller/CustomItem/LinkFormController.php index 0e1cb6a3a..f4cce8f80 100644 --- a/Controller/CustomItem/LinkFormController.php +++ b/Controller/CustomItem/LinkFormController.php @@ -31,7 +31,7 @@ public function formAction( FlashBag $flashBag, int $itemId, string $entityType, - int $entityId + int $entityId, ): Response { try { $customItem = $customItemModel->fetchEntity($itemId); @@ -93,7 +93,7 @@ public function saveAction( FlashBag $flashBag, int $itemId, string $entityType, - int $entityId + int $entityId, ): Response { $relationshipItem = null; $relationshipObject = null; @@ -164,7 +164,7 @@ protected function getRelationshipItem( CustomObject $relationshipObject, CustomItem $customItem, string $entityType, - int $entityId + int $entityId, ): CustomItem { /** @var CustomItemXrefCustomItem|null $relationshipItemXref */ $relationshipItemXref = $customItem->getCustomItemLowerReferences() diff --git a/Controller/CustomItem/ListController.php b/Controller/CustomItem/ListController.php index 381081f40..302b0331e 100644 --- a/Controller/CustomItem/ListController.php +++ b/Controller/CustomItem/ListController.php @@ -26,7 +26,7 @@ public function listAction( CustomItemPermissionProvider $permissionProvider, CustomItemRouteProvider $routeProvider, int $objectId, - int $page = 1 + int $page = 1, ): Response { $request = $this->getCurrentRequest(); diff --git a/Controller/CustomItem/LookupController.php b/Controller/CustomItem/LookupController.php index 38c4c813b..0b6dc7624 100644 --- a/Controller/CustomItem/LookupController.php +++ b/Controller/CustomItem/LookupController.php @@ -22,7 +22,7 @@ public function listAction( CustomItemModel $customItemModel, CustomItemPermissionProvider $permissionProvider, FlashBag $flashBag, - int $objectId + int $objectId, ): JsonResponse { try { $permissionProvider->canViewAtAll($objectId); diff --git a/Controller/CustomItem/SaveController.php b/Controller/CustomItem/SaveController.php index 0350b4800..9d0996217 100644 --- a/Controller/CustomItem/SaveController.php +++ b/Controller/CustomItem/SaveController.php @@ -30,7 +30,7 @@ public function saveAction( CustomItemRouteProvider $routeProvider, LockFlashMessageHelper $lockFlashMessageHelper, int $objectId, - ?int $itemId = null + ?int $itemId = null, ): Response { $request = $this->getCurrentRequest(); diff --git a/Controller/CustomItem/UnlinkController.php b/Controller/CustomItem/UnlinkController.php index fd0a724d5..fbbb79d6c 100644 --- a/Controller/CustomItem/UnlinkController.php +++ b/Controller/CustomItem/UnlinkController.php @@ -20,7 +20,7 @@ public function saveAction( FlashBag $flashBag, int $itemId, string $entityType, - int $entityId + int $entityId, ): JsonResponse { try { $customItem = $customItemModel->fetchEntity($itemId); diff --git a/Controller/CustomItem/ViewController.php b/Controller/CustomItem/ViewController.php index 62885f8cd..678b36dd7 100644 --- a/Controller/CustomItem/ViewController.php +++ b/Controller/CustomItem/ViewController.php @@ -26,7 +26,7 @@ public function viewAction( CustomItemPermissionProvider $permissionProvider, CustomItemRouteProvider $routeProvider, int $objectId, - int $itemId + int $itemId, ): Response { $request = $this->getCurrentRequest(); diff --git a/Controller/CustomObject/CancelController.php b/Controller/CustomObject/CancelController.php index 97798ef5d..ed5a8c59a 100644 --- a/Controller/CustomObject/CancelController.php +++ b/Controller/CustomObject/CancelController.php @@ -16,7 +16,7 @@ public function cancelAction( SessionProviderFactory $sessionProviderFactory, CustomObjectRouteProvider $routeProvider, CustomObjectModel $customObjectModel, - ?int $objectId + ?int $objectId, ): Response { $page = $sessionProviderFactory->createObjectProvider()->getPage(); diff --git a/Controller/CustomObject/DeleteController.php b/Controller/CustomObject/DeleteController.php index 4eb96c95a..1b6f4d710 100644 --- a/Controller/CustomObject/DeleteController.php +++ b/Controller/CustomObject/DeleteController.php @@ -25,7 +25,7 @@ public function deleteAction( FlashBag $flashBag, CustomObjectPermissionProvider $permissionProvider, EventDispatcherInterface $eventDispatcher, - int $objectId + int $objectId, ): Response { $controller = 'MauticPlugin\CustomObjectsBundle\Controller\CustomObject\ListController:listAction'; $page = [ diff --git a/Controller/CustomObject/FormController.php b/Controller/CustomObject/FormController.php index 581b00c1f..654f43c96 100644 --- a/Controller/CustomObject/FormController.php +++ b/Controller/CustomObject/FormController.php @@ -25,7 +25,7 @@ public function newAction( FormFactoryInterface $formFactory, CustomObjectRouteProvider $routeProvider, CustomFieldTypeProvider $customFieldTypeProvider, - CustomFieldModel $customFieldModel + CustomFieldModel $customFieldModel, ): Response { try { $permissionProvider->canCreate(); @@ -52,7 +52,7 @@ public function editAction( CustomObjectRouteProvider $routeProvider, CustomFieldTypeProvider $customFieldTypeProvider, CustomFieldModel $customFieldModel, - int $objectId + int $objectId, ): Response { try { $customObject = $customObjectModel->fetchEntity($objectId); @@ -93,7 +93,7 @@ public function cloneAction( CustomObjectRouteProvider $routeProvider, CustomFieldTypeProvider $customFieldTypeProvider, CustomFieldModel $customFieldModel, - int $objectId + int $objectId, ): Response { try { $customObject = clone $customObjectModel->fetchEntity($objectId); @@ -120,7 +120,7 @@ private function renderFormForObject( CustomFieldTypeProvider $customFieldTypeProvider, CustomFieldModel $customFieldModel, CustomObject $customObject, - string $route + string $route, ): Response { $form = $formFactory->create( CustomObjectType::class, diff --git a/Controller/CustomObject/ListController.php b/Controller/CustomObject/ListController.php index 130186518..1e144ef3d 100644 --- a/Controller/CustomObject/ListController.php +++ b/Controller/CustomObject/ListController.php @@ -22,7 +22,7 @@ public function listAction( CustomObjectModel $customObjectModel, CustomObjectPermissionProvider $permissionProvider, CustomObjectRouteProvider $routeProvider, - int $page = 1 + int $page = 1, ): Response { $request = $this->getCurrentRequest(); diff --git a/Controller/CustomObject/SaveController.php b/Controller/CustomObject/SaveController.php index 603a569c7..c0585332b 100644 --- a/Controller/CustomObject/SaveController.php +++ b/Controller/CustomObject/SaveController.php @@ -37,7 +37,7 @@ public function saveAction( ParamsToStringTransformer $paramsToStringTransformer, OptionsToStringTransformer $optionsToStringTransformer, LockFlashMessageHelper $lockFlashMessageHelper, - ?int $objectId = null + ?int $objectId = null, ): Response { $request = $this->getCurrentRequest(); @@ -133,7 +133,7 @@ private function handleRawPost( ParamsToStringTransformer $paramsToStringTransformer, OptionsToStringTransformer $optionsToStringTransformer, CustomObject $customObject, - array $rawCustomObject + array $rawCustomObject, ): void { if (empty($rawCustomObject['customFields'])) { return; diff --git a/Controller/CustomObject/ViewController.php b/Controller/CustomObject/ViewController.php index d8dd3e449..7fb22d28c 100644 --- a/Controller/CustomObject/ViewController.php +++ b/Controller/CustomObject/ViewController.php @@ -23,7 +23,7 @@ public function viewAction( AuditLogModel $auditLogModel, CustomObjectPermissionProvider $permissionProvider, CustomObjectRouteProvider $routeProvider, - int $objectId + int $objectId, ): Response { $request = $this->getCurrentRequest(); diff --git a/CustomFieldType/AbstractCustomFieldType.php b/CustomFieldType/AbstractCustomFieldType.php index 5a8b3199e..13fb995ec 100644 --- a/CustomFieldType/AbstractCustomFieldType.php +++ b/CustomFieldType/AbstractCustomFieldType.php @@ -26,7 +26,7 @@ abstract class AbstractCustomFieldType implements CustomFieldTypeInterface, \Str public function __construct( protected TranslatorInterface $translator, - protected FilterOperatorProviderInterface $filterOperatorProvider + protected FilterOperatorProviderInterface $filterOperatorProvider, ) { } diff --git a/CustomFieldType/AbstractMultivalueType.php b/CustomFieldType/AbstractMultivalueType.php index e46757d22..f8a97dc29 100644 --- a/CustomFieldType/AbstractMultivalueType.php +++ b/CustomFieldType/AbstractMultivalueType.php @@ -25,7 +25,7 @@ abstract class AbstractMultivalueType extends AbstractCustomFieldType public function __construct( TranslatorInterface $translator, FilterOperatorProviderInterface $filterOperatorProvider, - private CsvHelper $csvHelper + private CsvHelper $csvHelper, ) { parent::__construct($translator, $filterOperatorProvider); } diff --git a/DTO/TableConfig.php b/DTO/TableConfig.php index 70132dd11..be4e92a63 100644 --- a/DTO/TableConfig.php +++ b/DTO/TableConfig.php @@ -19,7 +19,7 @@ public function __construct( private int $limit, private int $page, private string $orderBy, - private string $orderDirection = 'ASC' + private string $orderDirection = 'ASC', ) { } diff --git a/Entity/CustomFieldOption.php b/Entity/CustomFieldOption.php index 59fef1510..f76e68eef 100644 --- a/Entity/CustomFieldOption.php +++ b/Entity/CustomFieldOption.php @@ -177,10 +177,6 @@ public function offsetExists(mixed $offset): bool /** * {@inheritdoc} - * - * @param mixed $offset - * - * @return mixed */ public function offsetGet(mixed $offset): mixed { diff --git a/Entity/CustomItem.php b/Entity/CustomItem.php index 99a658f9a..2decf3cab 100644 --- a/Entity/CustomItem.php +++ b/Entity/CustomItem.php @@ -188,7 +188,7 @@ public function __construct(/** * * @Groups({"custom_item:read", "custom_item:write"}) */ - private CustomObject $customObject + private CustomObject $customObject, ) { $this->customFieldValues = new ArrayCollection(); $this->contactReferences = new ArrayCollection(); diff --git a/Entity/CustomItemXrefCompany.php b/Entity/CustomItemXrefCompany.php index 8d03163f3..eeb166644 100644 --- a/Entity/CustomItemXrefCompany.php +++ b/Entity/CustomItemXrefCompany.php @@ -19,7 +19,7 @@ class CustomItemXrefCompany implements CustomItemXrefInterface public function __construct( private CustomItem $customItem, private Company $company, - ?\DateTimeInterface $dateAdded = null + ?\DateTimeInterface $dateAdded = null, ) { $this->dateAdded = $dateAdded ?: new \DateTimeImmutable('now', new \DateTimeZone('UTC')); } diff --git a/Entity/CustomItemXrefContact.php b/Entity/CustomItemXrefContact.php index 0648a0ea7..87f2368eb 100644 --- a/Entity/CustomItemXrefContact.php +++ b/Entity/CustomItemXrefContact.php @@ -20,7 +20,7 @@ class CustomItemXrefContact implements CustomItemXrefInterface public function __construct( private CustomItem $customItem, private Lead $contact, - ?\DateTimeInterface $dateAdded = null + ?\DateTimeInterface $dateAdded = null, ) { $this->dateAdded = $dateAdded ?: new \DateTimeImmutable('now', new \DateTimeZone('UTC')); } diff --git a/Event/CustomItemListQueryEvent.php b/Event/CustomItemListQueryEvent.php index 78f06e662..4d051b813 100644 --- a/Event/CustomItemListQueryEvent.php +++ b/Event/CustomItemListQueryEvent.php @@ -12,7 +12,7 @@ class CustomItemListQueryEvent extends Event { public function __construct( private QueryBuilder $queryBuilder, - private TableConfig $tableConfig + private TableConfig $tableConfig, ) { } diff --git a/Event/CustomItemXrefEntityDiscoveryEvent.php b/Event/CustomItemXrefEntityDiscoveryEvent.php index 8e6d4ce81..290375383 100644 --- a/Event/CustomItemXrefEntityDiscoveryEvent.php +++ b/Event/CustomItemXrefEntityDiscoveryEvent.php @@ -15,7 +15,7 @@ class CustomItemXrefEntityDiscoveryEvent extends Event public function __construct( private CustomItem $customItem, private string $entityType, - private int $entityId + private int $entityId, ) { } diff --git a/EventListener/ApiSubscriber.php b/EventListener/ApiSubscriber.php index 7125f145d..78c95d087 100644 --- a/EventListener/ApiSubscriber.php +++ b/EventListener/ApiSubscriber.php @@ -24,7 +24,7 @@ class ApiSubscriber implements EventSubscriberInterface public function __construct( private ConfigProvider $configProvider, private CustomObjectModel $customObjectModel, - private CustomItemModel $customItemModel + private CustomItemModel $customItemModel, ) { } diff --git a/EventListener/AssetsSubscriber.php b/EventListener/AssetsSubscriber.php index 0b5e7e264..4c80aee53 100644 --- a/EventListener/AssetsSubscriber.php +++ b/EventListener/AssetsSubscriber.php @@ -15,7 +15,7 @@ class AssetsSubscriber implements EventSubscriberInterface { public function __construct( private AssetsHelper $assetHelper, - private ConfigProvider $configProvider + private ConfigProvider $configProvider, ) { } diff --git a/EventListener/AuditLogSubscriber.php b/EventListener/AuditLogSubscriber.php index 1dc86ebc0..b2bfc9b4f 100644 --- a/EventListener/AuditLogSubscriber.php +++ b/EventListener/AuditLogSubscriber.php @@ -17,7 +17,7 @@ class AuditLogSubscriber implements EventSubscriberInterface { public function __construct( private AuditLogModel $auditLogModel, - private IpLookupHelper $ipLookupHelper + private IpLookupHelper $ipLookupHelper, ) { } diff --git a/EventListener/CampaignSubscriber.php b/EventListener/CampaignSubscriber.php index 01e437e79..369843243 100644 --- a/EventListener/CampaignSubscriber.php +++ b/EventListener/CampaignSubscriber.php @@ -45,7 +45,7 @@ public function __construct( private ConfigProvider $configProvider, private QueryFilterHelper $queryFilterHelper, private QueryFilterFactory $queryFilterFactory, - private Connection $connection + private Connection $connection, ) { } diff --git a/EventListener/ContactSubscriber.php b/EventListener/ContactSubscriber.php index 24cf17c35..495e0e876 100644 --- a/EventListener/ContactSubscriber.php +++ b/EventListener/ContactSubscriber.php @@ -27,7 +27,7 @@ public function __construct( private CustomItemRouteProvider $routeProvider, private CustomItemModel $customItemModel, private ConfigProvider $configProvider, - private CustomItemXrefContactRepository $customItemXrefContactRepository + private CustomItemXrefContactRepository $customItemXrefContactRepository, ) { } diff --git a/EventListener/ContactTabSubscriber.php b/EventListener/ContactTabSubscriber.php index d2f78f032..4edc023d1 100644 --- a/EventListener/ContactTabSubscriber.php +++ b/EventListener/ContactTabSubscriber.php @@ -29,7 +29,7 @@ public function __construct( private ConfigProvider $configProvider, private TranslatorInterface $translator, private CustomItemRouteProvider $customItemRouteProvider, - private SessionProviderFactory $sessionProviderFactory + private SessionProviderFactory $sessionProviderFactory, ) { } diff --git a/EventListener/CustomItemButtonSubscriber.php b/EventListener/CustomItemButtonSubscriber.php index 9ce55717f..5087b04b4 100644 --- a/EventListener/CustomItemButtonSubscriber.php +++ b/EventListener/CustomItemButtonSubscriber.php @@ -19,7 +19,7 @@ class CustomItemButtonSubscriber implements EventSubscriberInterface public function __construct( private CustomItemPermissionProvider $permissionProvider, private CustomItemRouteProvider $routeProvider, - private TranslatorInterface $translator + private TranslatorInterface $translator, ) { } diff --git a/EventListener/CustomItemPostDeleteSubscriber.php b/EventListener/CustomItemPostDeleteSubscriber.php index e94ec4e96..801ba6f4e 100644 --- a/EventListener/CustomItemPostDeleteSubscriber.php +++ b/EventListener/CustomItemPostDeleteSubscriber.php @@ -14,7 +14,7 @@ final class CustomItemPostDeleteSubscriber implements EventSubscriberInterface { public function __construct( private CustomItemXrefCustomItemRepository $customItemXrefCustomItemRepository, - private CustomItemXrefContactRepository $customItemXrefContactRepository + private CustomItemXrefContactRepository $customItemXrefContactRepository, ) { } diff --git a/EventListener/CustomItemPostSaveSubscriber.php b/EventListener/CustomItemPostSaveSubscriber.php index f784bd8f1..8ffc927fd 100644 --- a/EventListener/CustomItemPostSaveSubscriber.php +++ b/EventListener/CustomItemPostSaveSubscriber.php @@ -16,7 +16,7 @@ class CustomItemPostSaveSubscriber implements EventSubscriberInterface { public function __construct( private CustomItemModel $customItemModel, - private RequestStack $requestStack + private RequestStack $requestStack, ) { } diff --git a/EventListener/CustomItemTabSubscriber.php b/EventListener/CustomItemTabSubscriber.php index 18fa93fd1..f793c21f8 100644 --- a/EventListener/CustomItemTabSubscriber.php +++ b/EventListener/CustomItemTabSubscriber.php @@ -27,7 +27,7 @@ public function __construct( private CustomItemRepository $customItemRepository, private TranslatorInterface $translator, private CustomItemRouteProvider $customItemRouteProvider, - private SessionProviderFactory $sessionProviderFactory + private SessionProviderFactory $sessionProviderFactory, ) { } diff --git a/EventListener/CustomItemXrefContactSubscriber.php b/EventListener/CustomItemXrefContactSubscriber.php index b47ca0fd0..c23ba33b0 100644 --- a/EventListener/CustomItemXrefContactSubscriber.php +++ b/EventListener/CustomItemXrefContactSubscriber.php @@ -28,7 +28,7 @@ class CustomItemXrefContactSubscriber implements EventSubscriberInterface public function __construct( private EntityManager $entityManager, private UserHelper $userHelper, - private CustomItemRepository $customItemRepository + private CustomItemRepository $customItemRepository, ) { } diff --git a/EventListener/CustomItemXrefCustomItemSubscriber.php b/EventListener/CustomItemXrefCustomItemSubscriber.php index cfefa82ae..805e93b38 100644 --- a/EventListener/CustomItemXrefCustomItemSubscriber.php +++ b/EventListener/CustomItemXrefCustomItemSubscriber.php @@ -22,7 +22,7 @@ class CustomItemXrefCustomItemSubscriber implements EventSubscriberInterface { public function __construct( private EntityManager $entityManager, - private CustomItemRepository $customItemRepository + private CustomItemRepository $customItemRepository, ) { } diff --git a/EventListener/CustomObjectButtonSubscriber.php b/EventListener/CustomObjectButtonSubscriber.php index 1e68d13c3..f2b231a75 100644 --- a/EventListener/CustomObjectButtonSubscriber.php +++ b/EventListener/CustomObjectButtonSubscriber.php @@ -23,7 +23,7 @@ public function __construct( private CustomObjectRouteProvider $routeProvider, private CustomItemPermissionProvider $customItemPermissionProvider, private CustomItemRouteProvider $customItemRouteProvider, - private TranslatorInterface $translator + private TranslatorInterface $translator, ) { } diff --git a/EventListener/CustomObjectPreDeleteSubscriber.php b/EventListener/CustomObjectPreDeleteSubscriber.php index f711b251e..a33899a7b 100644 --- a/EventListener/CustomObjectPreDeleteSubscriber.php +++ b/EventListener/CustomObjectPreDeleteSubscriber.php @@ -14,7 +14,7 @@ class CustomObjectPreDeleteSubscriber implements EventSubscriberInterface { public function __construct( private CustomObjectModel $customObjectModel, - private TranslatorInterface $translator + private TranslatorInterface $translator, ) { } diff --git a/EventListener/DynamicContentSubscriber.php b/EventListener/DynamicContentSubscriber.php index e72fa4bd3..a2bd8839e 100644 --- a/EventListener/DynamicContentSubscriber.php +++ b/EventListener/DynamicContentSubscriber.php @@ -58,7 +58,7 @@ private function hasCustomObjectFilters(array $filters): bool $this->queryFilterFactory->configureQueryBuilderFromSegmentFilter($filter, 'filter'); return true; - } catch (InvalidSegmentFilterException $e) { + } catch (InvalidSegmentFilterException) { } } diff --git a/EventListener/ImportSubscriber.php b/EventListener/ImportSubscriber.php index 51bf22026..5fc280b9a 100644 --- a/EventListener/ImportSubscriber.php +++ b/EventListener/ImportSubscriber.php @@ -33,7 +33,7 @@ public function __construct( private ConfigProvider $configProvider, private CustomItemPermissionProvider $permissionProvider, private CustomFieldRepository $customFieldRepository, - private TranslatorInterface $translator + private TranslatorInterface $translator, ) { } diff --git a/EventListener/ReportSubscriber.php b/EventListener/ReportSubscriber.php index 80229bfff..e9133393f 100644 --- a/EventListener/ReportSubscriber.php +++ b/EventListener/ReportSubscriber.php @@ -42,7 +42,7 @@ public function __construct( private FieldsBuilder $fieldsBuilder, private CompanyReportData $companyReportData, private ReportHelper $reportHelper, - private TranslatorInterface $translator + private TranslatorInterface $translator, ) { } diff --git a/EventListener/SegmentFiltersChoicesGenerateSubscriber.php b/EventListener/SegmentFiltersChoicesGenerateSubscriber.php index 66d26dda3..881630909 100644 --- a/EventListener/SegmentFiltersChoicesGenerateSubscriber.php +++ b/EventListener/SegmentFiltersChoicesGenerateSubscriber.php @@ -32,7 +32,7 @@ public function __construct( TranslatorInterface $translator, private ConfigProvider $configProvider, private CustomFieldTypeProvider $fieldTypeProvider, - private TypeOperatorProviderInterface $typeOperatorProvider + private TypeOperatorProviderInterface $typeOperatorProvider, ) { $this->translator = $translator; } diff --git a/EventListener/SegmentFiltersDictionarySubscriber.php b/EventListener/SegmentFiltersDictionarySubscriber.php index 12b2b4a7c..dccbab32c 100644 --- a/EventListener/SegmentFiltersDictionarySubscriber.php +++ b/EventListener/SegmentFiltersDictionarySubscriber.php @@ -23,7 +23,7 @@ class SegmentFiltersDictionarySubscriber implements EventSubscriberInterface public function __construct( private ManagerRegistry $doctrineRegistry, - private ConfigProvider $configProvider + private ConfigProvider $configProvider, ) { } diff --git a/EventListener/SerializerSubscriber.php b/EventListener/SerializerSubscriber.php index fcd3e130d..be1cb0b50 100644 --- a/EventListener/SerializerSubscriber.php +++ b/EventListener/SerializerSubscriber.php @@ -27,7 +27,7 @@ public function __construct( private ConfigProvider $configProvider, private CustomItemXrefContactRepository $customItemXrefContactRepository, private CustomItemModel $customItemModel, - private RequestStack $requestStack + private RequestStack $requestStack, ) { } diff --git a/EventListener/TokenSubscriber.php b/EventListener/TokenSubscriber.php index 63ea1f54e..089ff6859 100644 --- a/EventListener/TokenSubscriber.php +++ b/EventListener/TokenSubscriber.php @@ -25,7 +25,6 @@ use MauticPlugin\CustomObjectsBundle\Exception\InvalidCustomObjectFormatListException; use MauticPlugin\CustomObjectsBundle\Exception\InvalidSegmentFilterException; use MauticPlugin\CustomObjectsBundle\Exception\NotFoundException; -use MauticPlugin\CustomObjectsBundle\Helper\ContactFilterMatcher; use MauticPlugin\CustomObjectsBundle\Helper\QueryBuilderManipulatorTrait; use MauticPlugin\CustomObjectsBundle\Helper\QueryFilterHelper; use MauticPlugin\CustomObjectsBundle\Helper\TokenFormatter; @@ -55,7 +54,7 @@ public function __construct( private EventModel $eventModel, private EventDispatcherInterface $eventDispatcher, private TokenFormatter $tokenFormatter, - private int $leadCustomItemFetchLimit + private int $leadCustomItemFetchLimit, ) { } @@ -355,7 +354,7 @@ private function getCustomFieldDataForLead(array $filters, string $leadId): arra private function getCustomFieldValue( CustomObject $customObject, string $customFieldAlias, - array $customItems + array $customItems, ): array { $fieldValues = []; diff --git a/Exception/ForbiddenException.php b/Exception/ForbiddenException.php index d0ddb1bd5..77faca8bb 100644 --- a/Exception/ForbiddenException.php +++ b/Exception/ForbiddenException.php @@ -11,7 +11,7 @@ public function __construct( ?string $entityType = null, ?int $entityId = null, int $code = 403, - ?\Throwable $throwable = null + ?\Throwable $throwable = null, ) { parent::__construct( trim("You do not have permission to {$permission} {$entityType} {$entityId}"), diff --git a/Exception/NoRelationshipException.php b/Exception/NoRelationshipException.php index 51dc8d76f..550576219 100644 --- a/Exception/NoRelationshipException.php +++ b/Exception/NoRelationshipException.php @@ -8,7 +8,7 @@ class NoRelationshipException extends \Exception { public function __construct( int $code = 403, - ?\Throwable $throwable = null + ?\Throwable $throwable = null, ) { parent::__construct( 'This custom object does not have relationship fields defined.', diff --git a/Exception/NotFoundException.php b/Exception/NotFoundException.php index 1961082db..eebf046d5 100644 --- a/Exception/NotFoundException.php +++ b/Exception/NotFoundException.php @@ -9,7 +9,7 @@ class NotFoundException extends \Exception public function __construct( string $message = 'Not found', int $code = 404, - ?\Throwable $throwable = null + ?\Throwable $throwable = null, ) { parent::__construct($message, $code, $throwable); } diff --git a/Extension/CustomItemListeningExtension.php b/Extension/CustomItemListeningExtension.php index 289074ada..e8cc0be50 100644 --- a/Extension/CustomItemListeningExtension.php +++ b/Extension/CustomItemListeningExtension.php @@ -25,7 +25,7 @@ public function applyToCollection( QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, - string $operationName = null + string $operationName = null, ): void { if (CustomItem::class !== $resourceClass) { return; diff --git a/Form/Type/CampaignActionLinkType.php b/Form/Type/CampaignActionLinkType.php index 5021dce64..65d5d8cee 100644 --- a/Form/Type/CampaignActionLinkType.php +++ b/Form/Type/CampaignActionLinkType.php @@ -16,7 +16,7 @@ class CampaignActionLinkType extends AbstractType { public function __construct( protected CustomItemRouteProvider $routeProvider, - protected TranslatorInterface $translator + protected TranslatorInterface $translator, ) { } diff --git a/Form/Type/CampaignConditionFieldValueType.php b/Form/Type/CampaignConditionFieldValueType.php index 87da53a87..ed59b65df 100644 --- a/Form/Type/CampaignConditionFieldValueType.php +++ b/Form/Type/CampaignConditionFieldValueType.php @@ -21,7 +21,7 @@ public function __construct( protected CustomFieldModel $customFieldModel, private CustomObjectModel $customObjectModel, protected CustomItemRouteProvider $routeProvider, - protected TranslatorInterface $translator + protected TranslatorInterface $translator, ) { } diff --git a/Form/Type/CustomFieldType.php b/Form/Type/CustomFieldType.php index 765abbdf3..0b4e13627 100644 --- a/Form/Type/CustomFieldType.php +++ b/Form/Type/CustomFieldType.php @@ -33,7 +33,7 @@ public function __construct( private CustomFieldTypeProvider $customFieldTypeProvider, private ParamsToStringTransformer $paramsToStringTransformer, private OptionsToStringTransformer $optionsToStringTransformer, - private CustomFieldFactory $customFieldFactory + private CustomFieldFactory $customFieldFactory, ) { } diff --git a/Form/Type/CustomObjectType.php b/Form/Type/CustomObjectType.php index b5a991662..dc89063e5 100644 --- a/Form/Type/CustomObjectType.php +++ b/Form/Type/CustomObjectType.php @@ -29,7 +29,7 @@ class CustomObjectType extends AbstractType public function __construct( private EntityManager $entityManager, private CustomFieldTypeProvider $customFieldTypeProvider, - private CustomObjectRepository $customObjectRepository + private CustomObjectRepository $customObjectRepository, ) { } diff --git a/Helper/ContactFilterMatcher.php b/Helper/ContactFilterMatcher.php index 28ab162bb..f307a247b 100644 --- a/Helper/ContactFilterMatcher.php +++ b/Helper/ContactFilterMatcher.php @@ -5,7 +5,6 @@ namespace MauticPlugin\CustomObjectsBundle\Helper; use Doctrine\DBAL\Connection; -use Mautic\EmailBundle\EventListener\MatchFilterForLeadTrait; use Mautic\LeadBundle\Entity\CompanyRepository; use Mautic\LeadBundle\Entity\LeadListRepository; use MauticPlugin\CustomObjectsBundle\DTO\TableConfig; @@ -17,42 +16,25 @@ use MauticPlugin\CustomObjectsBundle\Model\CustomItemModel; use MauticPlugin\CustomObjectsBundle\Model\CustomObjectModel; use MauticPlugin\CustomObjectsBundle\Polyfill\EventListener\MatchFilterForLeadTrait as MatchFilterForLeadTraitPolyfill; - -if (method_exists(MatchFilterForLeadTrait::class, 'transformFilterDataForLead')) { - class_alias(MatchFilterForLeadTrait::class, '\MauticPlugin\CustomObjectsBundle\Helper\MatchFilterForLeadTraitAlias'); -} else { - class_alias(MatchFilterForLeadTraitPolyfill::class, '\MauticPlugin\CustomObjectsBundle\Helper\MatchFilterForLeadTraitAlias'); -} +use Symfony\Component\DependencyInjection\Attribute\Autowire; class ContactFilterMatcher { - use MatchFilterForLeadTraitAlias { - transformFilterDataForLead as transformFilterDataForLeadAlias; + use MatchFilterForLeadTraitPolyfill { + transformFilterDataForLead as transformFilterDataForLeadPolyfill; } - private CustomFieldModel $customFieldModel; - private CustomObjectModel $customObjectModel; - private CustomItemModel $customItemModel; - private CompanyRepository $companyRepository; - private Connection $connection; - private int $leadCustomItemFetchLimit; - public function __construct( - CustomFieldModel $customFieldModel, - CustomObjectModel $customObjectModel, - CustomItemModel $customItemModel, + private CustomFieldModel $customFieldModel, + private CustomObjectModel $customObjectModel, + private CustomItemModel $customItemModel, LeadListRepository $segmentRepository, - CompanyRepository $companyRepository, - Connection $connection, - int $leadCustomItemFetchLimit + private CompanyRepository $companyRepository, + private Connection $connection, + #[Autowire(param: 'mautic.custom_item_fetch_limit_per_lead')] + private int $leadCustomItemFetchLimit, ) { - $this->customFieldModel = $customFieldModel; - $this->customObjectModel = $customObjectModel; - $this->customItemModel = $customItemModel; - $this->segmentRepository = $segmentRepository; - $this->companyRepository = $companyRepository; - $this->connection = $connection; - $this->leadCustomItemFetchLimit = $leadCustomItemFetchLimit; + $this->segmentRepository = $segmentRepository; } /** @@ -97,13 +79,13 @@ private function getCustomFieldDataForLead(array $filters, string $leadId): arra continue; } - if ('cmf_' === substr($condition['field'], 0, 4)) { + if (str_starts_with($condition['field'], 'cmf_')) { $customField = $this->customFieldModel->fetchEntity( (int) explode('cmf_', $condition['field'])[1] ); $customObject = $customField->getCustomObject(); $fieldAlias = $customField->getAlias(); - } elseif ('cmo_' === substr($condition['field'], 0, 4)) { + } elseif (str_starts_with($condition['field'], 'cmo_')) { $customObject = $this->customObjectModel->fetchEntity( (int) explode('cmo_', $condition['field'])[1] ); @@ -120,7 +102,7 @@ private function getCustomFieldDataForLead(array $filters, string $leadId): arra $result = $this->getCustomFieldValue($customObject, $fieldAlias, $cachedCustomItems[$key]); $customFieldValues[$condition['field']] = $result; - } catch (NotFoundException|InvalidCustomObjectFormatListException $e) { + } catch (NotFoundException|InvalidCustomObjectFormatListException) { continue; } } @@ -136,7 +118,7 @@ private function getCustomFieldDataForLead(array $filters, string $leadId): arra private function getCustomFieldValue( CustomObject $customObject, string $customFieldAlias, - array $customItems + array $customItems, ): array { $fieldValues = []; @@ -165,7 +147,7 @@ private function getCustomFieldValue( } else { $fieldValues[] = $fieldValue->getCustomField()->getTypeObject()->valueToString($fieldValue); } - } catch (NotFoundException $e) { + } catch (NotFoundException) { // Custom field not found. } } @@ -192,8 +174,6 @@ private function getCustomItems(CustomObject $customObject, string $leadId): arr /** * @param mixed[] $data * @param mixed[] $lead - * - * @return ?mixed[] */ private function transformFilterDataForLead(array $data, array $lead): ?array { @@ -201,7 +181,7 @@ private function transformFilterDataForLead(array $data, array $lead): ?array return $lead[$data['field']]; } - return $this->transformFilterDataForLeadAlias($data, $lead); + return $this->transformFilterDataForLeadPolyfill($data, $lead); } /** @@ -214,7 +194,7 @@ public function getTagIdsByLeadId(string $leadId): array ->from(MAUTIC_TABLE_PREFIX.'lead_tags_xref', 'x') ->where('x.lead_id = :leadId') ->setParameter('leadId', $leadId) - ->execute() + ->executeQuery() ->fetchFirstColumn(); } } diff --git a/Helper/LockFlashMessageHelper.php b/Helper/LockFlashMessageHelper.php index 322f34dad..c1231e20c 100644 --- a/Helper/LockFlashMessageHelper.php +++ b/Helper/LockFlashMessageHelper.php @@ -15,7 +15,7 @@ public function __construct( private CoreParametersHelper $coreParametersHelper, private TranslatorInterface $translator, private FlashBag $flashBag, - private Router $router + private Router $router, ) { } diff --git a/Helper/QueryFilterFactory.php b/Helper/QueryFilterFactory.php index 89f4a20fc..739805626 100644 --- a/Helper/QueryFilterFactory.php +++ b/Helper/QueryFilterFactory.php @@ -21,13 +21,13 @@ public function __construct( private CustomFieldTypeProvider $fieldTypeProvider, private CustomFieldRepository $customFieldRepository, private Calculator $calculator, - private int $itemRelationLevelLimit + private int $itemRelationLevelLimit, ) { } public function createQuery( string $alias, - ContactSegmentFilter $segmentFilter + ContactSegmentFilter $segmentFilter, ): UnionQueryContainer { $segmentFilterFieldId = (int) $segmentFilter->getField(); $segmentFilterFieldType = $segmentFilter->getType(); diff --git a/Helper/QueryFilterHelper.php b/Helper/QueryFilterHelper.php index d5ba3d24c..bf9309430 100644 --- a/Helper/QueryFilterHelper.php +++ b/Helper/QueryFilterHelper.php @@ -21,14 +21,14 @@ class QueryFilterHelper public function __construct( private EntityManager $entityManager, private QueryFilterFactory $queryFilterFactory, - private RandomParameterName $randomParameterNameService + private RandomParameterName $randomParameterNameService, ) { } public function createValueQuery( string $alias, ContactSegmentFilter $segmentFilter, - bool $filterAlreadyNegated = false + bool $filterAlreadyNegated = false, ): UnionQueryContainer { $unionQueryContainer = $this->queryFilterFactory->createQuery($alias, $segmentFilter); $this->addCustomFieldValueExpressionFromSegmentFilter($unionQueryContainer, $alias, $segmentFilter, $filterAlreadyNegated); @@ -69,7 +69,7 @@ public function addCustomFieldValueExpressionFromSegmentFilter( UnionQueryContainer $unionQueryContainer, string $tableAlias, ContactSegmentFilter $filter, - bool $filterAlreadyNegated = false + bool $filterAlreadyNegated = false, ): void { $filterValue = $filter->getParameterValue(); foreach ($unionQueryContainer as $segmentQueryBuilder) { @@ -97,7 +97,7 @@ public function addCustomObjectNameExpression( SegmentQueryBuilder $queryBuilder, string $tableAlias, string $operator, - ?string $value + ?string $value, ): void { $valueParameter = $this->randomParameterNameService->generateRandomParameterName(); $expression = $this->getCustomObjectNameExpression($queryBuilder, $tableAlias, $operator, $valueParameter); @@ -113,7 +113,7 @@ private function addOperatorExpression( $expression, string $operator, $value, - string $valueParameter + string $valueParameter, ): void { $valueType = null; @@ -154,7 +154,7 @@ private function getCustomValueValueExpression( ContactSegmentFilter $filter, string $valueParameter, bool $alreadyNegated = false, - $filterParameterValue = null + $filterParameterValue = null, ) { $operator = $filter->getOperator(); if ($alreadyNegated) { @@ -254,7 +254,7 @@ private function getCustomObjectNameExpression( SegmentQueryBuilder $customQuery, string $tableAlias, string $operator, - string $valueParameter + string $valueParameter, ) { return match ($operator) { 'empty' => $customQuery->expr()->or( @@ -318,7 +318,7 @@ private function getBasicItemQueryBuilder(SegmentQueryBuilder $queryBuilder, str public function createMergeFilterQuery( ContactSegmentFilter $segmentFilter, - string $leadsTableAlias + string $leadsTableAlias, ): SegmentQueryBuilder { $customItemXrefContactAlias = 'cix'; $qb = new SegmentQueryBuilder($this->entityManager->getConnection()); @@ -380,7 +380,7 @@ private function joinMergeCustomItem( SegmentQueryBuilder $qb, string $customItemXrefContactAlias, string $cinAliasItem, - int $segmentFilterFieldId + int $segmentFilterFieldId, ): void { $qb->leftJoin( $customItemXrefContactAlias, @@ -396,7 +396,7 @@ private function joinMergeCustomField( string $customItemXrefContactAlias, string $dataTable, string $aliasValue, - int $segmentFilterFieldId + int $segmentFilterFieldId, ): void { $qb->innerJoin( $customItemXrefContactAlias, @@ -418,7 +418,7 @@ private function getMergeExpression( string $cinAlias, string $alias, ContactSegmentFilter $filter, - string $valueParameter + string $valueParameter, ) { $segmentFilterFieldOperator = $filter->getOperator(); if ($isCmoFilter) { diff --git a/Model/CustomFieldOptionModel.php b/Model/CustomFieldOptionModel.php index c259bfcab..1f3349233 100644 --- a/Model/CustomFieldOptionModel.php +++ b/Model/CustomFieldOptionModel.php @@ -9,7 +9,7 @@ class CustomFieldOptionModel { public function __construct( - private EntityManager $entityManager + private EntityManager $entityManager, ) { } diff --git a/Model/CustomFieldValueModel.php b/Model/CustomFieldValueModel.php index 1bc2325b7..58ed81592 100644 --- a/Model/CustomFieldValueModel.php +++ b/Model/CustomFieldValueModel.php @@ -20,7 +20,7 @@ class CustomFieldValueModel { public function __construct( private EntityManager $entityManager, - private ValidatorInterface $validator + private ValidatorInterface $validator, ) { } diff --git a/Model/CustomItemXrefContactModel.php b/Model/CustomItemXrefContactModel.php index 9ae36f3a2..c1af9430b 100644 --- a/Model/CustomItemXrefContactModel.php +++ b/Model/CustomItemXrefContactModel.php @@ -17,7 +17,7 @@ class CustomItemXrefContactModel extends FormModel public function getLinksLineChartData( \DateTime $from, \DateTime $to, - CustomItem $customItem + CustomItem $customItem, ): array { $chart = new LineChart(null, $from, $to); $query = new ChartQuery($this->em->getConnection(), $from, $to); diff --git a/Polyfill/EventListener/MatchFilterForLeadTrait.php b/Polyfill/EventListener/MatchFilterForLeadTrait.php index 19304737e..269e4bb42 100644 --- a/Polyfill/EventListener/MatchFilterForLeadTrait.php +++ b/Polyfill/EventListener/MatchFilterForLeadTrait.php @@ -67,6 +67,12 @@ protected function matchFilterForLead(array $filter, array $lead): bool $subgroup = null; if (is_array($leadValues)) { + if ('custom_object' === $data['object'] && [] === $leadValues) { + // No custom items linked to this contact: only 'empty' is true. + $groups[$groupNum] = 'empty' === $data['operator']; + continue; + } + foreach ($leadValues as $leadVal) { if ($subgroup) { break; @@ -164,14 +170,14 @@ protected function matchFilterForLead(array $filter, array $lead): bool $groups[$groupNum] = 1 !== preg_match('/'.$filterVal.'/i', $leadVal); break; case 'startsWith': - $groups[$groupNum] = 0 === strncmp($leadVal, $filterVal, strlen($filterVal)); + $groups[$groupNum] = str_starts_with($leadVal, $filterVal); break; case 'endsWith': $endOfString = substr($leadVal, strlen($leadVal) - strlen($filterVal)); $groups[$groupNum] = 0 === strcmp($endOfString, $filterVal); break; case 'contains': - $groups[$groupNum] = false !== strpos((string) $leadVal, (string) $filterVal); + $groups[$groupNum] = str_contains((string) $leadVal, (string) $filterVal); break; default: throw new OperatorsNotFoundException('Operator is not defined or invalid operator found.'); @@ -188,8 +194,6 @@ protected function matchFilterForLead(array $filter, array $lead): bool /** * @param mixed[] $data * @param mixed[] $lead - * - * @return ?mixed[] */ private function transformFilterDataForLead(array $data, array $lead): ?array { @@ -208,7 +212,7 @@ private function doFiltersContainCompanyFilter(array $filters): bool return true; } - if ((0 === strpos($filter['field'], 'company') && 'company' !== $filter['field'])) { + if (str_starts_with($filter['field'], 'company') && 'company' !== $filter['field']) { return true; } } diff --git a/Security/Permissions/CustomObjectPermissions.php b/Security/Permissions/CustomObjectPermissions.php index 9c4b1f50e..59779fe67 100644 --- a/Security/Permissions/CustomObjectPermissions.php +++ b/Security/Permissions/CustomObjectPermissions.php @@ -27,7 +27,7 @@ public function __construct( CoreParametersHelper $coreParametersHelper, private CustomObjectModel $customObjectModel, private ConfigProvider $configProvider, - private TranslatorInterface $translator + private TranslatorInterface $translator, ) { parent::__construct($coreParametersHelper->all()); } diff --git a/Segment/Query/Filter/CustomFieldFilterQueryBuilder.php b/Segment/Query/Filter/CustomFieldFilterQueryBuilder.php index 54cdbf167..11db52f39 100644 --- a/Segment/Query/Filter/CustomFieldFilterQueryBuilder.php +++ b/Segment/Query/Filter/CustomFieldFilterQueryBuilder.php @@ -17,7 +17,7 @@ class CustomFieldFilterQueryBuilder extends BaseFilterQueryBuilder public function __construct( RandomParameterName $randomParameterNameService, EventDispatcherInterface $dispatcher, - private QueryFilterHelper $filterHelper + private QueryFilterHelper $filterHelper, ) { parent::__construct($randomParameterNameService, $dispatcher); } diff --git a/Segment/Query/Filter/CustomItemNameFilterQueryBuilder.php b/Segment/Query/Filter/CustomItemNameFilterQueryBuilder.php index d8c184d1f..c1cd3475c 100644 --- a/Segment/Query/Filter/CustomItemNameFilterQueryBuilder.php +++ b/Segment/Query/Filter/CustomItemNameFilterQueryBuilder.php @@ -20,7 +20,7 @@ class CustomItemNameFilterQueryBuilder extends BaseFilterQueryBuilder public function __construct( RandomParameterName $randomParameterNameService, private QueryFilterHelper $filterHelper, - EventDispatcherInterface $dispatcher + EventDispatcherInterface $dispatcher, ) { parent::__construct($randomParameterNameService, $dispatcher); } diff --git a/Segment/Query/Filter/CustomObjectMergedFilterQueryBuilder.php b/Segment/Query/Filter/CustomObjectMergedFilterQueryBuilder.php index 04161419e..a4374d289 100644 --- a/Segment/Query/Filter/CustomObjectMergedFilterQueryBuilder.php +++ b/Segment/Query/Filter/CustomObjectMergedFilterQueryBuilder.php @@ -16,7 +16,7 @@ class CustomObjectMergedFilterQueryBuilder extends BaseFilterQueryBuilder public function __construct( RandomParameterName $randomParameterNameService, EventDispatcherInterface $dispatcher, - private QueryFilterHelper $queryFilterHelper + private QueryFilterHelper $queryFilterHelper, ) { parent::__construct($randomParameterNameService, $dispatcher); } diff --git a/Segment/Query/Filter/QueryFilterFactory.php b/Segment/Query/Filter/QueryFilterFactory.php index 7a1ef0458..451966e08 100644 --- a/Segment/Query/Filter/QueryFilterFactory.php +++ b/Segment/Query/Filter/QueryFilterFactory.php @@ -15,7 +15,7 @@ class QueryFilterFactory { public function __construct( private ContactSegmentFilterFactory $contactSegmentFilterFactory, - private QueryFilterHelper $queryFilterHelper + private QueryFilterHelper $queryFilterHelper, ) { } diff --git a/Tests/Functional/ApiPlatform/CustomFieldFunctionalTest.php b/Tests/Functional/ApiPlatform/CustomFieldFunctionalTest.php index 5d6a8f24b..322d3fab2 100644 --- a/Tests/Functional/ApiPlatform/CustomFieldFunctionalTest.php +++ b/Tests/Functional/ApiPlatform/CustomFieldFunctionalTest.php @@ -24,7 +24,7 @@ private function runTestCustomFieldCRUD( ?string $retrievedLabel, string $httpUpdated, ?string $updatedLabel, - string $httpDeleted + string $httpDeleted, ): void { // USER $user = $this->getUser(); @@ -177,7 +177,7 @@ private function runTestCustomFieldWithOptionsCRUD( ?int $updatedOptionsCount, ?array $updatedOptions, ?string $updatedDeafaultValue, - string $httpDeleted + string $httpDeleted, ): void { // USER $user = $this->getUser(); diff --git a/Tests/Functional/ApiPlatform/CustomFieldOptionFunctionalTest.php b/Tests/Functional/ApiPlatform/CustomFieldOptionFunctionalTest.php index daea1f0b4..a12b7f4bd 100644 --- a/Tests/Functional/ApiPlatform/CustomFieldOptionFunctionalTest.php +++ b/Tests/Functional/ApiPlatform/CustomFieldOptionFunctionalTest.php @@ -30,7 +30,7 @@ private function runTestCustomFieldOptionCRUD( ?string $retrievedLabel, string $httpUpdated, ?string $updatedLabel, - string $httpDeleted + string $httpDeleted, ): void { // USER $user = $this->getUser(); diff --git a/Tests/Functional/ApiPlatform/CustomObjectFunctionalTest.php b/Tests/Functional/ApiPlatform/CustomObjectFunctionalTest.php index 2560e189a..4060134d4 100644 --- a/Tests/Functional/ApiPlatform/CustomObjectFunctionalTest.php +++ b/Tests/Functional/ApiPlatform/CustomObjectFunctionalTest.php @@ -23,7 +23,7 @@ public function runTestCustomObjectCRUD( ?string $retrievedAlias, string $httpUpdated, ?string $updatedAlias, - string $httpDeleted + string $httpDeleted, ): void { $user = $this->getUser(); $this->setPermission($user, 'custom_objects:custom_objects', $permissions); diff --git a/Tests/Functional/EventListener/CampaignConditionTest.php b/Tests/Functional/EventListener/CampaignConditionTest.php index dd464be5e..c0b43b12e 100644 --- a/Tests/Functional/EventListener/CampaignConditionTest.php +++ b/Tests/Functional/EventListener/CampaignConditionTest.php @@ -26,7 +26,7 @@ protected function setUp(): void static::getContainer()->set( 'session', new Session( - new class() extends FixedMockFileSessionStorage { + new class extends FixedMockFileSessionStorage { } ) ); diff --git a/Tests/Functional/EventListener/CampaignSubscriberTest.php b/Tests/Functional/EventListener/CampaignSubscriberTest.php index d756c28a8..e9f7f4e6f 100644 --- a/Tests/Functional/EventListener/CampaignSubscriberTest.php +++ b/Tests/Functional/EventListener/CampaignSubscriberTest.php @@ -289,7 +289,7 @@ private function createCampaignExecutionEvent( Lead $contact, int $fieldId, string $operator, - $fieldValue = null + $fieldValue = null, ): CampaignExecutionEvent { return new CampaignExecutionEvent( [ diff --git a/Tests/Functional/EventListener/DynamicContentSubscriberTest.php b/Tests/Functional/EventListener/DynamicContentSubscriberTest.php index e6e5ba46f..dbd338f1e 100644 --- a/Tests/Functional/EventListener/DynamicContentSubscriberTest.php +++ b/Tests/Functional/EventListener/DynamicContentSubscriberTest.php @@ -83,6 +83,7 @@ public function filtersDataProvider(): iterable /** * @param mixed[] $filters + * * @dataProvider filtersDataProvider */ public function testCustomObjectFiltersAreFollowedWhenEmailIsSent(bool $shouldMatch, array $filters): void @@ -126,6 +127,7 @@ public function testCustomObjectFiltersAreFollowedWhenEmailIsSent(bool $shouldMa /** * @param mixed[] $filters + * * @dataProvider filtersDataProvider */ public function testCustomObjectFiltersAreFollowedInPagePreview(bool $shouldMatch, array $filters): void diff --git a/Tests/Functional/Segment/Query/Filter/CustomFieldFilterQueryBuilderTest.php b/Tests/Functional/Segment/Query/Filter/CustomFieldFilterQueryBuilderTest.php index f94a020d5..507881584 100644 --- a/Tests/Functional/Segment/Query/Filter/CustomFieldFilterQueryBuilderTest.php +++ b/Tests/Functional/Segment/Query/Filter/CustomFieldFilterQueryBuilderTest.php @@ -94,7 +94,7 @@ private function createSegmentFilterMock( $value, string $type = 'text', string $operator = 'eq', - string $fixtureField = 'custom_field1' + string $fixtureField = 'custom_field1', ): MockObject { $filterMock = $this->getMockBuilder(ContactSegmentFilter::class) ->disableOriginalConstructor() diff --git a/Tests/Unit/Controller/CustomField/AbstractFieldControllerTest.php b/Tests/Unit/Controller/CustomField/AbstractFieldControllerTest.php index 533cfb927..a01f346bf 100644 --- a/Tests/Unit/Controller/CustomField/AbstractFieldControllerTest.php +++ b/Tests/Unit/Controller/CustomField/AbstractFieldControllerTest.php @@ -17,7 +17,7 @@ protected function createRequestStackMock( $fieldType = null, $panelId = null, $panelCount = null, - array $mapExtras = [] + array $mapExtras = [], ): RequestStack { $request = $this->createMock(Request::class); diff --git a/Tests/Unit/Controller/CustomField/FormControllerTest.php b/Tests/Unit/Controller/CustomField/FormControllerTest.php index 4c051a028..e2907e82d 100644 --- a/Tests/Unit/Controller/CustomField/FormControllerTest.php +++ b/Tests/Unit/Controller/CustomField/FormControllerTest.php @@ -329,7 +329,7 @@ private function createFormController( ?int $fieldId, string $fieldType, ?int $panelId = null, - ?int $panelCount = null + ?int $panelCount = null, ): void { $this->requestStack = $this->createRequestStackMock( $objectId, diff --git a/Tests/Unit/Controller/CustomField/SaveControllerTest.php b/Tests/Unit/Controller/CustomField/SaveControllerTest.php index 797805c64..5847a7876 100644 --- a/Tests/Unit/Controller/CustomField/SaveControllerTest.php +++ b/Tests/Unit/Controller/CustomField/SaveControllerTest.php @@ -398,7 +398,7 @@ private function createSaveController( string $fieldType, ?int $panelId = null, ?int $panelCount = null, - array $mapExtras = [] + array $mapExtras = [], ): void { $this->requestStack = $this->createRequestStackMock( $objectId, diff --git a/Tests/Unit/Controller/CustomItem/FormControllerTest.php b/Tests/Unit/Controller/CustomItem/FormControllerTest.php index 357ef542e..2d0bb9ec1 100644 --- a/Tests/Unit/Controller/CustomItem/FormControllerTest.php +++ b/Tests/Unit/Controller/CustomItem/FormControllerTest.php @@ -232,7 +232,7 @@ public function testNewAction(): void public function testNewWithRedirectToContactAction(): void { - $customObject = new class() extends CustomObject { + $customObject = new class extends CustomObject { public function getId() { return FormControllerTest::OBJECT_ID; @@ -281,7 +281,7 @@ public function getId(): int public function testNewWithRedirectToContactActionWithChildObject(): void { - $customObject = new class() extends CustomObject { + $customObject = new class extends CustomObject { public function getId() { return FormControllerTest::OBJECT_ID; @@ -289,7 +289,7 @@ public function getId() public function getRelationshipObject(): CustomObject { - return new class() extends CustomObject { + return new class extends CustomObject { public function getId() { return 555; @@ -450,7 +450,7 @@ public function testEditAction(): void public function testEditWithRedirectToContactAction(): void { - $customObject = new class() extends CustomObject { + $customObject = new class extends CustomObject { public function getId() { return FormControllerTest::OBJECT_ID; @@ -503,7 +503,7 @@ public function getId(): int public function testEditWithRedirectToContactActionWithChildObject(): void { - $customObject = new class() extends CustomObject { + $customObject = new class extends CustomObject { public function getId() { return FormControllerTest::OBJECT_ID; @@ -511,7 +511,7 @@ public function getId() public function getRelationshipObject(): CustomObject { - return new class() extends CustomObject { + return new class extends CustomObject { public function getId() { return 555; diff --git a/Tests/Unit/Controller/CustomItem/SaveControllerTest.php b/Tests/Unit/Controller/CustomItem/SaveControllerTest.php index 5dc17011f..60fd2cae1 100644 --- a/Tests/Unit/Controller/CustomItem/SaveControllerTest.php +++ b/Tests/Unit/Controller/CustomItem/SaveControllerTest.php @@ -503,7 +503,7 @@ function () { ->method('fetchEntity') ->with(self::OBJECT_ID) ->willReturn( - new class() extends CustomObject { + new class extends CustomObject { public function getId() { return SaveControllerTest::OBJECT_ID; @@ -511,7 +511,7 @@ public function getId() public function getRelationshipObject(): CustomObject { - return new class() extends CustomObject { + return new class extends CustomObject { public function getId() { return 6668; diff --git a/Tests/Unit/Controller/CustomItem/UnlinkControllerTest.php b/Tests/Unit/Controller/CustomItem/UnlinkControllerTest.php index c548accf1..c0d7cfd9f 100644 --- a/Tests/Unit/Controller/CustomItem/UnlinkControllerTest.php +++ b/Tests/Unit/Controller/CustomItem/UnlinkControllerTest.php @@ -165,10 +165,10 @@ public function getId(): int public function testSaveActionWithChildItem(): void { - $customObject = new class() extends CustomObject { + $customObject = new class extends CustomObject { }; - $childCustomObject = new class() extends CustomObject { + $childCustomObject = new class extends CustomObject { }; $customObject->setRelationshipObject($childCustomObject); diff --git a/Tests/Unit/DTO/TableConfigTest.php b/Tests/Unit/DTO/TableConfigTest.php index 110f2acf2..fa3c6eafd 100644 --- a/Tests/Unit/DTO/TableConfigTest.php +++ b/Tests/Unit/DTO/TableConfigTest.php @@ -92,7 +92,7 @@ private function initTableConfig( int $limit = self::LIMIT, int $page = self::PAGE, string $orderBy = self::ORDER_BY, - string $orderDirection = self::ORDER_BY_DIR + string $orderDirection = self::ORDER_BY_DIR, ): TableConfig { return new TableConfig( $limit, diff --git a/Tests/Unit/EventListener/CustomItemPostSaveSubscriberTest.php b/Tests/Unit/EventListener/CustomItemPostSaveSubscriberTest.php index b1a1e38ed..56cf2c3c1 100644 --- a/Tests/Unit/EventListener/CustomItemPostSaveSubscriberTest.php +++ b/Tests/Unit/EventListener/CustomItemPostSaveSubscriberTest.php @@ -24,7 +24,7 @@ public function testGetSubscribedEvents(): void public function testPostSaveWithMasterItemDoesNotAttemptToLink(): void { - $customItemModel = new class() extends CustomItemModel { + $customItemModel = new class extends CustomItemModel { public function __construct() { // noop @@ -36,10 +36,10 @@ public function fetchEntity(int $id): CustomItem } }; - $requestStack = new class() extends RequestStack { + $requestStack = new class extends RequestStack { public function getCurrentRequest() { - return new class() extends Request { + return new class extends Request { public function __construct() { parent::__construct(); @@ -65,7 +65,7 @@ public function __construct() public function testPostSaveWithRelationshipButWrongRouteItemDoesNotAttemptToLink(): void { - $customItemModel = new class() extends CustomItemModel { + $customItemModel = new class extends CustomItemModel { public function __construct() { // noop @@ -77,10 +77,10 @@ public function fetchEntity(int $id): CustomItem } }; - $requestStack = new class() extends RequestStack { + $requestStack = new class extends RequestStack { public function getCurrentRequest() { - return new class() extends Request { + return new class extends Request { public function __construct() { parent::__construct(); diff --git a/Tests/Unit/EventListener/CustomObjectPostSaveSubscriberTest.php b/Tests/Unit/EventListener/CustomObjectPostSaveSubscriberTest.php index 5422c7ea3..c9bae9092 100644 --- a/Tests/Unit/EventListener/CustomObjectPostSaveSubscriberTest.php +++ b/Tests/Unit/EventListener/CustomObjectPostSaveSubscriberTest.php @@ -44,7 +44,7 @@ public function saveEntity($entity, $unlock = true): void public function testPostSaveMasterObject(): void { - $customObjectModel = new class() extends CustomObjectModel { + $customObjectModel = new class extends CustomObjectModel { public function __construct() { // noop diff --git a/Tests/Unit/Helper/ContactFilterMatcherTest.php b/Tests/Unit/Helper/ContactFilterMatcherTest.php new file mode 100644 index 000000000..d29482d28 --- /dev/null +++ b/Tests/Unit/Helper/ContactFilterMatcherTest.php @@ -0,0 +1,313 @@ +customFieldModel = $this->createMock(CustomFieldModel::class); + $this->customObjectModel = $this->createMock(CustomObjectModel::class); + $this->customItemModel = $this->createMock(CustomItemModel::class); + $this->segmentRepository = $this->createMock(LeadListRepository::class); + $this->companyRepository = $this->createMock(CompanyRepository::class); + $this->connection = $this->createMock(Connection::class); + + $this->matcher = new ContactFilterMatcher( + $this->customFieldModel, + $this->customObjectModel, + $this->customItemModel, + $this->segmentRepository, + $this->companyRepository, + $this->connection, + 10 + ); + } + + public function testMatchReturnsFalseWhenNoCustomObjectFiltersPresent(): void + { + $filters = [ + $this->buildLeadFilter('email', '=', 'test@example.com'), + ]; + + $hasCustomFields = false; + $result = $this->matcher->match($filters, ['id' => 1, 'email' => 'test@example.com'], $hasCustomFields); + + $this->assertFalse($result); + $this->assertFalse($hasCustomFields); + $this->customObjectModel->expects($this->never())->method('fetchEntity'); + } + + public function testMatchReturnsFalseWhenCustomObjectFetchThrowsNotFoundException(): void + { + $this->customObjectModel->method('fetchEntity') + ->willThrowException(new NotFoundException('Custom object not found')); + + $hasCustomFields = false; + $result = $this->matcher->match([$this->buildCmoFilter('cmo_1', '=', 'Acme')], ['id' => 42], $hasCustomFields); + + $this->assertFalse($result); + $this->assertFalse($hasCustomFields); + } + + public function testMatchReturnsFalseWhenCustomObjectFetchThrowsInvalidCustomObjectFormatListException(): void + { + $this->customObjectModel->method('fetchEntity') + ->willThrowException(new InvalidCustomObjectFormatListException('bad format')); + + $hasCustomFields = false; + $result = $this->matcher->match([$this->buildCmoFilter('cmo_1', '=', 'Acme')], ['id' => 42], $hasCustomFields); + + $this->assertFalse($result); + $this->assertFalse($hasCustomFields); + } + + public function testMatchReturnsFalseWhenContactHasNoLinkedCustomItems(): void + { + $this->customObjectModel->method('fetchEntity')->willReturn($this->buildCustomObject(5)); + $this->customItemModel->method('getArrayTableData')->willReturn([]); + + $hasCustomFields = false; + $result = $this->matcher->match([$this->buildCmoFilter('cmo_5', '=', 'Acme')], ['id' => 42], $hasCustomFields); + + $this->assertFalse($result); + // hasCustomFields is true because the CO filter was found and processed + $this->assertTrue($hasCustomFields); + } + + public function testMatchReturnsTrueForEmptyOperatorWhenContactHasNoLinkedItems(): void + { + $this->customObjectModel->method('fetchEntity')->willReturn($this->buildCustomObject(1)); + $this->customItemModel->method('getArrayTableData')->willReturn([]); + + $filter = array_merge($this->buildCmoFilter('cmo_1', 'empty', ''), ['type' => 'text']); + $result = $this->matcher->match([$filter], ['id' => 42]); + + $this->assertTrue($result); + } + + public function testMatchReturnsFalseForNotEmptyOperatorWhenContactHasNoLinkedItems(): void + { + $this->customObjectModel->method('fetchEntity')->willReturn($this->buildCustomObject(1)); + $this->customItemModel->method('getArrayTableData')->willReturn([]); + + $filter = array_merge($this->buildCmoFilter('cmo_1', '!empty', ''), ['type' => 'text']); + $result = $this->matcher->match([$filter], ['id' => 42]); + + $this->assertFalse($result); + } + + public function testMatchReturnsTrueWhenItemNameMatchesEqualFilter(): void + { + $this->customObjectModel->method('fetchEntity')->willReturn($this->buildCustomObject(3)); + $this->customItemModel->method('getArrayTableData')->willReturn([['name' => 'Acme Corp']]); + + $result = $this->matcher->match([$this->buildCmoFilter('cmo_3', '=', 'Acme Corp')], ['id' => 42]); + + $this->assertTrue($result); + } + + public function testMatchReturnsFalseWhenItemNameDoesNotMatchEqualFilter(): void + { + $this->customObjectModel->method('fetchEntity')->willReturn($this->buildCustomObject(3)); + $this->customItemModel->method('getArrayTableData')->willReturn([['name' => 'Wrong Corp']]); + + $result = $this->matcher->match([$this->buildCmoFilter('cmo_3', '=', 'Acme Corp')], ['id' => 42]); + + $this->assertFalse($result); + } + + public function testMatchReturnsTrueWhenAnyLinkedItemNameMatchesFilter(): void + { + $this->customObjectModel->method('fetchEntity')->willReturn($this->buildCustomObject(3)); + $this->customItemModel->method('getArrayTableData')->willReturn([ + ['name' => 'First Item'], + ['name' => 'Acme Corp'], + ['name' => 'Third Item'], + ]); + + $result = $this->matcher->match([$this->buildCmoFilter('cmo_3', '=', 'Acme Corp')], ['id' => 42]); + + $this->assertTrue($result); + } + + public function testMatchSetsHasCustomFieldsToTrueWhenCustomObjectFilterIsProcessed(): void + { + $this->customObjectModel->method('fetchEntity')->willReturn($this->buildCustomObject(1)); + $this->customItemModel->method('getArrayTableData')->willReturn([['name' => 'Any']]); + + $hasCustomFields = false; + $this->matcher->match([$this->buildCmoFilter('cmo_1', '=', 'Any')], ['id' => 42], $hasCustomFields); + + $this->assertTrue($hasCustomFields); + } + + public function testCustomItemsAreFetchedOncePerObjectAndLeadAcrossMultipleFilters(): void + { + $this->customObjectModel->method('fetchEntity')->willReturn($this->buildCustomObject(1)); + + $this->customItemModel->expects($this->once()) + ->method('getArrayTableData') + ->willReturn([['name' => 'Acme']]); + + $filters = [ + $this->buildCmoFilter('cmo_1', '=', 'Acme'), + $this->buildCmoFilter('cmo_1', '!=', 'Other'), + ]; + + $this->matcher->match($filters, ['id' => 42]); + } + + public function testMatchFetchesCompanyDataWhenFilterFieldStartsWithCompany(): void + { + $this->customObjectModel->method('fetchEntity')->willReturn($this->buildCustomObject(1)); + $this->customItemModel->method('getArrayTableData')->willReturn([['name' => 'Test']]); + + $this->companyRepository->expects($this->once()) + ->method('getCompaniesByLeadId') + ->with('42') + ->willReturn([]); + + $filters = [ + $this->buildCmoFilter('cmo_1', '=', 'Test'), + $this->buildLeadFilter('companycountry', '=', 'US'), + ]; + + $this->matcher->match($filters, ['id' => 42]); + } + + public function testMatchDoesNotFetchCompanyDataWhenLeadAlreadyHasCompanies(): void + { + $this->customObjectModel->method('fetchEntity')->willReturn($this->buildCustomObject(1)); + $this->customItemModel->method('getArrayTableData')->willReturn([['name' => 'Test']]); + + $this->companyRepository->expects($this->never())->method('getCompaniesByLeadId'); + + $filters = [ + $this->buildCmoFilter('cmo_1', '=', 'Test'), + $this->buildLeadFilter('companycountry', '=', 'US'), + ]; + + $this->matcher->match($filters, ['id' => 42, 'companies' => [['companycountry' => 'US']]]); + } + + public function testMatchFetchesTagsWhenFilterTypeIsTags(): void + { + $this->customObjectModel->method('fetchEntity')->willReturn($this->buildCustomObject(1)); + $this->customItemModel->method('getArrayTableData')->willReturn([['name' => 'Test']]); + + $result = $this->createMock(Result::class); + $queryBuilder = $this->createMock(DbalQueryBuilder::class); + $result->method('fetchFirstColumn')->willReturn(['1', '5']); + $queryBuilder->method('select')->willReturnSelf(); + $queryBuilder->method('from')->willReturnSelf(); + $queryBuilder->method('where')->willReturnSelf(); + $queryBuilder->method('setParameter')->willReturnSelf(); + $queryBuilder->method('executeQuery')->willReturn($result); + + $this->connection->expects($this->once()) + ->method('createQueryBuilder') + ->willReturn($queryBuilder); + + $filters = [ + $this->buildCmoFilter('cmo_1', '=', 'Test'), + ['object' => 'lead', 'field' => 'tags', 'type' => 'tags', 'operator' => 'in', 'filter' => ['1'], 'glue' => 'and'], + ]; + + $this->matcher->match($filters, ['id' => 42]); + } + + public function testMatchDoesNotFetchTagsWhenLeadAlreadyHasTags(): void + { + $this->customObjectModel->method('fetchEntity')->willReturn($this->buildCustomObject(1)); + $this->customItemModel->method('getArrayTableData')->willReturn([['name' => 'Test']]); + + $this->connection->expects($this->never())->method('createQueryBuilder'); + + $filters = [ + $this->buildCmoFilter('cmo_1', '=', 'Test'), + ['object' => 'lead', 'field' => 'tags', 'type' => 'tags', 'operator' => 'in', 'filter' => ['1'], 'glue' => 'and'], + ]; + + $this->matcher->match($filters, ['id' => 42, 'tags' => ['1', '5']]); + } + + // Helpers + + private function buildCustomObject(int $id): MockObject + { + $customObject = $this->createMock(CustomObject::class); + $customObject->method('getId')->willReturn($id); + + return $customObject; + } + + /** + * @return mixed[] + */ + private function buildCmoFilter(string $field, string $operator, string $filterValue): array + { + return [ + 'object' => 'custom_object', + 'field' => $field, + 'type' => 'text', + 'operator' => $operator, + 'filter' => $filterValue, + 'glue' => 'and', + ]; + } + + /** + * @return mixed[] + */ + private function buildLeadFilter(string $field, string $operator, string $filterValue): array + { + return [ + 'object' => 'lead', + 'field' => $field, + 'type' => 'text', + 'operator' => $operator, + 'filter' => $filterValue, + 'glue' => 'and', + ]; + } +} diff --git a/Tests/Unit/Repository/CustomObjectRepositoryTest.php b/Tests/Unit/Repository/CustomObjectRepositoryTest.php index d522892c0..70622f20a 100644 --- a/Tests/Unit/Repository/CustomObjectRepositoryTest.php +++ b/Tests/Unit/Repository/CustomObjectRepositoryTest.php @@ -150,7 +150,7 @@ public function testGetTableAlias(): void public function testGetFilterSegmentsMethod(): void { - $customObject = new class() extends CustomObject { + $customObject = new class extends CustomObject { public function getId() { return random_int(1, 100); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 59bfd9961..bc030b658 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -692,6 +692,31 @@ parameters: count: 1 path: Tests/Unit/Segment/Query/UnionQueryContainerTest.php + - + message: "#^Constant MAUTIC_TABLE_PREFIX not found\\.$#" + count: 1 + path: Helper/ContactFilterMatcher.php + + - + message: "#^Method MauticPlugin\\\\CustomObjectsBundle\\\\Helper\\\\ContactFilterMatcher\\:\\:transformFilterDataForLead\\(\\) is unused\\.$#" + count: 1 + path: Helper/ContactFilterMatcher.php + + - + message: "#^Method MauticPlugin\\\\CustomObjectsBundle\\\\Helper\\\\ContactFilterMatcher\\:\\:transformFilterDataForLeadPolyfill\\(\\) never returns array so it can be removed from the return type\\.$#" + count: 1 + path: Polyfill/EventListener/MatchFilterForLeadTrait.php + + - + message: "#^Method MauticPlugin\\\\CustomObjectsBundle\\\\Helper\\\\ContactFilterMatcher\\:\\:transformFilterDataForLeadPolyfill\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: Polyfill/EventListener/MatchFilterForLeadTrait.php + + - + message: "#^Method MauticPlugin\\\\CustomObjectsBundle\\\\Helper\\\\ContactFilterMatcher\\:\\:transformFilterDataForLead\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: Helper/ContactFilterMatcher.php + - message: """ #^Fetching deprecated class constant PARAM_INT_ARRAY of class Doctrine\\\\DBAL\\\\Connection\\: diff --git a/phpstan-class-aliases.php b/phpstan-class-aliases.php index 5c9cf0653..60d7ea99c 100644 --- a/phpstan-class-aliases.php +++ b/phpstan-class-aliases.php @@ -1,3 +1,3 @@