Completed
Pull Request — master (#220)
by Alejandro
03:53 queued 01:02
created

UrlShortenerConfigCustomizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 26 4
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