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) |
|
|
|
|
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 ") { |
|
|
|
|
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 ") { |
|
|
|
|
49
|
|
|
$tokens[$i - 1][1] = "\n "; |
50
|
|
|
Refactor::saveTokens($absFilePath, $tokens); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.