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

WorkerCLITrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A autoOrYesConfirmation() 0 17 4
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
}