ArchiveTokenCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Yokai\SecurityTokenBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
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 Command
15
{
16
    /**
17
     * @var ArchivistInterface
18
     */
19
    private $archivist;
20
21 2
    public function __construct(ArchivistInterface $archivist)
22
    {
23 2
        parent::__construct();
24
25 2
        $this->archivist = $archivist;
26 2
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31 2
    protected function configure()
32
    {
33
        $this
34 2
            ->setName('yokai:security-token:archive')
35 2
            ->addOption('purpose', null, InputOption::VALUE_OPTIONAL, 'Filter tokens to archive on purpose.')
36 2
            ->addOption('before',  null, InputOption::VALUE_OPTIONAL, '[deprecated] Filter tokens to archive on created date.')
37
        ;
38 2
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 2
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45 2
        $purpose = $input->getOption('purpose');
46
47 2
        if ($input->getOption('before')) {
48
            @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...
49
                'The "before" option is deprecated since version 2.2 and will be removed in 3.0.',
50
                E_USER_DEPRECATED
51
            );
52
        }
53
54 2
        $count = $this->archivist->archive($purpose);
55
56 2
        $output->writeln(
57 2
            sprintf('<info>Successfully archived <comment>%d</comment> security token(s).</info>', $count)
58
        );
59 2
    }
60
}
61