IndexingCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
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\SanityBundle\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\Collector\AcceptanceDto;
23
use Veslo\AppBundle\Workflow\Vacancy\PitInterface;
24
use Veslo\SanityBundle\Vacancy\Indexer\Cockroach;
25
26
/**
27
 * Represents dung (vacancies) indexing process.
28
 * This is 'to_index' transition of vacancy research workflow, from 'collected' to 'indexed'
29
 *
30
 * Usage example:
31
 * ```
32
 * bin/console veslo:sanity:indexing --iterations=10
33
 * ```
34
 *
35
 * @see https://en.wikipedia.org/wiki/Ministries_of_Nineteen_Eighty-Four#Ministry_of_Truth
36
 */
37
class IndexingCommand extends Command
38
{
39
    /**
40
     * Collected vacancy data storage
41
     * Provides AcceptanceDto instances for indexing or null if storage is empty
42
     *
43
     * @var PitInterface
44
     *
45
     * @see AcceptanceDto
46
     */
47
    private $source;
48
49
    /**
50
     * Delivers a vacancy to the Ministry of Truth for analysis and sanity index calculation
51
     *
52
     * @var Cockroach
53
     */
54
    private $indexer;
55
56
    /**
57
     * CollectingCommand constructor.
58
     *
59
     * @param PitInterface $source  Collected vacancy data storage
60
     * @param Cockroach    $indexer Delivers a vacancy to the Ministry of Truth for sanity index calculation
61
     * @param string|null  $name    The name of the command; passing null means it must be set in configure()
62
     */
63
    public function __construct(PitInterface $source, Cockroach $indexer, ?string $name = null)
64
    {
65
        $this->source  = $source;
66
        $this->indexer = $indexer;
67
68
        parent::__construct($name);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    protected function configure()
75
    {
76
        $this
77
            ->setDescription('Calculates a sanity index for vacancies via "Ministry of Truth" API')
78
            ->addOption(
79
                'iterations',
80
                'i',
81
                InputOption::VALUE_REQUIRED,
82
                'Maximum count of vacancies to proceed for a single run',
83
                10
84
            )
85
        ;
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    protected function execute(InputInterface $input, OutputInterface $output)
92
    {
93
        $iterations = (int) $input->getOption('iterations');
94
95
        $successfulIterations = $this->indexer->deliver($this->source, $iterations);
96
97
        $messageComplete = str_replace(
98
            ['{iterations}', '{successful}'],
99
            [$iterations, $successfulIterations],
100
            'Indexing complete ({iterations} iterations, {successful} successful).'
101
        );
102
        $output->writeln($messageComplete);
103
    }
104
}
105