Conditions | 11 |
Paths | 11 |
Total Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
28 | public static function within($paths, $composerPath, $composerNamespace, $command) |
||
29 | { |
||
30 | $detailed = $command->option('detailed'); |
||
31 | |||
32 | foreach ($paths as $classFilePath) { |
||
33 | $absFilePath = $classFilePath->getRealPath(); |
||
34 | |||
35 | // exclude blade files |
||
36 | if (Str::endsWith($absFilePath, ['.blade.php'])) { |
||
37 | continue; |
||
38 | } |
||
39 | |||
40 | // exclude migration directories |
||
41 | if (Str::startsWith($absFilePath, LaravelPaths::migrationDirs())) { |
||
42 | continue; |
||
43 | } |
||
44 | |||
45 | if (! self::hasOpeningTag($absFilePath)) { |
||
46 | continue; |
||
47 | } |
||
48 | |||
49 | [ |
||
50 | $currentNamespace, |
||
|
|||
51 | $class, |
||
52 | $type, |
||
53 | $parent, |
||
54 | ] = GetClassProperties::fromFilePath($absFilePath); |
||
55 | |||
56 | // Skip if there is no class/trait/interface definition found. |
||
57 | // For example a route file or a config file. |
||
58 | if (! $class || $parent == 'Migration') { |
||
59 | continue; |
||
60 | } |
||
61 | |||
62 | $detailed && event('microscope.checking', [$classFilePath->getRelativePathname(), $command]); |
||
63 | |||
64 | $relativePath = FilePath::getRelativePath($absFilePath); |
||
65 | $correctNamespace = NamespaceCorrector::calculateCorrectNamespace($relativePath, $composerPath, $composerNamespace); |
||
66 | self::$checkedNamespaces++; |
||
67 | |||
68 | if ($currentNamespace === $correctNamespace) { |
||
69 | continue; |
||
70 | } |
||
71 | |||
72 | self::changedNamespaces($class, $currentNamespace, $correctNamespace); |
||
73 | ErrorPrinter::warnIncorrectNamespace($currentNamespace, $relativePath, $class); |
||
74 | |||
75 | if (! $command->option('nofix') && ErrorPrinter::ask($command, $correctNamespace)) { |
||
76 | self::doNamespaceCorrection($absFilePath, $currentNamespace, $correctNamespace); |
||
77 | // maybe an event listener |
||
78 | app(ErrorPrinter::class)->badNamespace($relativePath, $correctNamespace, $currentNamespace); |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | |||
119 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.