Completed
Pull Request — master (#148)
by Alejandro
04:16
created

UrlShortenerConfigCustomizer::process()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 4.0027

Importance

Changes 0
Metric Value
cc 4
eloc 17
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 26
ccs 17
cts 18
cp 0.9444
crap 4.0027
rs 8.5806
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\CLI\Install\Plugin;
5
6
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig;
7
use Shlinkio\Shlink\Core\Service\UrlShortener;
8
use Symfony\Component\Console\Style\SymfonyStyle;
9
10
class UrlShortenerConfigCustomizer implements ConfigCustomizerInterface
11
{
12
    /**
13
     * @param SymfonyStyle $io
14
     * @param CustomizableAppConfig $appConfig
15
     * @return void
16
     */
17 3
    public function process(SymfonyStyle $io, CustomizableAppConfig $appConfig)
18
    {
19 3
        $io->title('URL SHORTENER');
20
21 3
        if ($appConfig->hasUrlShortener() && $io->confirm('Do you want to keep imported URL shortener config?')) {
22 1
            return;
23
        }
24
25
        // Ask for URL shortener params
26 2
        $appConfig->setUrlShortener([
27 2
            'SCHEMA' => $io->choice(
28 2
                'Select schema for generated short URLs',
29 2
                ['http', 'https'],
30 2
                'http'
31
            ),
32 2
            'HOSTNAME' => $io->ask('Hostname for generated URLs'),
33 2
            'CHARS' => $io->ask(
34 2
                'Character set for generated short codes (leave empty to autogenerate one)',
35 2
                null,
36
                function ($value) {
37
                    return $value;
38 2
                }
39 2
            ) ?: \str_shuffle(UrlShortener::DEFAULT_CHARS),
40 2
            'VALIDATE_URL' => $io->confirm('Do you want to validate long urls by 200 HTTP status code on response'),
41
        ]);
42 2
    }
43
}
44