DiggingCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 33
c 1
b 0
f 0
dl 0
loc 78
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 17 1
A configure() 0 20 1
A __construct() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the Veslo project <https://github.com/symfony-doge/veslo>.
5
 *
6
 * (C) 2019 Pavel Petrov <[email protected]>.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://opensource.org/licenses/GPL-3.0 GPL-3.0
12
 */
13
14
declare(strict_types=1);
15
16
namespace Veslo\AnthillBundle\Command;
17
18
use Symfony\Component\Console\Command\Command;
19
use Symfony\Component\Console\Input\InputArgument;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Input\InputOption;
22
use Symfony\Component\Console\Output\OutputInterface;
23
use Veslo\AnthillBundle\Command\Roadmap\ListCommand;
24
use Veslo\AnthillBundle\Vacancy\AntQueen;
25
use Veslo\AnthillBundle\Vacancy\DiggerInterface;
26
27
/**
28
 * Represents dung (vacancies) digging process.
29
 * This is an initial stage of vacancy research workflow, where objects will be 'found' first time
30
 *
31
 * Usage example:
32
 * ```
33
 * bin/console veslo:anthill:digging hh php --iterations=10
34
 * ```
35
 *
36
 * @see ListCommand
37
 */
38
class DiggingCommand extends Command
39
{
40
    /**
41
     * Aggregates all available roadmap services for vacancy parsing
42
     *
43
     * @var AntQueen
44
     */
45
    private $antQueen;
46
47
    /**
48
     * Digs some dung (vacancies) from internet and sends to queue for processing
49
     *
50
     * @var DiggerInterface
51
     */
52
    private $digger;
53
54
    /**
55
     * DiggingCommand constructor.
56
     *
57
     * @param AntQueen        $antQueen Aggregates all available roadmap services for vacancy parsing
58
     * @param DiggerInterface $digger   Digs some dung (vacancies) from internet and sends to queue for processing
59
     * @param string|null     $name     The name of the command; passing null means it must be set in configure()
60
     */
61
    public function __construct(AntQueen $antQueen, DiggerInterface $digger, ?string $name = null)
62
    {
63
        $this->antQueen = $antQueen;
64
        $this->digger   = $digger;
65
66
        parent::__construct($name);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    protected function configure()
73
    {
74
        $this
75
            ->setDescription('Digs some dung (vacancies) from internet and sends to queue for processing')
76
            ->addArgument(
77
                'roadmap',
78
                InputArgument::REQUIRED,
79
                'Name of digging plan during which vacancies will be parsed from specified source'
80
            )
81
            ->addArgument(
82
                'configuration',
83
                InputArgument::OPTIONAL,
84
                'Key of configuration record for roadmap, determines vacancy search criteria'
85
            )
86
            ->addOption(
87
                'iterations',
88
                'i',
89
                InputOption::VALUE_REQUIRED,
90
                'Maximum count of vacancies from internet to proceed during command\'s single run',
91
                10
92
            )
93
        ;
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99
    protected function execute(InputInterface $input, OutputInterface $output)
100
    {
101
        $roadmapName      = (string) $input->getArgument('roadmap');
102
        $configurationKey = (string) $input->getArgument('configuration');
103
        $iterations       = (int) $input->getOption('iterations');
104
105
        $roadmap = $this->antQueen->buildRoadmap($roadmapName, $configurationKey);
106
107
        $successfulIterations = $this->digger->dig($roadmap, $iterations);
108
109
        $roadmapName     = $roadmap->getName();
110
        $messageComplete = str_replace(
111
            ['{roadmapName}', '{iterations}', '{successful}'],
112
            [$roadmapName, $iterations, $successfulIterations],
113
            'Digging complete for roadmap: {roadmapName} ({iterations} iterations, {successful} successful).'
114
        );
115
        $output->writeln($messageComplete);
116
    }
117
}
118