Skip to content

Commit

Permalink
[CS] Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DACHCOM Bot authored Jan 13, 2025
1 parent cd525e0 commit 6b2b93e
Show file tree
Hide file tree
Showing 342 changed files with 3,908 additions and 280 deletions.
14 changes: 12 additions & 2 deletions src/Assembler/FormAssembler.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace FormBuilderBundle\Assembler;

use FormBuilderBundle\Builder\FrontendFormBuilder;
use FormBuilderBundle\Event\FormAssembleEvent;
use FormBuilderBundle\Form\RuntimeData\FormRuntimeDataAllocatorInterface;
use FormBuilderBundle\FormBuilderEvents;
use FormBuilderBundle\Manager\DoubleOptInManager;
use FormBuilderBundle\Resolver\FormOptionsResolver;
use FormBuilderBundle\Manager\FormDefinitionManager;
use FormBuilderBundle\Model\FormDefinitionInterface;
use FormBuilderBundle\Resolver\FormOptionsResolver;
use Symfony\Component\Form\FormInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

Expand Down Expand Up @@ -118,7 +129,6 @@ public function buildForm(
array $formData = [],
bool $headless = false
): FormInterface {

$systemRuntimeData = $this->getSystemRuntimeData($optionsResolver, $headless);
$formAttributes = $optionsResolver->getFormAttributes();
$useCsrfProtection = $optionsResolver->useCsrfProtection();
Expand Down
13 changes: 11 additions & 2 deletions src/Assembler/FunnelActionElementAssembler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace FormBuilderBundle\Assembler;

use FormBuilderBundle\Model\FunnelActionDefinition;
Expand Down Expand Up @@ -48,7 +59,6 @@ private function assembleElement(
array $funnelActionConfiguration,
array $funnelActionContext,
): FunnelActionElement {

$contextOptionsResolver = new OptionsResolver();
$contextOptionsResolver->setDefaults([
'initiationPath' => null,
Expand Down Expand Up @@ -157,5 +167,4 @@ private function isLastChannel(OutputWorkflowInterface $outputWorkflow, OutputWo

return $outputWorkflow->getChannels()->last()->getId() === $channel->getId();
}

}
25 changes: 14 additions & 11 deletions src/Builder/ExtJsFormBuilder.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace FormBuilderBundle\Builder;

use FormBuilderBundle\Configuration\Configuration;
use FormBuilderBundle\Manager\TemplateManager;
use FormBuilderBundle\Model\Fragment\EntityToArrayAwareInterface;
use FormBuilderBundle\Model\FormDefinitionInterface;
use FormBuilderBundle\Model\Fragment\EntityToArrayAwareInterface;
use FormBuilderBundle\Model\OutputWorkflowInterface;
use FormBuilderBundle\OutputWorkflow\Channel\Funnel\Layer\VirtualActionDefinitions;
use FormBuilderBundle\Registry\OptionsTransformerRegistry;
use FormBuilderBundle\Registry\ConditionalLogicRegistry;
use FormBuilderBundle\Registry\OptionsTransformerRegistry;
use FormBuilderBundle\Registry\OutputWorkflowChannelRegistry;
use FormBuilderBundle\Transformer\DynamicOptionsTransformerInterface;
use FormBuilderBundle\Transformer\OptionsTransformerInterface;
Expand Down Expand Up @@ -248,7 +259,6 @@ private function generateAvailableWorkflowChannelsList(OutputWorkflowInterface $
{
$data = [];
foreach ($this->outputWorkflowChannelRegistry->getAllIdentifier() as $availableChannel) {

if ($this->outputWorkflowChannelRegistry->isFunnelAwareChannel($availableChannel) && $outputWorkflow->isFunnelWorkflow() === false) {
continue;
}
Expand All @@ -269,7 +279,6 @@ private function generateExtJsFormTypesStructure(bool $flat = false): array
$fieldStructure = $flat === true ? [] : $this->getFieldTypeGroups();

foreach ($formTypes as $formType => $formTypeConfiguration) {

if (!$this->isAllowedFormType($formType)) {
continue;
}
Expand Down Expand Up @@ -546,7 +555,7 @@ private function generateDoubleOptInConfiguration(): array
{
return $this->configuration->getConfig('double_opt_in');
}

private function getFormStoreData(): array
{
$formAttributes = $this->configuration->getConfig('form_attributes');
Expand Down Expand Up @@ -605,7 +614,6 @@ private function transformFieldOptions(array &$fieldData, bool $reverse = false)
}

foreach ($fieldData['options'] as $optionName => $optionValue) {

$optionKey = sprintf('options.%s', $optionName);

if (!isset($backendConfig['fields'][$optionKey])) {
Expand Down Expand Up @@ -652,7 +660,6 @@ private function checkDynamicFieldOptions(&$fieldData, array $formTypeConfig, st
}

foreach ($dynamicFields as $dynamicFieldName => $dynamicFieldOption) {

$dynamicFieldKey = str_replace('options.', '', $dynamicFieldName);
$optionFieldKey = str_replace('options.', '', $optionKey);

Expand All @@ -667,15 +674,13 @@ private function checkDynamicFieldOptions(&$fieldData, array $formTypeConfig, st

$dynamicFieldData = $transformedData;
if (!empty($dynamicFieldOption['options_transformer'])) {

/** @var DynamicOptionsTransformerInterface $transformer */
$transformer = $this->optionsTransformerRegistry->getDynamic($dynamicFieldOption['options_transformer']);
$dynamicFieldConfig = $dynamicFieldOption['config'] ?? null;

$dynamicFieldData = $reverse === false
? $transformer->transform($rawData, $transformedData, $dynamicFieldConfig)
: $transformer->reverseTransform($fieldData['options'][$dynamicFieldKey], $transformedData, $dynamicFieldConfig);

}

if ($reverse === true) {
Expand Down Expand Up @@ -706,14 +711,12 @@ private function transformContainerOptions(array &$fieldData, bool $reverse = fa
$currentConfiguration = $fieldData['configuration'];

foreach ($containerConfigurations as $containerConfiguration) {

$configName = $containerConfiguration['name'];
if (!isset($currentConfiguration[$configName])) {
continue;
}

if (!empty($containerConfiguration['options_transformer'])) {

$blockValue = $currentConfiguration[$configName];
$blockConfig = $containerConfiguration['config'];

Expand Down
16 changes: 11 additions & 5 deletions src/Builder/FrontendFormBuilder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace FormBuilderBundle\Builder;

use FormBuilderBundle\EventSubscriber\FormBuilderSubscriber;
Expand Down Expand Up @@ -31,7 +42,6 @@ public function buildDoubleOptInForm(
bool $isHeadlessForm = false,
bool $useCsrfProtection = true
): FormInterface {

$formDefinitionConfig = $formDefinition->getConfiguration();
$doubleOptInConfig = $formDefinition->getDoubleOptInConfig();

Expand Down Expand Up @@ -89,7 +99,6 @@ public function buildForm(
array $formData = [],
bool $useCsrfProtection = true
): FormInterface {

$defaults = [
'form_preset' => null,
'form_template' => null
Expand Down Expand Up @@ -136,7 +145,6 @@ public function buildHeadlessForm(
array $formData = [],
bool $useCsrfProtection = true
): FormInterface {

$formDefinitionConfig = $formDefinition->getConfiguration();

$formOptions = [
Expand All @@ -159,7 +167,6 @@ private function getBuilder(
array $formOptions = [],
bool $isHeadlessForm = false
): FormBuilderInterface {

$formDefinitionConfig = $formDefinition->getConfiguration();

if (isset($formDefinitionConfig['attributes']) && is_array($formDefinitionConfig['attributes'])) {
Expand Down Expand Up @@ -188,7 +195,6 @@ private function getBuilder(
private function addFormAttributes(array $currentAttributes, array $attributes): array
{
foreach ($attributes as $attribute) {

// legacy
if (!isset($attribute['option'])) {
continue;
Expand Down
12 changes: 11 additions & 1 deletion src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace FormBuilderBundle\Configuration;

class Configuration
Expand Down Expand Up @@ -107,7 +118,6 @@ public function getAvailableConstraints(): array
$constraintConfig = [];

foreach ($refClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $refProperty) {

$propertyName = $refProperty->getName();

if (in_array($propertyName, $invalidProperties)) {
Expand Down
14 changes: 12 additions & 2 deletions src/Controller/Admin/ExportController.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace FormBuilderBundle\Controller\Admin;

use Carbon\Carbon;
use FormBuilderBundle\Manager\FormDefinitionManager;
use FormBuilderBundle\Model\FormDefinitionInterface;
use FormBuilderBundle\Model\FormFieldDefinitionInterface;
use FormBuilderBundle\Model\OutputWorkflowInterface;
use FormBuilderBundle\Tool\ImportExportProcessor;
use Pimcore\Bundle\AdminBundle\Controller\AdminAbstractController;
use Pimcore\Model\Tool\Email;
use FormBuilderBundle\Manager\FormDefinitionManager;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -201,7 +212,6 @@ private function extractMailParams(Email\Log $log, FormDefinitionInterface $form
}

foreach ($mailParams as $mailParam) {

if (!is_array($mailParam)) {
continue;
}
Expand Down
17 changes: 12 additions & 5 deletions src/Controller/Admin/MailEditorController.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace FormBuilderBundle\Controller\Admin;

use FormBuilderBundle\Builder\ExtJsFormBuilder;
use FormBuilderBundle\MailEditor\TemplateGenerator;
use FormBuilderBundle\MailEditor\Widget\MailEditorFieldDataWidgetInterface;
use FormBuilderBundle\MailEditor\Widget\MailEditorWidgetInterface;
use FormBuilderBundle\Manager\FormDefinitionManager;
use FormBuilderBundle\Model\Fragment\EntityToArrayAwareInterface;
use FormBuilderBundle\Registry\MailEditorWidgetRegistry;
use FormBuilderBundle\MailEditor\TemplateGenerator;
use Pimcore\Bundle\AdminBundle\Controller\AdminAbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -50,7 +61,6 @@ public function getMailEditorDataAction(Request $request): JsonResponse
* @var MailEditorWidgetInterface $widget
*/
foreach ($widgets as $widgetType => $widget) {

$groupName = $widget->getWidgetGroupName();

if (!isset($allWidgets[$groupName])) {
Expand All @@ -61,10 +71,8 @@ public function getMailEditorDataAction(Request $request): JsonResponse
}

if ($widget instanceof MailEditorFieldDataWidgetInterface) {

$fieldConfigElements = [];
foreach ($formFields as $field) {

$widgetFieldType = $widget->getWidgetIdentifierByField($widgetType, $field);
$widgetsConfiguration[$widgetFieldType] = $this->translateWidgetConfig($widget->getWidgetConfigByField($field));

Expand Down Expand Up @@ -104,7 +112,6 @@ public function getMailEditorDataAction(Request $request): JsonResponse

$allWidgets[$groupName]['elements'] = $fieldConfigElements;
$widgetFieldsTemplate = (new TemplateGenerator())->generateWidgetFieldTemplate($fieldConfigElements);

} else {
$widgetsConfiguration[$widgetType] = $this->translateWidgetConfig($widget->getWidgetConfig());
$allWidgets[$groupName]['elements'][] = [
Expand Down
15 changes: 11 additions & 4 deletions src/Controller/Admin/OutputWorkflowApiController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - DACHCOM Commercial License (DCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) DACHCOM.DIGITAL AG (https://www.dachcom-digital.com)
* @license GPLv3 and DCL
*/

namespace FormBuilderBundle\Controller\Admin;

use FormBuilderBundle\Builder\ExtJsFormBuilder;
Expand Down Expand Up @@ -89,7 +100,6 @@ public function getApiProviderAction(Request $request): JsonResponse
}

foreach ($services as $identifier => $service) {

try {
$configurationFields = $this->validateApiConfigurationFields($service->getProviderConfigurationFields($formDefinition));
} catch (\Throwable $e) {
Expand All @@ -112,7 +122,6 @@ public function getApiProviderAction(Request $request): JsonResponse
protected function validateApiPredefinedFields(array $fields): array
{
return array_map(static function ($property) {

if (!is_array($property)) {
$property = [
'label' => $property,
Expand All @@ -124,7 +133,6 @@ protected function validateApiPredefinedFields(array $fields): array
'label' => $property['label'] ?? 'UNKNOWN',
'value' => $property['value'] ?? 'UNKNOWN'
];

}, $fields);
}

Expand All @@ -137,7 +145,6 @@ protected function validateApiConfigurationFields(array $fields): array
$validatedConfigurationFields = [];

foreach ($fields as $field) {

$optionsResolver = new OptionsResolver();
$optionsResolver->setRequired(['type', 'label', 'name', 'required']);
$optionsResolver->setAllowedValues('type', ['text', 'select']);
Expand Down
Loading

0 comments on commit 6b2b93e

Please sign in to comment.