Completed
Pull Request — master (#246)
by Alejandro
05:59
created

AskUtilsTrait::askRequired()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 1
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 3
cts 4
cp 0.75
crap 2.0625
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Installer\Util;
5
6
use Shlinkio\Shlink\Installer\Exception\MissingRequiredOptionException;
7
use Symfony\Component\Console\Style\SymfonyStyle;
8
9
trait AskUtilsTrait
10
{
11
    /**
12
     * @return mixed
13
     */
14 4
    private function askRequired(SymfonyStyle $io, string $optionName, string $question)
15
    {
16
        return $io->ask($question, null, function ($value) use ($optionName) {
17 1
            if (empty($value)) {
18
                throw MissingRequiredOptionException::fromOption($optionName);
19
            };
20
21 1
            return $value;
22 4
        });
23
    }
24
}
25