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

UrlShortenerConfigCustomizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 34
ccs 17
cts 18
cp 0.9444
rs 10
wmc 4
lcom 0
cbo 1

1 Method

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