ActionsUnDocblock::check()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
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