Completed
Push — l10n_master ( 6cb695...818918 )
by Kunstmaan
50:17 queued 35:37
created

TranslatorCommandController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 47.37 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 36
loc 76
ccs 0
cts 49
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A clearCacheAction() 0 10 1
A importAction() 18 18 1
A importForcedAction() 18 18 1
A exportAction() 0 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Kunstmaan\TranslatorBundle\Controller;
4
5
use Kunstmaan\AdminBundle\FlashMessages\FlashTypes;
6
use Kunstmaan\TranslatorBundle\Model\Export\ExportCommand;
7
use Kunstmaan\TranslatorBundle\Model\Import\ImportCommand;
8
use Symfony\Component\Routing\Annotation\Route;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
use Symfony\Component\HttpFoundation\RedirectResponse;
11
12
class TranslatorCommandController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
13
{
14
    /**
15
     * @Route("/clear-cache", name="KunstmaanTranslatorBundle_command_clear_cache")
16
     */
17
    public function clearCacheAction()
18
    {
19
        $this->get('kunstmaan_translator.service.translator.resource_cacher')->flushCache();
20
        $this->addFlash(
21
            FlashTypes::SUCCESS,
22
            $this->get('translator')->trans('kuma_translator.command.clear.flash.success')
23
        );
24
25
        return new RedirectResponse($this->generateUrl('KunstmaanTranslatorBundle_settings_translations'));
26
    }
27
28
    /**
29
     * @Route("/import", name="KunstmaanTranslatorBundle_command_import")
30
     */
31 View Code Duplication
    public function importAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        $importCommand = new ImportCommand();
34
        $importCommand
35
            ->setForce(false)
36
            ->setDefaultBundle($this->getParameter('kuma_translator.default_bundle'))
37
            ->setBundles($this->getParameter('kuma_translator.bundles'))
38
            ->setGlobals(true);
39
40
        $this->get('kunstmaan_translator.service.importer.command_handler')->executeImportCommand($importCommand);
41
42
        $this->addFlash(
43
            FlashTypes::SUCCESS,
44
            $this->get('translator')->trans('kuma_translator.command.import.flash.success')
45
        );
46
47
        return new RedirectResponse($this->generateUrl('KunstmaanTranslatorBundle_settings_translations'));
48
    }
49
50
    /**
51
     * @Route("/import-forced", name="KunstmaanTranslatorBundle_command_import_forced")
52
     */
53 View Code Duplication
    public function importForcedAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $importCommand = new ImportCommand();
56
        $importCommand
57
            ->setForce(true)
58
            ->setDefaultBundle($this->getParameter('kuma_translator.default_bundle'))
59
            ->setBundles($this->getParameter('kuma_translator.bundles'))
60
            ->setGlobals(false);
61
62
        $this->get('kunstmaan_translator.service.importer.command_handler')->executeImportCommand($importCommand);
63
64
        $this->addFlash(
65
            FlashTypes::SUCCESS,
66
            $this->get('translator')->trans('kuma_translator.command.import.flash.force_success')
67
        );
68
69
        return new RedirectResponse($this->generateUrl('KunstmaanTranslatorBundle_settings_translations'));
70
    }
71
72
    /**
73
     * @Route("/export", name="KunstmaanTranslatorBundle_command_export")
74
     */
75
    public function exportAction()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
76
    {
77
        $locales = $this->getParameter('kuma_translator.managed_locales');
78
        $exportCommand = new ExportCommand();
79
        $exportCommand
80
            ->setLocales($locales)
81
            ->setFormat('csv');
82
83
        $response = $this->get('kunstmaan_translator.service.exporter.command_handler')->executeExportCSVCommand($exportCommand);
84
85
        return $response;
86
    }
87
}
88