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

TranslationFlagCommand::configure()   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 6
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\Command;
4
5
use Kunstmaan\TranslatorBundle\Repository\TranslationRepository;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Command to reset/request translation flags from the stash
13
 *
14
 * @final since 5.1
15
 * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
16
 */
17
class TranslationFlagCommand extends ContainerAwareCommand
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...d\ContainerAwareCommand has been deprecated with message: since Symfony 4.2, use {@see Command} 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...
18
{
19
    /**
20
     * @var TranslationRepository
21
     */
22
    private $translationRepository;
23
24
    /**
25
     * @param TranslationRepository|null $translationRepository
26
     */
27
    public function __construct(/* TranslationRepository */ $translationRepository = null)
28
    {
29
        parent::__construct();
30
31
        if (!$translationRepository instanceof TranslationRepository) {
32
            @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), 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...
33
34
            $this->setName(null === $translationRepository ? 'kuma:translator:flag' : $translationRepository);
35
36
            return;
37
        }
38
39
        $this->translationRepository = $translationRepository;
40
    }
41
42
    protected function configure()
43
    {
44
        parent::configure();
45
46
        $this
47
            ->setName('kuma:translator:flag')
48
            ->setDescription('Reset translation flags')
49
            ->addOption('reset', 'r', InputOption::VALUE_NONE, 'Reset all flags to null in stash')
50
        ;
51
    }
52
53
    public function execute(InputInterface $input, OutputInterface $output)
54
    {
55
        if ($input->getOption('reset')) {
56
            $this->resetAllTranslationFlags();
57
            $output->writeln('<info>All translation and translation domain flags are reset.</info>');
58
        }
59
60
        return 0;
61
    }
62
63
    /**
64
     * Rest all flags of all translations and all domains
65
     */
66
    public function resetAllTranslationFlags()
67
    {
68
        if (null === $this->translationRepository) {
69
            $this->translationRepository = $this->getContainer()->get('kunstmaan_translator.repository.translation');
70
        }
71
72
        $this->translationRepository->resetAllFlags();
73
    }
74
}
75