Passed
Push — master ( a1929c...27d925 )
by Dispositif
02:28
created

WorkerCLITrait::autoOrYesConfirmation()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 17
rs 9.9332
1
<?php
2
/*
3
 * This file is part of dispositif/wikibot application (@github)
4
 * 2019-2023 © Philippe M./Irønie  <[email protected]>
5
 * For the full copyright and MIT license information, view the license file.
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Application\Traits;
11
12
use Codedungeon\PHPCliColors\Color;
13
14
/**
15
 * CLI : confirmation, mode auto, colors...
16
 * todo move infra ou lib ?
17
 */
18
trait WorkerCLITrait
19
{
20
    protected function autoOrYesConfirmation(string $question = 'ÉDITION ?'): bool
21
    {
22
        $this->modeAuto = $this->modeAuto ?? false;
1 ignored issue
show
Bug Best Practice introduced by
The property modeAuto does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
        if ($this->modeAuto) {
24
            return true;
25
        }
26
        $ask = readline(Color::LIGHT_MAGENTA . '*** '.$question.' [y/n/auto]' . Color::NORMAL);
27
        if ('auto' === $ask) {
28
            $this->modeAuto = true;
29
30
            return true;
31
        }
32
        if ('y' === $ask) {
33
            return true;
34
        }
35
36
        return false;
37
    }
38
}