SettingsClear   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 16.07 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 1
cbo 1
dl 9
loc 56
ccs 18
cts 18
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 9 24 2

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 Merodiro\Settings\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\Cache;
7
use Merodiro\Settings\Facades\Settings;
8
9
class SettingsClear extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'settings:clear {--model=}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Clear settings cache';
24
25
    /**
26
     * Create a new command instance.
27
     *
28
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
29
     */
30 44
    public function __construct()
31
    {
32 44
        parent::__construct();
33 44
    }
34
35
    /**
36
     * Execute the console command.
37
     *
38
     * @return mixed
39
     */
40 4
    public function handle()
41
    {
42 4
        $this->comment('Clearing settings cache.');
43
44 4
        Settings::all()->each(function ($value, $key) {
45 2
            $cache_key = Settings::cacheKey($key);
46
47 2
            Cache::forget($cache_key);
48 4
        });
49
50 4
        $model = $this->option('model');
51
52 4 View Code Duplication
        if (isset($model)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
53
            (new $model)->all()->each(function ($user) {
54 2
                $user->allSettings()->each(function ($value, $key) use ($user) {
55 2
                    $cache_key = $user->settingsCacheKey($key);
56
57 2
                    Cache::forget($cache_key);
58 2
                });
59 2
            });
60
        }
61
62 4
        $this->info('Cleared  settings cache.');
63 4
    }
64
}
65