ActionsUnDocblock::removeGenericDocBlocks()   B
last analyzed

Complexity

Conditions 11
Paths 21

Size

Total Lines 34

Duplication

Lines 8
Ratio 23.53 %

Importance

Changes 0
Metric Value
cc 11
nc 21
nop 2
dl 8
loc 34
rs 7.3166
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Imanghafoori\LaravelMicroscope\Checks;
4
5
use Illuminate\Support\Str;
6
use Imanghafoori\LaravelMicroscope\Analyzers\Refactor;
7
8
class ActionsUnDocblock
9
{
10
    public static $command;
11
12
    public static function check($tokens, $absFilePath, $classFilePath, $psr4Path, $psr4Namespace)
0 ignored issues
show
Unused Code introduced by
The parameter $absFilePath is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
13
    {
14
        $fullNamespace = RoutelessActions::getFullNamespace($classFilePath, $psr4Path, $psr4Namespace);
15
16
        if (RoutelessActions::isLaravelController($fullNamespace)) {
17
            self::removeGenericDocBlocks($tokens, $classFilePath->getRealpath());
18
        }
19
    }
20
21
    private static function removeGenericDocBlocks($tokens, $absFilePath)
22
    {
23
        foreach ($tokens as $i => $token) {
24
            if ($token[0] == T_DOC_COMMENT) {
25
                if (Str::contains($token[1], [
26
                    'Remove the specified resource from storage.',
27
                    'Update the specified resource in storage.',
28
                    'Store a newly created resource in storage.',
29
                    'Display the specified resource.',
30
                    'Display a listing of the resource.',
31
                    'Show the form for creating a new resource.',
32
                    'Show the form for editing the specified resource.',
33
                ])) {
34
                    unset($tokens[$i]);
35
                    if ($tokens[$i + 1][0] == T_WHITESPACE) {
36
                        unset($tokens[$i + 1]);
37
                    }
38
                    Refactor::saveTokens($absFilePath, $tokens);
39
                }
40
            }
41
42
            if (\in_array($token[0], [T_PUBLIC, T_PRIVATE, T_PROTECTED]) && ($tokens[$i - 1][0] == T_WHITESPACE)) {
43 View Code Duplication
                if (($tokens[$i - 2][0] == '}') && $tokens[$i - 1][1] != "\n\n    ") {
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...
44
                    $tokens[$i - 1][1] = "\n\n    ";
45
                    Refactor::saveTokens($absFilePath, $tokens);
46
                }
47
48 View Code Duplication
                if (($tokens[$i - 2][0] == '{') && $tokens[$i - 1][1] != "\n    ") {
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...
49
                    $tokens[$i - 1][1] = "\n    ";
50
                    Refactor::saveTokens($absFilePath, $tokens);
51
                }
52
            }
53
        }
54
    }
55
}
56