Passed
Push — 10.x ( 912076...7ef113 )
by Andrey
12:30
created

Ask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 7
c 1
b 0
f 0
dl 0
loc 21
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A askLocales() 0 9 3
A getAllLocales() 0 3 1
A selectLocales() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Helldar\LaravelLangPublisher\Concerns;
6
7
use Helldar\LaravelLangPublisher\Facades\Helpers\Locales;
8
use Helldar\Support\Facades\Helpers\Arr;
9
10
trait Ask
11
{
12
    protected function askLocales(string $method): array
13
    {
14
        if ($locales = $this->argument('locales')) {
0 ignored issues
show
Bug introduced by
It seems like argument() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
        if ($locales = $this->/** @scrutinizer ignore-call */ argument('locales')) {
Loading history...
15
            return Arr::wrap($locales);
16
        }
17
18
        $locales = $this->confirm("Do you want to $method all localizations?") ? $this->getAllLocales() : $this->selectLocales();
0 ignored issues
show
Bug introduced by
It seems like confirm() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        $locales = $this->/** @scrutinizer ignore-call */ confirm("Do you want to $method all localizations?") ? $this->getAllLocales() : $this->selectLocales();
Loading history...
19
20
        return Arr::wrap($locales);
21
    }
22
23
    protected function getAllLocales(): array
24
    {
25
        return Locales::available();
26
    }
27
28
    protected function selectLocales()
29
    {
30
        return $this->choice('What languages to add? (specify the necessary localizations separated by commas)', $this->getAllLocales(), null, null, true);
0 ignored issues
show
Bug introduced by
It seems like choice() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        return $this->/** @scrutinizer ignore-call */ choice('What languages to add? (specify the necessary localizations separated by commas)', $this->getAllLocales(), null, null, true);
Loading history...
31
    }
32
}
33