funivan / phpclean Goto Github PK
View Code? Open in Web Editor NEWStatic Code Analysis for PhpStorm and Intellij Idea.
License: MIT License
Static Code Analysis for PhpStorm and Intellij Idea.
License: MIT License
From java
Reports dangling Javadoc comments. Javadoc comment are dangling if they don't belong to any class, method or field. For example a Javadoc comment in between method declarations that have their own javadoc comments.
Investigate __destruct
method
Produces error "Return type declaration is not allowed"
Current
Public methods should be closed (make methods or class final)
new
Public/protected methods should be closed (make methods or class final)
/** @var ConstraintInterface $constraint */
- this statement should be replaced to the assert
java.lang.IndexOutOfBoundsException: toIndex (2) is greater than size (1).
at kotlin.collections.ArraysKt__ArraysJVMKt.copyOfRangeToIndexCheck(ArraysJVM.kt:49)
at kotlin.collections.ArraysKt___ArraysJvmKt.copyOfRange(_ArraysJvm.kt:1192)
at kotlin.collections.ArraysKt___ArraysKt.slice(_Arrays.kt:3753)
at com.funivan.idea.phpClean.inspections.redundantDocCommentTag.RedundantDocCommentTagInspection$buildVisitor$1.checkComment(RedundantDocCommentTagInspection.kt:43)
at com.funivan.idea.phpClean.inspections.redundantDocCommentTag.RedundantDocCommentTagInspection$buildVisitor$1.visitPhpFunction(RedundantDocCommentTagInspection.kt:36)
at com.funivan.idea.phpClean.inspections.redundantDocCommentTag.RedundantDocCommentTagInspection$buildVisitor$1.visitPhpMethod(RedundantDocCommentTagInspection.kt:24)
at com.jetbrains.php.lang.psi.elements.impl.MethodImpl.accept(MethodImpl.java:89)
at com.intellij.codeInspection.InspectionEngine.acceptElements(InspectionEngine.java:75)
at com.intellij.codeInspection.InspectionEngine.createVisitorAndAcceptElements(InspectionEngine.java:63)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.runToolOnElements(LocalInspectionsPass.java:295)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$null$5(LocalInspectionsPass.java:263)
at com.intellij.util.AstLoadingFilter.forceAllowTreeLoading(AstLoadingFilter.java:156)
at com.intellij.util.AstLoadingFilter.forceAllowTreeLoading(AstLoadingFilter.java:148)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$null$6(LocalInspectionsPass.java:260)
at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:127)
at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:116)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitPriorityElementsAndInit$7(LocalInspectionsPass.java:260)
at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:133)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1166)
at com.intellij.concurrency.ApplierCompleter.lambda$wrapInReadActionAndIndicator$1(ApplierCompleter.java:105)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:586)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:532)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:86)
at com.intellij.concurrency.ApplierCompleter.wrapInReadActionAndIndicator(ApplierCompleter.java:116)
at com.intellij.concurrency.ApplierCompleter.lambda$compute$0(ApplierCompleter.java:96)
at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:164)
at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:218)
at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:96)
at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Your plugin complain on use of $_GET
, $_SERVER
with "Deprecated global variable usage" which is pretty nonsense, as neither $_GET
, nor $_POST
nor $_SERVER
etc are deprecated.
Bad:
do{
// ...
} while (false !== $currentTheme = $currentTheme->getParent($context));
Ok:
do{
/// ...
$currentTheme = $currentTheme->getParent($context)
} while (false !== $currentTheme);
Source: kalessil/phpinspectionsea#662
Invalid /** @var \SimpleXMLElement $doc */
Valid assert($doc instanceof \SimpleXMLElement);
both types should work
/** @var $options \stdClass */
/** @var \stdClass $options */
/**
* @return \Generator|string[] // <-- warning should be ommited here
*/
function items() : \Generator
In file: task-pangrams.php
java.lang.ArrayIndexOutOfBoundsException: 1
at com.funivan.idea.phpClean.inspections.redundantDocCommentTag.RedundantDocCommentTagInspection$buildVisitor$1.visitPhpFunction(RedundantDocCommentTagInspection.kt:28)
at com.jetbrains.php.lang.psi.elements.impl.FunctionImpl.accept(FunctionImpl.java:128)
at com.intellij.codeInspection.InspectionEngine.acceptElements(InspectionEngine.java:75)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$null$8(LocalInspectionsPass.java:319)
at com.intellij.util.AstLoadingFilter.lambda$toComputable$2(AstLoadingFilter.java:169)
at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:127)
at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:116)
at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:111)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitRestElementsAndCleanup$9(LocalInspectionsPass.java:318)
at com.intellij.concurrency.JobLauncherImpl.lambda$null$0(JobLauncherImpl.java:128)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:582)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:532)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:86)
at com.intellij.concurrency.JobLauncherImpl.lambda$processImmediatelyIfTooFew$1(JobLauncherImpl.java:124)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:942)
at com.intellij.concurrency.JobLauncherImpl.processImmediatelyIfTooFew(JobLauncherImpl.java:135)
at com.intellij.concurrency.JobLauncherImpl.invokeConcurrentlyUnderProgress(JobLauncherImpl.java:57)
at com.intellij.concurrency.JobLauncher.invokeConcurrentlyUnderProgress(JobLauncher.java:56)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.visitRestElementsAndCleanup(LocalInspectionsPass.java:331)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.inspect(LocalInspectionsPass.java:201)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.doInspectInBatch(LocalInspectionsPass.java:133)
at com.intellij.codeInspection.ex.GlobalInspectionContextImpl.inspectFile(GlobalInspectionContextImpl.java:572)
at com.intellij.codeInspection.ex.GlobalInspectionContextImpl.lambda$null$2(GlobalInspectionContextImpl.java:453)
at com.intellij.openapi.project.DumbService.lambda$runReadActionInSmartMode$0(DumbService.java:98)
at com.intellij.openapi.project.DumbService.lambda$runReadActionInSmartMode$1(DumbService.java:142)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:976)
at com.intellij.openapi.application.ReadAction.compute(ReadAction.java:57)
at com.intellij.openapi.project.DumbService.runReadActionInSmartMode(DumbService.java:135)
at com.intellij.openapi.project.DumbService.runReadActionInSmartMode(DumbService.java:98)
at com.intellij.openapi.project.DumbService.tryRunReadActionInSmartMode(DumbService.java:116)
at com.intellij.codeInspection.ex.GlobalInspectionContextImpl.lambda$runTools$7(GlobalInspectionContextImpl.java:444)
at com.intellij.concurrency.JobLauncherImpl$1MyTask.lambda$call$0(JobLauncherImpl.java:304)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:582)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:532)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:86)
at com.intellij.concurrency.JobLauncherImpl$1MyTask.call(JobLauncherImpl.java:291)
at com.intellij.concurrency.JobLauncherImpl$1MyTask.call(JobLauncherImpl.java:281)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
First iteration: catch in short tags
<?= $user ?> // Fire error if user is not scalar
Hi,
There are some other patterns that could be matched with the __toString inspection
None of the following are matched:
<?php
class a{
public function __toString()
{
$debug = debug_backtrace();
echo "__toString called on line ".$debug['0']['line']."\n";
return "";
}
}
function string_param(string $a){
}
function object_param(object $a){
echo $a; //here
(string)$a; //here
$a == "0"; //here
string_param($a); //here
?><?= $a; ?><?php //here
}
$a = new a();
$a == "0"; //here
string_param($a); //here
object_param($a);
If it help, I can try to create a PR with failing tests.
Thanks!
Automerge https://mergify.io/#how-it-works
Hi! Currently I have a problem where the method from the closed library gets overloaded, when a child class is inherited from it we are in one of two situations:
It is recommended, that in such case or any other where parameter or return definition is not possible (e.g. parameter taking both string and integer) it is possible to silence the inspections with the annotation. Example of such implementation may be:
/**
* @param string $psRequest **@suppress(MissingParameterTypeInspection)**
* @param string $prTarget **@suppress(MissingParameterTypeInspection)**
* ......
* @return mixed|string
* @throws SoapFault
*/
function __doRequest($psRequest, $prTarget, ...) {
In a perfect world, it would be possible to also have a parameter that specify a regexp expression as parameter of the inspection, following variations of Hungarian Notation coding standards, that would match parameters of particular pattern to be excluded for the type requirement in my case all this parameters would be e.g. pm% and functions fm% prefixed - that would always be excluded from type missing inspection.
__destruct
__call
Protected properties can be changed to private if class does not have super and child classes
+ is not abstract
interface Named {
function name() : string;
}
class User implements Named {
function name():string;
}
$u = new User();
echo $u->name(); // <-- error goes here. Check it
```
Maybe we should add an option to this inspection
Hi, I just got an error in the Plugin reported by PHPStorm.
It is reproductible with the following code:
<?php
class test
{
public function a(<caret>){
}
}
Type the character "," in the caret position
Here is the complete error log:
java.lang.Throwable: Empty PSI elements must not be passed to createDescriptor. Start: Parameter, end: Parameter, startContainingFile: PHP file
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:134)
at com.intellij.codeInspection.ProblemDescriptorBase.(ProblemDescriptorBase.java:61)
at com.intellij.codeInspection.InspectionManagerBase.createProblemDescriptor(InspectionManagerBase.java:83)
at com.intellij.codeInspection.InspectionManagerBase.createProblemDescriptor(InspectionManagerBase.java:72)
at com.intellij.codeInspection.ProblemsHolder.registerProblem(ProblemsHolder.java:66)
at com.intellij.codeInspection.ProblemsHolder.registerProblem(ProblemsHolder.java:59)
at com.funivan.idea.phpClean.inspections.missingParameterType.MissingParameterTypeDeclarationInspection$buildVisitor$1.visitPhpMethod(MissingParameterTypeDeclarationInspection.kt:27)
at com.jetbrains.php.lang.psi.elements.impl.MethodImpl.accept(MethodImpl.java:89)
at com.intellij.codeInspection.InspectionEngine.acceptElements(InspectionEngine.java:75)
at com.intellij.codeInspection.InspectionEngine.createVisitorAndAcceptElements(InspectionEngine.java:63)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.runToolOnElements(LocalInspectionsPass.java:292)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$null$5(LocalInspectionsPass.java:260)
at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:126)
at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:115)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitPriorityElementsAndInit$6(LocalInspectionsPass.java:257)
at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:133)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1163)
at com.intellij.concurrency.ApplierCompleter.lambda$wrapInReadActionAndIndicator$1(ApplierCompleter.java:105)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:582)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:532)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:87)
at com.intellij.concurrency.ApplierCompleter.wrapInReadActionAndIndicator(ApplierCompleter.java:116)
at com.intellij.concurrency.ApplierCompleter.lambda$compute$0(ApplierCompleter.java:96)
at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:147)
at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:222)
at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:96)
at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.pollAndExecCC(ForkJoinPool.java:1190)
at java.util.concurrent.ForkJoinPool.helpComplete(ForkJoinPool.java:1879)
at java.util.concurrent.ForkJoinPool.awaitJoin(ForkJoinPool.java:2045)
at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:390)
at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:719)
at java.util.concurrent.ForkJoinPool.invoke(ForkJoinPool.java:2616)
at com.intellij.concurrency.JobLauncherImpl.invokeConcurrentlyUnderProgress(JobLauncherImpl.java:65)
at com.intellij.concurrency.JobLauncher.invokeConcurrentlyUnderProgress(JobLauncher.java:56)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.visitPriorityElementsAndInit(LocalInspectionsPass.java:263)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.inspect(LocalInspectionsPass.java:196)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.collectInformationWithProgress(LocalInspectionsPass.java:115)
at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:84)
at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:69)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$null$1(PassExecutorService.java:423)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1168)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:416)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:582)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:532)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:87)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:415)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:391)
at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:147)
at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:222)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:389)
at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:161)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Dependabot couldn't find a build.gradle for this project.
Dependabot requires a build.gradle to evaluate your project's current Java dependencies. It had expected to find one at the path: /build.gradle
.
If this isn't a Java project, or if it is a library, you may wish to disable updates for it from within Dependabot.
You can mention @dependabot in the comments below to contact the Dependabot team.
w: PluginCheckTest.kt: (5, 24): 'Assert' is deprecated. Deprecated in Java
w: PluginCheckTest.kt: (13, 13): 'Assert' is deprecated. Deprecated in Java
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
Suggest to call __toString
fail case:
new class extends \DateTime {
public function modify($modify) : self
{
// somenting...
parent::modify($modify);
}
}
class someClass {
public function __toString(){
}
public static function create() : self{
}
}
SomeClass::create() // <--- error should be here
Specify functions in the configuration panel.
For example we can deprecate array_merge function.
Specify tags in the configuration.
/**
* @property string $user // <-- warning should be here
*/
Dependabot couldn't find a build.gradle for this project.
Dependabot requires a build.gradle to evaluate your project's current Java dependencies. It had expected to find one at the path: /build.gradle
.
If this isn't a Java project, or if it is a library, you may wish to disable updates for it from within Dependabot.
You can mention @dependabot in the comments below to contact the Dependabot team.
class HelloPhrase {
function __toString(){
return 'Hi'
}
}
function hi() : HelloPhrase {
return new HelloPhrase();
}
echo hi(); // <-- warning should be here
Hey!
I'm not sure if you're interested in supporting PHP versions < 7 with this plugin, or even if you're interested in suggestions, but I'll give it a try!
We have a big legacy code at work who run in PHP 5.3 for now. We're in the process of migrating to PHP 7.2 but it's a big project and it's not the main preoccupation when there's business who need new features.
To make sure we won't break anything, we began with a lot of code cleaning. PhpStorm helped a lot with that, and PHP EA helped very much too. I like your plugin for personnal projects but except "PhpClean undefined method" inspection, it's not very relevant with our work codebase. For starters, it suggest adding return types and scalar type hints when our PHP version don't allow it yet, so we had to disable those inspections
However, we would need a similar inspection to make our code cleaner. We have a lot of code like this:
class foo{
function bar($var){
$var->do_a_thing();
}
}
While we generally have types in PHPDoc, we don't have a lot of type hints. It's a shame because we can't always be sure we receive an object in the method (some methods can receive multiple types, including scalars).
So what we would need is an inspection that tell us to add a type hint only when the parameter seem to be used as an object directly.
For example, the previous code would be flagged, but ideally this would not:
class foo{
function bar($var){
if(!is_object($var)){
echo $var;
}
$var->do_a_thing();
}
}
The Quickfix could be to just add object before the variable name, but the warning only should be enough.
Feel free to close if it's too specific or if you're not interested in old PHP versions :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.