Passed
Branch develop (38ee07)
by BENARD
05:37
created

PostTopMonthCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 2
1
<?php
2
namespace VideoGamesRecords\CoreBundle\Command\Article;
3
4
use Exception;
5
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use VideoGamesRecords\CoreBundle\Service\Article\PostTopMonthHandler;
10
11
class PostTopMonthCommand extends Command
12
{
13
    protected static $defaultName = 'vgr-core:post-top-month';
14
15
    private PostTopMonthHandler $postTopMonthHandler;
16
17
    public function __construct(PostTopMonthHandler $postTopMonthHandler)
18
    {
19
        $this->postTopMonthHandler = $postTopMonthHandler;
20
        parent::__construct();
21
    }
22
23
    protected function configure()
24
    {
25
        $this
26
            ->setName('vgr-core:post-top-month')
27
            ->setDescription('Command post top month')
28
            ->addOption(
29
                'date',
30
                null,
31
                InputOption::VALUE_OPTIONAL,
32
                ''
33
            )
34
        ;
35
    }
36
37
    /**
38
     * @param InputInterface  $input
39
     * @param OutputInterface $output
40
     * @return int
41
     * @throws Exception
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output): int
44
    {
45
        $date = $input->getOption('date');
46
        if ($date === null) {
47
            $date = date('Y-m-d');
48
        }
49
        $this->postTopMonthHandler->handle($date);
50
        return Command::SUCCESS;
51
    }
52
}
53