Completed
Pull Request — master (#16)
by
unknown
01:26
created

RouteTranslationsClearCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
dl 5
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace RichanFongdasen\I18n\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
use RichanFongdasen\I18n\Traits\TranslatedRouteCommandContext;
8
9 View Code Duplication
class RouteTranslationsClearCommand extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    use TranslatedRouteCommandContext;
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'route:trans:clear';
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Remove the translated route cache files for each locale';
24
    /**
25
     * The filesystem instance.
26
     *
27
     * @var \Illuminate\Filesystem\Filesystem
28
     */
29
    protected $files;
30
    /**
31
     * Create a new route clear command instance.
32
     *
33
     * @param  \Illuminate\Filesystem\Filesystem  $files
34
     */
35
    public function __construct(Filesystem $files)
36
    {
37
        parent::__construct();
38
        $this->files = $files;
39
    }
40
    /**
41
     * Execute the console command.
42
     *
43
     * @return void
44
     */
45
    public function handle()
46
    {
47
        foreach ($this->getSupportedLocales() as $locale) {
48
            $path = $this->makeLocaleRoutesPath($locale);
49
            if ($this->files->exists($path)) {
50
                $this->files->delete($path);
51
            }
52
        }
53
        $path = $this->laravel->getCachedRoutesPath();
54
        if ($this->files->exists($path)) {
55
            $this->files->delete($path);
56
        }
57
        $this->info('Route caches for locales cleared!');
58
    }
59
}
60