PublishTranslationCommand::publishAll()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Rawilk\LaravelModules\Commands\Other;
4
5
use Illuminate\Console\Command;
6
use Rawilk\LaravelModules\Module;
7
use Rawilk\LaravelModules\Publishing\LangPublisher;
8
9
class PublishTranslationCommand extends Command
10
{
11
    /** @var string */
12
    protected $signature = 'module:publish-translation
13
                            {module? : The name of the module to publish translations for}';
14
15
    /** @var string */
16
    protected $description = 'Publish the translations for a module.';
17
18
    public function handle(): void
19
    {
20
        if ($name = $this->argument('module')) {
21
            $this->publish($name);
22
23
            return;
24
        }
25
26
        $this->publishAll();
27
    }
28
29
    private function publish($name): void
30
    {
31
        $module = $name instanceof Module
32
            ? $name
33
            : $this->laravel['modules']->findOrFail($name);
34
35
        with(new LangPublisher($module))
36
            ->setRepository($this->laravel['modules'])
37
            ->setConsole($this)
38
            ->publish();
39
40
        $this->line("<info>Published Translations</info>: {$module->getStudlyName()}");
41
    }
42
43
    private function publishAll(): void
44
    {
45
        /** @var \Rawilk\LaravelModules\Module $module */
46
        foreach ($this->laravel['modules']->allEnabled() as $module) {
47
            $this->publish($module);
48
        }
49
    }
50
}
51