You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/09/23 11:58:49 UTC

[GitHub] junichi11 commented on a change in pull request #896: [NETBEANS-1276] PHPStan Support

junichi11 commented on a change in pull request #896: [NETBEANS-1276] PHPStan Support
URL: https://github.com/apache/incubator-netbeans/pull/896#discussion_r219696792
 
 

 ##########
 File path: php/php.code.analysis/src/org/netbeans/modules/php/analysis/PHPStanAnalyzerImpl.java
 ##########
 @@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.php.analysis;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.prefs.Preferences;
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.api.annotations.common.StaticResource;
+import org.netbeans.api.fileinfo.NonRecursiveFolder;
+import org.netbeans.modules.analysis.spi.Analyzer;
+import org.netbeans.modules.php.analysis.commands.PHPStan;
+import org.netbeans.modules.php.analysis.options.AnalysisOptions;
+import org.netbeans.modules.php.analysis.ui.analyzer.PHPStanCustomizerPanel;
+import org.netbeans.modules.php.analysis.util.AnalysisUtils;
+import org.netbeans.modules.php.analysis.util.Mappers;
+import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
+import org.netbeans.modules.php.api.util.StringUtils;
+import org.netbeans.modules.refactoring.api.Scope;
+import org.netbeans.spi.editor.hints.ErrorDescription;
+import org.netbeans.spi.editor.hints.HintsController;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.NbBundle;
+import org.openide.util.lookup.ServiceProvider;
+
+public class PHPStanAnalyzerImpl implements Analyzer {
+
+    private static final Logger LOGGER = Logger.getLogger(PHPStanAnalyzerImpl.class.getName());
+    private final Context context;
+    private final AtomicBoolean cancelled = new AtomicBoolean();
+
+    public PHPStanAnalyzerImpl(Context context) {
+        this.context = context;
+    }
+
+    @NbBundle.Messages({
+        "PHPStanAnalyzerImpl.phpStan.error=PHPStan is not valid",
+        "PHPStanAnalyzerImpl.phpStan.error.description=Invalid phpstan set in IDE Options."
+    })
+    @Override
+    public Iterable<? extends ErrorDescription> analyze() {
+        Preferences settings = context.getSettings();
+        if (settings != null && !settings.getBoolean(PHPStanCustomizerPanel.ENABLED, false)) {
+            return Collections.emptyList();
+        }
+
+        PHPStan phpStan = getValidPHPStan();
+        if (phpStan == null) {
+            context.reportAnalysisProblem(
+                    Bundle.PHPStanAnalyzerImpl_phpStan_error(),
+                    Bundle.PHPStanAnalyzerImpl_phpStan_error_description());
+            return Collections.emptyList();
+        }
+
+        String level = getValidPHPStanLevel();
+        FileObject config = getValidPHPStanConfiguration();
+        PHPStanParams phpStanParams = new PHPStanParams()
+                .setLevel(level)
+                .setConfiguration(config);
+        Scope scope = context.getScope();
+
+        Map<FileObject, Integer> fileCount = AnalysisUtils.countPhpFiles(scope);
+        int totalCount = 0;
+        for (Integer count : fileCount.values()) {
+            totalCount += count;
+        }
+
+        context.start(totalCount);
+        try {
+            return doAnalyze(scope, phpStan, phpStanParams, fileCount);
+        } finally {
+            context.finish();
+        }
+    }
+
+    @Override
+    public boolean cancel() {
+        cancelled.set(true);
+        // XXX cancel phpstan ?
 
 Review comment:
   Code Sniffer also has this comment. Actually, `phpstan` command is not canceled here. (If there is the next target, the command is not run for it.) However, users can stop the command in the output window. So, I think we can remove this comment :)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists