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

LanguageConfigCustomizer::chooseLanguage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
rs 10
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