Completed
Pull Request — master (#17)
by ARCANEDEV
04:24
created

PublishCommand::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php namespace Arcanedev\LaravelLang\Commands;
2
3
use Arcanedev\LaravelLang\Contracts\TransPublisher;
4
use Arcanedev\LaravelLang\Exceptions\LangPublishException;
5
6
/**
7
 * Class     PublishCommand
8
 *
9
 * @package  Arcanedev\LaravelLang\Commands
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class PublishCommand extends AbstractCommand
13
{
14
    /* -----------------------------------------------------------------
15
     |  Properties
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * The name and signature of the console command.
21
     *
22
     * @var string
23
     */
24
    protected $signature   = 'trans:publish
25
                                {locale : The language to publish the translations.}
26
                                {--force : Force to override the translations}';
27
28
    /**
29
     * The console command description.
30
     *
31
     * @var string
32
     */
33
    protected $description = 'Publish the [locale] translations.';
34
35
    /**
36
     * The TransPublisher instance.
37
     *
38
     * @var \Arcanedev\LaravelLang\Contracts\TransPublisher
39
     */
40
    private $publisher;
41
42
    /* -----------------------------------------------------------------
43
     |  Constructor
44
     | -----------------------------------------------------------------
45
     */
46
47
    /**
48
     * Create a new console command instance.
49
     *
50
     * @param  \Arcanedev\LaravelLang\Contracts\TransPublisher  $publisher
51
     */
52 15
    public function __construct(TransPublisher $publisher)
53
    {
54 15
        $this->publisher = $publisher;
55 15
        $this->name      = 'trans:publish';
56
57 15
        parent::__construct();
58 15
    }
59
60
    /* -----------------------------------------------------------------
61
     |  Main Methods
62
     | -----------------------------------------------------------------
63
     */
64
65
    /**
66
     * Execute the console command.
67
     */
68 12
    public function handle()
69
    {
70 12
        $this->copyright();
71
72 12
        $locale = (string) $this->argument('locale');
73
74 12
        if ($this->publisher->isDefault($locale))
75 6
            $this->info("The locale [{$locale}] is a default lang and it's shipped with laravel.");
76
        else
77 9
            $this->publish($locale, (bool) $this->option('force'));
78
79 12
        $this->line('');
80 12
    }
81
82
    /* -----------------------------------------------------------------
83
     |  Other Methods
84
     | -----------------------------------------------------------------
85
     */
86
87
    /**
88
     * Publish the translations.
89
     *
90
     * @param  string  $locale
91
     * @param  bool    $force
92
     */
93 9
    private function publish($locale, $force)
94
    {
95
        try {
96 9
            $this->publisher->publish($locale, $force);
97
98 9
            $this->info("The locale [{$locale}] translations were published successfully.");
99
        }
100 5
        catch (LangPublishException $e) {
101 3
            $this->error($e->getMessage());
102
        }
103 9
    }
104
}
105