Completed
Push — master ( d5dc6c...9a2ca3 )
by Alejandro
11s
created

UrlShortenerConfigCustomizer::process()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

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