CheckAll   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 7.32 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 3 32 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 Imanghafoori\LaravelMicroscope\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Str;
7
use Imanghafoori\LaravelMicroscope\ErrorReporters\ErrorPrinter;
8
use Imanghafoori\LaravelMicroscope\Traits\LogsErrors;
9
10
class CheckAll extends Command
11
{
12
    use LogsErrors;
13
14
    protected $signature = 'check:all {--d|detailed : Show files being checked} {--f|force} {--s|nofix : avoids the automatic fixes}';
15
16
    protected $description = 'Run all checks with one command';
17
18
    public function handle(ErrorPrinter $errorPrinter)
19
    {
20
        $t1 = microtime(true);
21
        $errorPrinter->printer = $this->output;
22
23
        // turns off error logging.
24
        $errorPrinter->logErrors = false;
25
26
        $this->call('check:psr4', ['--detailed' => $this->option('detailed'), '--nofix' => $this->option('nofix'), '--force' => $this->option('force')]);
27
        $this->call('check:imports', ['--nofix' => $this->option('nofix'), '--detailed' => $this->option('detailed')]);
28
        $this->call('check:events');
29
        $this->call('check:gates');
30
        $this->call('check:views', ['--detailed' => $this->option('detailed')]);
31
        $this->call('check:routes');
32
        $this->call('check:stringy_classes');
33
        $this->call('check:dd');
34
        $this->call('check:dead_controllers');
35
        $this->call('check:early_returns', ['--nofix' => true]);
36
        $this->call('check:bad_practices');
37
38
        // turns on error logging.
39
        $errorPrinter->logErrors = true;
40
41
        $this->finishCommand($errorPrinter);
42
        $errorPrinter->printer->writeln('time: '.round(microtime(true) - $t1, 2).' (sec)', 2);
43
44 View Code Duplication
        if (random_int(1, 5) == 2 && Str::startsWith(request()->server('argv')[1] ?? '', 'check:al')) {
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...
45
            ErrorPrinter::thanks($this);
46
        }
47
48
        return $errorPrinter->hasErrors() ? 1 : 0;
49
    }
50
}
51