Skip to content

Commit

Permalink
Adding Symfony 4.0 and 4.1 Rector rule sets to CI (mautic#11479)
Browse files Browse the repository at this point in the history
* Adding SYMFONY_40 Rector rule

* Refactoring $this->form to DI because Rector couldn't bare it

Error message:

Could not process "app/bundles/IntegrationsBundle/Controller/ConfigController.php" file, due to:
         "System error: "Rector\Symfony\Rector\MethodCall\FormIsValidRector::isIsSubmittedByAlreadyCalledOnVariable():
         Argument #1 ($variable) must be of type PhpParser\Node\Expr\Variable, PhpParser\Node\Expr\PropertyFetch given,
         called in vendor/rector/rector/vendor/rector/rector-symfony/src/Rector/MethodCall/FormIsValidRector.php:59"
         Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On
         line: 86

* Adding also Symfony 4.1 ruleset as it does not change any code

* Typo fix

Co-authored-by: mollux <[email protected]>

Co-authored-by: mollux <[email protected]>
  • Loading branch information
escopecz and mollux authored Sep 23, 2022
1 parent 071484d commit 5626b8d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ jobs:
if [[ "${{ matrix.commands }}" == "PHPSTAN" ]]; then
composer phpstan
elif [[ "${{ matrix.commands }}" == "Rector" ]]; then
bin/console cache:warmup
composer rector -- --dry-run --no-progress-bar
elif [[ "${{ matrix.commands }}" == "CS Fixer" ]]; then
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
Expand Down
2 changes: 1 addition & 1 deletion app/bundles/ApiBundle/Controller/CommonApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ protected function processForm($entity, $parameters = null, $method = 'PUT')

$form->submit($submitParams, 'PATCH' !== $method);

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$this->setCategory($entity, $categoryId);
$preSaveError = $this->preSaveEntity($entity, $form, $submitParams, $action);

Expand Down
2 changes: 0 additions & 2 deletions app/bundles/CoreBundle/Helper/ThemeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,6 @@ public function zip($themeName)

return $tmpPath;
}

return false;
}

/**
Expand Down
33 changes: 14 additions & 19 deletions app/bundles/IntegrationsBundle/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class ConfigController extends AbstractFormController
*/
protected $request;

/**
* @var Form
*/
private $form;

/**
* @var BasicIntegration|ConfigFormInterface
*/
Expand Down Expand Up @@ -86,26 +81,26 @@ public function editAction(Request $request, string $integration)
$this->request = $request;

// Create the form
$this->form = $this->getForm();
$form = $this->getForm();

if (Request::METHOD_POST === $request->getMethod()) {
return $this->submitForm();
return $this->submitForm($form);
}

// Clear the session of previously stored fields in case it got stuck
/** @var Session $session */
$session = $this->get('session');
$session->remove("$integration-fields");

return $this->showForm();
return $this->showForm($form);
}

/**
* @return JsonResponse|Response
*/
private function submitForm()
private function submitForm(Form $form)
{
if ($this->isFormCancelled($this->form)) {
if ($this->isFormCancelled($form)) {
return $this->closeForm();
}

Expand All @@ -114,7 +109,7 @@ private function submitForm()
$fieldMappings = $settings['sync']['fieldMappings'] ?? [];

// Submit the form
$this->form->handleRequest($this->request);
$form->handleRequest($this->request);
if ($this->integrationObject instanceof ConfigFormSyncInterface) {
$integration = $this->integrationObject->getName();
$settings = $this->integrationConfiguration->getFeatureSettings();
Expand All @@ -131,7 +126,7 @@ private function submitForm()

/** @var FieldValidationHelper $fieldValidator */
$fieldValidator = $this->get('mautic.integrations.helper.field_validator');
$fieldValidator->validateRequiredFields($this->form, $this->integrationObject, $settings['sync']['fieldMappings']);
$fieldValidator->validateRequiredFields($form, $this->integrationObject, $settings['sync']['fieldMappings']);

$this->integrationConfiguration->setFeatureSettings($settings);
}
Expand All @@ -145,8 +140,8 @@ private function submitForm()
// Show the form if there are errors and the plugin is published or the authorized button was clicked
$integrationDetailsPost = $this->request->request->get('integration_details', []);
$authorize = !empty($integrationDetailsPost['in_auth']);
if (!$this->form->isValid() && ($this->integrationConfiguration->getIsPublished() || $authorize)) {
return $this->showForm();
if ($form->isSubmitted() && !$form->isValid() && ($this->integrationConfiguration->getIsPublished() || $authorize)) {
return $this->showForm($form);
}

// Save the integration configuration
Expand All @@ -156,12 +151,12 @@ private function submitForm()
$eventDispatcher->dispatch(IntegrationEvents::INTEGRATION_CONFIG_AFTER_SAVE, $configEvent);

// Show the form if the apply button was clicked
if ($this->isFormApplied($this->form)) {
if ($this->isFormApplied($form)) {
// Regenerate the form
$this->resetFieldsInSession();
$this->form = $this->getForm();
$form = $this->getForm();

return $this->showForm();
return $this->showForm($form);
}

// Otherwise close the modal
Expand All @@ -186,10 +181,10 @@ private function getForm()
/**
* @return JsonResponse|Response
*/
private function showForm()
private function showForm(Form $form)
{
$integrationObject = $this->integrationObject;
$form = $this->setFormTheme($this->form, 'IntegrationsBundle:Config:form.html.php');
$form = $this->setFormTheme($form, 'IntegrationsBundle:Config:form.html.php');
$formHelper = $this->get('templating.helper.form');

$showFeaturesTab =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,6 @@ protected function isFormValid(Form $form, array $data = null)
{
$form->submit($data, 'PATCH' !== $this->request->getMethod());

return $form->isValid();
return $form->isSubmitted() && $form->isValid();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function preSaveEntity(&$entity, $form, $parameters, $action = 'edit')
$triggerEventForm = $this->createTriggerEventEntityForm($triggerEventEntity);
$triggerEventForm->submit($eventParams, 'PATCH' !== $method);

if (!$triggerEventForm->isValid()) {
if (!($triggerEventForm->isSubmitted() && $triggerEventForm->isValid())) {
$formErrors = $this->getFormErrorMessages($triggerEventForm);
$msg = $this->getFormErrorMessage($formErrors);

Expand Down
8 changes: 7 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
);

// Define what rule sets will be applied
// $rectorConfig->sets([\Rector\Set\ValueObject\SetList::DEAD_CODE]); // @todo implement the whole set. Start rule by rule bellow.
$rectorConfig->sets([
\Rector\Symfony\Set\SymfonySetList::SYMFONY_40,
\Rector\Symfony\Set\SymfonySetList::SYMFONY_41,

// @todo implement the whole set. Start rule by rule below.
// \Rector\Set\ValueObject\SetList::DEAD_CODE
]);

// Define what signle rules will be applied
$rectorConfig->rule(\Rector\DeadCode\Rector\BooleanAnd\RemoveAndTrueRector::class);
Expand Down

0 comments on commit 5626b8d

Please sign in to comment.