Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

TranslatorCommandController::clearCacheAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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\Bundle\FrameworkBundle\Controller\Controller;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\Routing\Annotation\Route;
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
     * @deprecated Using the "KunstmaanTranslatorBundle_command_export" route is deprecated since KunstmaanTranslatorBundle 5.4 and will be removed in KunstmaanTranslatorBundle 6.0. Use the default adminlist bundle export functionality instead.
76
     */
77
    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...
78
    {
79
        // NEXT_MAJOR this route will be removed because we are now using the common export logic
80
        @trigger_error('Using the "KunstmaanTranslatorBundle_command_export" route is deprecated since KunstmaanTranslatorBundle 5.4 and will be removed in KunstmaanTranslatorBundle 6.0. Use the default adminlist bundle export functionality instead.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
81
        $locales = $this->getParameter('kuma_translator.managed_locales');
82
        $exportCommand = new ExportCommand();
83
        $exportCommand
84
            ->setLocales($locales)
85
            ->setFormat('csv');
86
87
        $response = $this->get('kunstmaan_translator.service.exporter.command_handler')->executeExportCSVCommand($exportCommand);
88
89
        return $response;
90
    }
91
}
92