Completed
Pull Request — master (#24)
by Yann
03:08
created

ArchiveTokenCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
cbo 5
dl 0
loc 38
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 20 2
1
<?php
2
3
namespace Yokai\SecurityTokenBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Yokai\SecurityTokenBundle\Archive\ArchivistInterface;
10
11
/**
12
 * @author Yann Eugoné <[email protected]>
13
 */
14
class ArchiveTokenCommand extends ContainerAwareCommand
15
{
16
    /**
17
     * @inheritDoc
18
     */
19
    protected function configure()
20
    {
21
        $this
22
            ->setName('yokai:security-token:archive')
23
            ->addOption('purpose', null, InputOption::VALUE_OPTIONAL, 'Filter tokens to archive on purpose.')
24
            ->addOption('before',  null, InputOption::VALUE_OPTIONAL, '[deprecated] Filter tokens to archive on created date.')
0 ignored issues
show
Coding Style introduced by
Expected 1 space instead of 2 after comma in function call.
Loading history...
25
        ;
26
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $purpose = $input->getOption('purpose');
34
35
        if ($input->getOption('before')) {
36
            @trigger_error(
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...
37
                'The "before" option is deprecated since version 2.2 and will be removed in 3.0.',
38
                E_USER_DEPRECATED
39
            );
40
        }
41
42
        /** @var $archivist ArchivistInterface */
43
        $archivist = $this->getContainer()->get('yokai_security_token.archivist');
44
45
        $count = $archivist->archive($purpose);
46
47
        $output->writeln(
48
            sprintf('<info>Successfully archived <comment>%d</comment> security token(s).</info>', $count)
49
        );
50
    }
51
}
52