ParsingCommand   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 configure() 0 10 1
A __construct() 0 6 1
A execute() 0 12 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\LocationDto;
23
use Veslo\AnthillBundle\Vacancy\Parser\Earwig;
24
use Veslo\AppBundle\Workflow\Vacancy\PitInterface;
25
26
/**
27
 * Represents dung (vacancies) parsing process
28
 * This is 'to_parse' transition of vacancy research workflow, moves an object place from 'found' to 'parsed'
29
 *
30
 * Usage example:
31
 * ```
32
 * bin/console veslo:anthill:parsing --iterations=10
33
 * ```
34
 */
35
class ParsingCommand extends Command
36
{
37
    /**
38
     * Vacancy URL storage
39
     * Should return instances of vacancy LocationDto or null, if storage is empty
40
     *
41
     * @var PitInterface
42
     *
43
     * @see LocationDto
44
     */
45
    private $source;
46
47
    /**
48
     * Parses vacancy URL from queue and sends data further to conveyor according to workflow
49
     *
50
     * @var Earwig
51
     */
52
    private $earwig;
53
54
    /**
55
     * ParsingCommand constructor.
56
     *
57
     * @param PitInterface $source Vacancy URL storage
58
     * @param Earwig       $earwig Parses vacancy URL from queue and sends data further according to workflow
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, Earwig $earwig, ?string $name = null)
62
    {
63
        $this->source = $source;
64
        $this->earwig = $earwig;
65
66
        parent::__construct($name);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    protected function configure()
73
    {
74
        $this
75
            ->setDescription('Parses vacancy URL and sends result data to queue for processing')
76
            ->addOption(
77
                'iterations',
78
                'i',
79
                InputOption::VALUE_REQUIRED,
80
                'Maximum count of vacancies from parsing queue 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->earwig->parse($this->source, $iterations);
94
95
        $messageComplete = str_replace(
96
            ['{iterations}', '{successful}'],
97
            [$iterations, $successfulIterations],
98
            'Parsing complete ({iterations} iterations, {successful} successful).'
99
        );
100
        $output->writeln($messageComplete);
101
    }
102
}
103