Completed
Push — master ( 395774...b3be9a )
by
unknown
16s queued 12s
created

MetaSeoController::updateSeo()   B

Complexity

Conditions 3
Paths 11

Size

Total Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 8.9381
c 0
b 0
f 0
cc 3
nc 11
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Dealer\Controller;
4
5
use Dealer\Dealer;
6
use Dealer\Model\DealerMetaSeoQuery;
7
use Symfony\Component\HttpFoundation\RedirectResponse;
8
use Thelia\Controller\Admin\BaseAdminController;
9
use Thelia\Form\Exception\FormValidationException;
10
use Thelia\Tools\URL;
11
12
class MetaSeoController extends BaseAdminController
13
{
14
    public function updateSeo()
15
    {
16
        $form = $this->createForm('dealer.meta.seo');
17
        try {
18
            $this->validateForm($form);
19
20
            $databasesConfiguration = [
21
                'dealer_id' => $form->getForm()->get('dealer_id')->getData(),
22
                'slug' => $form->getForm()->get('slug')->getData(),
23
                'meta_title' => $form->getForm()->get('meta_title')->getData(),
24
                'meta_description' => $form->getForm()->get('meta_description')->getData(),
25
                'meta_keywords' => $form->getForm()->get('meta_keywords')->getData(),
26
                'meta_json' => $form->getForm()->get('meta_json')->getData(),
27
            ];
28
29
            $dealerSeo = DealerMetaSeoQuery::create()
30
                ->filterByDealerId($databasesConfiguration["dealer_id"])
31
                ->findOneOrCreate();
32
33
            $dealerSeo
34
                ->setJson( $databasesConfiguration["meta_json"])
35
                ->setSlug($databasesConfiguration["slug"])
36
                ->setMetaTitle($databasesConfiguration["meta_title"])
37
                ->setMetaDescription($databasesConfiguration["meta_description"])
38
                ->setMetaKeywords($databasesConfiguration["meta_keywords"])
39
                ->save();
40
41
            return RedirectResponse::create(
42
                URL::getInstance()->absoluteUrl('admin/module/Dealer/dealer')
43
            );
44
45
        } catch (FormValidationException $exception) {
0 ignored issues
show
Bug introduced by
The class Thelia\Form\Exception\FormValidationException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
46
            if (!$form->getForm()->isValid()) {
47
                $this->setupFormErrorContext(
48
                    'Dealer meta seo manager',
49
                    $this->createStandardFormValidationErrorMessage($exception),
50
                    $form
51
                );
52
                $form->setErrorMessage(null);
53
            } else {
54
                $this->setupFormErrorContext(
55
                    'Dealer meta seo manager',
56
                    $exception->getMessage(),
57
                    $form
58
                );
59
            }
60
61
            $response = $this->render(
62
                'module-configure',
63
                [
64
                    'module_code' => Dealer::DOMAIN_NAME
65
                ]
66
            );
67
        }
68
69
        return $response;
70
    }
71
}