CollectingCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 12 1
A __construct() 0 6 1
A configure() 0 10 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\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\OutputInterface;
22
use Veslo\AnthillBundle\Dto\Vacancy\Parser\ParsedDto;
23
use Veslo\AnthillBundle\Vacancy\Collector\AntWorker;
24
use Veslo\AppBundle\Workflow\Vacancy\PitInterface;
25
26
/**
27
 * Represents dung (vacancies) collecting process.
28
 * This is 'to_collect' transition of vacancy research workflow, from 'parsed' to 'collected'
29
 *
30
 * Usage example:
31
 * ```
32
 * bin/console veslo:anthill:collecting --iterations=10
33
 * ```
34
 */
35
class CollectingCommand extends Command
36
{
37
    /**
38
     * Vacancy parsed data storage
39
     * Should return ParsedDto instances or null if storage is empty
40
     *
41
     * @var PitInterface
42
     *
43
     * @see ParsedDto
44
     */
45
    private $source;
46
47
    /**
48
     * Collects raw vacancy data from queue and transforms it to the local persistent entities
49
     *
50
     * @var AntWorker
51
     */
52
    private $antWorker;
53
54
    /**
55
     * CollectingCommand constructor.
56
     *
57
     * @param PitInterface $source    Vacancy parsed data storage
58
     * @param AntWorker    $antWorker Collects raw vacancy data from queue and transforms it to the local entities
59
     * @param string|null  $name      The name of the command; passing null means it must be set in configure()
60
     */
61
    public function __construct(PitInterface $source, AntWorker $antWorker, ?string $name = null)
62
    {
63
        $this->source    = $source;
64
        $this->antWorker = $antWorker;
65
66
        parent::__construct($name);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    protected function configure()
73
    {
74
        $this
75
            ->setDescription('Collects dung (vacancies) from queue and sends to the Ministry of Truth for analysis')
76
            ->addOption(
77
                'iterations',
78
                'i',
79
                InputOption::VALUE_REQUIRED,
80
                'Maximum count of vacancy data entries to proceed during command\'s single run',
81
                10
82
            )
83
        ;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    protected function execute(InputInterface $input, OutputInterface $output)
90
    {
91
        $iterations = (int) $input->getOption('iterations');
92
93
        $successfulIterations = $this->antWorker->collect($this->source, $iterations);
94
95
        $messageComplete = str_replace(
96
            ['{iterations}', '{successful}'],
97
            [$iterations, $successfulIterations],
98
            'Collecting complete ({iterations} iterations, {successful} successful).'
99
        );
100
        $output->writeln($messageComplete);
101
    }
102
}
103