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

RouteTranslationsClearCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 51
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A handle() 14 14 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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