Completed
Push — master ( cb42e4...38bddd )
by Yann
01:59
created

ArchiveTokenCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 1
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 2
    protected function configure()
20
    {
21
        $this
22 2
            ->setName('yokai:security-token:archive')
23 2
            ->addOption('purpose', null, InputOption::VALUE_OPTIONAL, 'Filter tokens to archive on purpose.')
24 2
            ->addOption('before',  null, InputOption::VALUE_OPTIONAL, '[deprecated] Filter tokens to archive on created date.')
25
        ;
26 2
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31 2
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33 2
        $purpose = $input->getOption('purpose');
34
35 2
        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 2
        $archivist = $this->getContainer()->get('yokai_security_token.archivist');
44
45 2
        $count = $archivist->archive($purpose);
46
47 2
        $output->writeln(
48 2
            sprintf('<info>Successfully archived <comment>%d</comment> security token(s).</info>', $count)
49
        );
50 2
    }
51
}
52