Completed
Push — master ( aca90e...8ef0e7 )
by Alejandro
10s
created

LanguageConfigCustomizer::process()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

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