Passed
Branch develop (6d6783)
by BENARD
03:42
created

ArticleCommand::execute()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 15
nc 8
nop 2
dl 0
loc 19
rs 9.4555
c 0
b 0
f 0
1
<?php
2
namespace VideoGamesRecords\DwhBundle\Command;
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\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use VideoGamesRecords\DwhBundle\Service\ArticleService;
11
12
class ArticleCommand extends Command
13
{
14
    protected static $defaultName = 'vgr-dwh:article';
15
16
    private ArticleService $articleService;
17
18
    public function __construct(ArticleService $articleService)
19
    {
20
        $this->articleService = $articleService;
21
        parent::__construct();
22
    }
23
24
    protected function configure()
25
    {
26
        $this
27
            ->setName('vgr-dwh:article')
28
            ->setDescription('Command post article')
29
            ->addArgument(
30
                'function',
31
                InputArgument::REQUIRED,
32
                'Who do you want to do?'
33
            )
34
            ->addOption(
35
                'date',
36
                null,
37
                InputOption::VALUE_OPTIONAL,
38
                ''
39
            )
40
        ;
41
    }
42
43
    /**
44
     * @param InputInterface  $input
45
     * @param OutputInterface $output
46
     * @return int
47
     * @throws Exception
48
     */
49
    protected function execute(InputInterface $input, OutputInterface $output): int
50
    {
51
        $function = $input->getArgument('function');
52
        $date = $input->getOption('date');
53
        if ($date === null) {
54
            $date = date('Y-m-d');
55
        }
56
        switch ($function) {
57
            case 'top-week':
58
                $this->articleService->postTopWeek($date);
59
                break;
60
            case 'top-month':
61
                $this->articleService->postTopMonth($date);
62
                break;
63
            case 'top-year':
64
                $this->articleService->postTopYear($date);
65
                break;
66
        }
67
        return 0;
68
    }
69
}
70