Completed
Branch master (38bddd)
by Yann
01:51
created

ArchiveTokenCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.0811

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 8
cts 11
cp 0.7272
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 2
crap 2.0811
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.')
0 ignored issues
show
Coding Style introduced by
Expected 1 space instead of 2 after comma in function call.
Loading history...
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