Completed
Push — feature/specific-replay/create... ( d40997 )
by A.
04:27
created

ReplaySpecificEventsCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 45
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
B execute() 0 35 2
1
<?php
2
3
/**
4
 * Copyright 2017 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupMiddleware\MiddlewareBundle\Console\Command;
20
21
use Symfony\Component\Console\Command\Command;
22
use Symfony\Component\Console\Helper\FormatterHelper;
23
use Symfony\Component\Console\Helper\QuestionHelper;
24
use Symfony\Component\Console\Input\InputInterface;
25
use Symfony\Component\Console\Output\OutputInterface;
26
use Symfony\Component\Console\Question\ConfirmationQuestion;
27
28
class ReplaySpecificEventsCommand extends Command
29
{
30
    protected function configure()
31
    {
32
        $this
33
            ->setName('middleware:event:specific_replay')
34
            ->setDescription('replay specified events for specified projectors');
35
    }
36
37
    public function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        /** @var FormatterHelper $formatter */
40
        $formatter = $this->getHelper('formatter');
41
42
        /** @var QuestionHelper $interrogator */
43
        $interrogator = $this->getHelper('question');
44
45
        $output->writeln(['', $formatter->formatBlock([
46
            '',
47
            'WARNING!!!!',
48
            '',
49
            'You are about to WIPE all read data and recreate all data based on chosen events and projectors.',
50
            '',
51
            'This can take a while and should not be interrupted',
52
            ''
53
        ], 'error'), '']);
54
        $question = "Are you sure you wish to continue? (y/N)";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Are you sure you wish to continue? (y/N) does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
55
56
        $question = sprintf($question, 'error', 'error');
57
        $areYouSure = new ConfirmationQuestion(sprintf("<question>%s</question>\n", $question), false);
58
        if (!$interrogator->ask($input, $output, $areYouSure)) {
59
            $output->writeln('<comment>Replay cancelled!</comment>');
60
61
            return;
62
        }
63
64
        $output->writeln(['',$formatter->formatBlock('Starting Event Replay', 'info')]);
65
        $output->writeln(
66
            $formatter->formatBlock(' >> If it is interrupted it must be rerun till completed', 'comment')
67
        );
68
69
        // ensures the progressbar doesn't overwrite the messages above
70
        $output->writeln(['','',''], 'info');
71
    }
72
}
73