Passed
Push — 10.x ( 7ef113...ba9d3e )
by Andrey
13:56
created

Base::filter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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\Console;
21
22
use Helldar\LaravelLangPublisher\Concerns\Ask;
23
use Helldar\LaravelLangPublisher\Concerns\Optionable;
24
use Helldar\LaravelLangPublisher\Concerns\Paths;
25
use Helldar\LaravelLangPublisher\Facades\Helpers\Config;
26
use Helldar\LaravelLangPublisher\Facades\Helpers\Locales;
27
use Illuminate\Console\Command;
28
29
abstract class Base extends Command
30
{
31
    use Ask;
32
    use Optionable;
33
    use Paths;
34
35
    /** @var \Helldar\Contracts\LangPublisher\Processor */
36
    protected $processor;
37
38
    public function handle()
39
    {
40
        $this->resolveProcessor();
41
42
        $this->collecting();
43
44
        $this->finish();
45
    }
46
47
    protected function finish(): void
48
    {
49
        $this->info('Saving changes...');
50
51
        $this->processor->finish();
52
    }
53
54
    protected function resolveProcessor(): void
55
    {
56
        $locales = $this->targetLocales();
57
        $force   = $this->hasForce();
58
59
        $this->processor = new $this->processor($locales, $force);
0 ignored issues
show
Unused Code introduced by
The call to Helldar\Contracts\LangPu...rocessor::__construct() has too many arguments starting with $locales. ( Ignorable by Annotation )

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

59
        $this->processor = /** @scrutinizer ignore-call */ new $this->processor($locales, $force);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
60
    }
61
62
    protected function collecting(): void
63
    {
64
        foreach ($this->plugins() as $provider) {
65
            $this->info('Processing ' . get_class($provider) . '...');
66
67
            $this->processor->handle($provider);
68
        }
69
    }
70
71
    /**
72
     * @return \Helldar\Contracts\LangPublisher\Provider[]
73
     */
74
    protected function plugins(): array
75
    {
76
        return Config::plugins();
77
    }
78
79
    protected function targetLocales(): array
80
    {
81
        return Locales::installed();
82
    }
83
}
84