PartialUp   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 52.17 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 24
loc 46
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 24 24 3

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 DigiFactory\PartialDown\Commands;
4
5
use Exception;
6
use Illuminate\Console\Command;
7
use Illuminate\Support\Str;
8
9
class PartialUp extends Command
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'partial-up {part}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Bring specific part of the application out of maintenance mode';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return int
29
     */
30 View Code Duplication
    public function handle()
0 ignored issues
show
Duplication introduced by
This method 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...
31
    {
32
        $part = Str::slug($this->argument('part'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('part') targeting Illuminate\Console\Conce...ractsWithIO::argument() can also be of type array or null; however, Illuminate\Support\Str::slug() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
33
34
        $lockFilename = 'framework/partial-down-'.$part;
35
36
        try {
37
            if (! file_exists(storage_path($lockFilename))) {
38
                $this->comment("This part [{$part}] of the application is already up.");
39
40
                return true;
41
            }
42
43
            unlink(storage_path($lockFilename));
44
45
            $this->info("This part [{$part}] of the application is now live.");
46
        } catch (Exception $e) {
47
            $this->error("Failed to disable maintenance mode for this part [{$part}] of the application.");
48
49
            $this->error($e->getMessage());
50
51
            return 1;
52
        }
53
    }
54
}
55