Completed
Push — master ( b53e51...1009f9 )
by Alejandro
04:13 queued 38s
created

UrlShortenerConfigCustomizerPlugin::process()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 18
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 27
ccs 19
cts 19
cp 1
crap 4
rs 8.5806
1
<?php
2
namespace Shlinkio\Shlink\CLI\Install\Plugin;
3
4
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
5
use Shlinkio\Shlink\Core\Service\UrlShortener;
6
use Symfony\Component\Console\Exception\RuntimeException;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Question\ChoiceQuestion;
10
use Symfony\Component\Console\Question\ConfirmationQuestion;
11
12
class UrlShortenerConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin
13
{
14
    /**
15
     * @param InputInterface $input
16
     * @param OutputInterface $output
17
     * @param CustomizableAppConfig $appConfig
18
     * @return void
19
     * @throws RuntimeException
20
     */
21 3
    public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig)
22
    {
23 3
        $this->printTitle($output, 'URL SHORTENER');
24
25 3
        if ($appConfig->hasUrlShortener() && $this->questionHelper->ask($input, $output, new ConfirmationQuestion(
26
            '<question>Do you want to keep imported URL shortener config? (Y/n):</question> '
27 3
        ))) {
28 1
            return;
29
        }
30
31
        // Ask for URL shortener params
32 2
        $appConfig->setUrlShortener([
33 2
            'SCHEMA' => $this->questionHelper->ask($input, $output, new ChoiceQuestion(
34 2
                '<question>Select schema for generated short URLs (defaults to http):</question>',
35 2
                ['http', 'https'],
36
                0
37 2
            )),
38 2
            'HOSTNAME' => $this->ask($input, $output, 'Hostname for generated URLs'),
39 2
            'CHARS' => $this->ask(
40 2
                $input,
41 2
                $output,
42 2
                'Character set for generated short codes (leave empty to autogenerate one)',
43 2
                null,
44
                true
45 2
            ) ?: str_shuffle(UrlShortener::DEFAULT_CHARS)
46 2
        ]);
47 2
    }
48
}
49