Completed
Pull Request — master (#11)
by ARCANEDEV
06:50
created

PublishCommand::getArguments()   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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php namespace Arcanedev\LaravelLang\Commands;
2
3
use Arcanedev\LaravelLang\Bases\Command;
4
use Arcanedev\LaravelLang\Contracts\TransPublisher;
5
use Arcanedev\LaravelLang\Exceptions\LangPublishException;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputOption;
8
9
/**
10
 * Class     PublishCommand
11
 *
12
 * @package  Arcanedev\LaravelLang\Commands
13
 * @author   ARCANEDEV <[email protected]>
14
 */
15
class PublishCommand extends Command
16
{
17
    /* ------------------------------------------------------------------------------------------------
18
     |  Properties
19
     | ------------------------------------------------------------------------------------------------
20
     */
21
    /**
22
     * The name and signature of the console command.
23
     *
24
     * @var string
25
     */
26
    protected $signature   = 'trans:publish
27
                                {locale : The language to publish the translations.}
28
                                {--force : Force to override the translations}';
29
30
    /**
31
     * The console command description.
32
     *
33
     * @var string
34
     */
35
    protected $description = 'Publish the [locale] translations.';
36
37
    /**
38
     * The TransPublisher instance.
39
     *
40
     * @var \Arcanedev\LaravelLang\Contracts\TransPublisher
41
     */
42
    private $publisher;
43
44
    /* ------------------------------------------------------------------------------------------------
45
     |  Constructor
46
     | ------------------------------------------------------------------------------------------------
47
     */
48
    /**
49
     * Create a new console command instance.
50
     *
51
     * @param  \Arcanedev\LaravelLang\Contracts\TransPublisher  $publisher
52
     */
53 60
    public function __construct(TransPublisher $publisher)
54
    {
55 60
        $this->publisher = $publisher;
56 60
        $this->name      = 'trans:publish';
57
58 60
        parent::__construct();
59 60
    }
60
61
    /* ------------------------------------------------------------------------------------------------
62
     |  Main Functions
63
     | ------------------------------------------------------------------------------------------------
64
     */
65
    /**
66
     * Execute the console command.
67
     */
68 48
    public function handle()
69
    {
70 48
        $this->copyright();
71
72 48
        $locale = (string) $this->argument('locale');
73 48
        $force  = (bool) $this->option('force');
74
75 48
        if ($this->publisher->isDefault($locale)) {
76 12
            $this->info('The locale [' . $locale . '] is a default lang and it\'s shipped with laravel.');
77 9
        }
78
        else {
79 36
            $this->publish($locale, $force);
80
        }
81
82 48
        $this->line('');
83 48
    }
84
85
    /* ------------------------------------------------------------------------------------------------
86
     |  Other Functions
87
     | ------------------------------------------------------------------------------------------------
88
     */
89
    /**
90
     * Publish the translations.
91
     *
92
     * @param  string  $locale
93
     * @param  bool    $force
94
     */
95 36
    private function publish($locale, $force)
96
    {
97
        try {
98 36
            $this->publisher->publish($locale, $force);
99
100 36
            $this->info('The locale [' . $locale . '] translations were published successfully.');
101
        }
102 30
        catch (LangPublishException $e) {
103 12
            $this->error($e->getMessage());
104
        }
105 36
    }
106
107
    /**
108
     * Get the console command arguments.
109
     *
110
     * @return array
111
     *
112
     * @codeCoverageIgnore
113
     */
114
    protected function getArguments()
115
    {
116
        return [
117
            ['locale', InputArgument::REQUIRED, 'The language to publish the translations.'],
118
        ];
119
    }
120
121
    /**
122
     * Get the console command options.
123
     *
124
     * @return array
125
     *
126
     * @codeCoverageIgnore
127
     */
128
    protected function getOptions()
129
    {
130
        return [
131
            ['force', 'f', InputOption::VALUE_OPTIONAL, 'Force to override the translations', false],
132
        ];
133
    }
134
}
135