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

LanguageConfigCustomizer::process()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 2
dl 0
loc 13
rs 9.8333
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\Installer\Model\CustomizableAppConfig;
7
use Symfony\Component\Console\Style\SymfonyStyle;
8
9
class LanguageConfigCustomizer implements ConfigCustomizerInterface
10
{
11
    private const SUPPORTED_LANGUAGES = ['en', 'es'];
12
13
    public function process(SymfonyStyle $io, CustomizableAppConfig $appConfig): void
14
    {
15
        $io->title('LANGUAGE');
16
17
        if ($appConfig->hasLanguage() && $io->confirm('Do you want to keep imported language?')) {
18
            return;
19
        }
20
21
        $appConfig->setLanguage([
22
            'DEFAULT' => $this->chooseLanguage('Select default language for the application in general', $io),
23
            'CLI' => $this->chooseLanguage('Select default language for CLI executions', $io),
24
        ]);
25
    }
26
27
    private function chooseLanguage(string $message, SymfonyStyle $io): string
28
    {
29
        return $io->choice($message, self::SUPPORTED_LANGUAGES, self::SUPPORTED_LANGUAGES[0]);
30
    }
31
}
32