Completed
Push — master ( 03910f...346372 )
by Matt
04:36
created

ProblemsGenerateCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 17 3
A __construct() 0 4 1
A configure() 0 6 1
1
<?php
2
3
namespace App\Command;
4
5
use App\Service\ProblemService;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Style\SymfonyStyle;
12
13
class ProblemsGenerateCommand extends Command
14
{
15
    protected static $defaultName = 'problems:generate';
16
    protected static $defaultDescription = 'Add a short description for your command';
17
18
19
    /** @var ProblemService */
20
    private $problemService;
21
22
    function __construct(ProblemService $problemService)
23
    {
24
        $this->problemService = $problemService;
25
        parent::__construct();
26
    }
27
28
    protected function configure()
29
    {
30
        $this
31
            ->setDescription(self::$defaultDescription)
32
            ->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
33
            ->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
34
        ;
35
    }
36
37
    protected function execute(InputInterface $input, OutputInterface $output): int
38
    {
39
        $io = new SymfonyStyle($input, $output);
40
        $arg1 = $input->getArgument('arg1');
41
42
        if ($arg1) {
43
            $io->note(sprintf('You passed an argument: %s', $arg1));
0 ignored issues
show
Bug introduced by
It seems like $arg1 can also be of type string[]; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
            $io->note(sprintf('You passed an argument: %s', /** @scrutinizer ignore-type */ $arg1));
Loading history...
44
        }
45
46
        if ($input->getOption('option1')) {
47
            // ...
48
        }
49
        $this->problemService->createProblemReport();
50
51
        // $io->success('You have a new command! Now make it your own! Pass --help to see your options.');
52
53
        return Command::SUCCESS;
54
    }
55
}
56