Passed
Pull Request — main (#153)
by Andrey
30:18 queued 15:26
created

Ask::getAllLocales()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the "andrey-helldar/laravel-lang-publisher" project.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @author Andrey Helldar <[email protected]>
10
 *
11
 * @copyright 2021 Andrey Helldar
12
 *
13
 * @license MIT
14
 *
15
 * @see https://github.com/andrey-helldar/laravel-lang-publisher
16
 */
17
18
declare(strict_types=1);
19
20
namespace Helldar\LaravelLangPublisher\Concerns;
21
22
use Helldar\LaravelLangPublisher\Facades\Helpers\Locales;
23
use Helldar\Support\Facades\Helpers\Arr;
24
use Helldar\Support\Facades\Helpers\Str;
25
26
trait Ask
27
{
28 62
    protected function getLocales(): array
29
    {
30 62
        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

30
        if ($locales = $this->/** @scrutinizer ignore-call */ argument('locales')) {
Loading history...
31 62
            return $this->resolveSelectedLocales($locales);
32
        }
33
34 6
        return $this->askLocales($this->getMethod());
35
    }
36
37 6
    protected function askLocales(string $method): array
38
    {
39 6
        $locales = $this->confirm("Do you want to $method all localizations?") ? $this->getAllLocales() : $this->selectLocales($method);
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

39
        $locales = $this->/** @scrutinizer ignore-call */ confirm("Do you want to $method all localizations?") ? $this->getAllLocales() : $this->selectLocales($method);
Loading history...
Bug introduced by
It seems like getAllLocales() 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

39
        $locales = $this->confirm("Do you want to $method all localizations?") ? $this->/** @scrutinizer ignore-call */ getAllLocales() : $this->selectLocales($method);
Loading history...
40
41 6
        return $this->resolveSelectedLocales($locales);
42
    }
43
44 6
    protected function selectLocales(string $method)
45
    {
46 6
        return $this->choice("Select localizations to $method (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

46
        return $this->/** @scrutinizer ignore-call */ choice("Select localizations to $method (specify the necessary localizations separated by commas):", $this->getAllLocales(), null, null, true);
Loading history...
47
    }
48
49 62
    protected function resolveSelectedLocales($locales): array
50
    {
51 62
        $locales = Arr::wrap($locales);
52
53 62
        return $this->validatedLocales($locales);
54
    }
55
56 6
    protected function getMethod(): string
57
    {
58 6
        $name = class_basename(static::class);
59
60 6
        return Str::lower($name);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Helldar\Support\F...lpers\Str::lower($name) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
61
    }
62
63 62
    protected function validatedLocales(array $locales): array
64
    {
65 62
        foreach ($locales as $locale) {
66 62
            Locales::validate($locale);
67
        }
68
69 62
        return $locales;
70
    }
71
}
72