{"action":"created","comment":{"url":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls/comments/42387347","id":42387347,"diff_hunk":"@@ -0,0 +1,168 @@\n+/*\n+ * SonarQube PHP Plugin\n+ * Copyright (C) 2010 SonarSource and Akram Ben Aissi\n+ * sonarqube@googlegroups.com\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 3 of the License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ * Lesser General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02\n+ */\n+package org.sonar.php.metrics;\n+\n+import org.sonar.api.batch.SensorContext;\n+import org.sonar.api.batch.fs.FileSystem;\n+import org.sonar.api.batch.fs.InputFile;\n+import org.sonar.api.issue.NoSonarFilter;\n+import org.sonar.api.measures.CoreMetrics;\n+import org.sonar.api.measures.FileLinesContextFactory;\n+import org.sonar.api.measures.Metric;\n+import org.sonar.api.measures.PersistenceMode;\n+import org.sonar.api.measures.RangeDistributionBuilder;\n+import org.sonar.plugins.php.api.tree.Tree;\n+import org.sonar.plugins.php.api.tree.Tree.Kind;\n+import org.sonar.plugins.php.api.visitors.CheckContext;\n+import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck;\n+\n+import java.util.ArrayList;\n+import java.util.Arrays;\n+import java.util.List;\n+\n+public class MetricsVisitor extends PHPSubscriptionCheck {\n+\n+  private static final Number[] LIMITS_COMPLEXITY_FUNCTIONS = {1, 2, 4, 6, 8, 10, 12, 20, 30};\n+  private static final Number[] FILES_DISTRIBUTION_BOTTOM_LIMITS = {0, 5, 10, 20, 30, 60, 90};\n+\n+  private static final Kind[] FUNCTION_NODES = {\n+    Kind.FUNCTION_DECLARATION,\n+    Kind.FUNCTION_EXPRESSION,\n+    Kind.METHOD_DECLARATION,\n+  };\n+\n+  private final FileSystem fs;\n+  private final SensorContext sensorContext;\n+  private InputFile inputFile;\n+  private NoSonarFilter noSonarFilter;\n+  private FileLinesContextFactory fileLinesContextFactory;\n+\n+  private int classComplexity;\n+  private int functionComplexity;\n+  private RangeDistributionBuilder functionComplexityDistribution;\n+  private RangeDistributionBuilder fileComplexityDistribution;\n+\n+  public MetricsVisitor(FileSystem fs, SensorContext context, NoSonarFilter noSonarFilter, FileLinesContextFactory fileLinesContextFactory) {\n+    this.fs = fs;\n+    this.sensorContext = context;\n+    this.noSonarFilter = noSonarFilter;\n+    this.fileLinesContextFactory = fileLinesContextFactory;\n+  }\n+\n+  @Override\n+  public List<Kind> nodesToVisit() {\n+    List<Kind> result = new ArrayList<>(Arrays.asList(FUNCTION_NODES));\n+    result.add(Kind.CLASS_DECLARATION);\n+    result.add(Kind.COMPILATION_UNIT);\n+    return result;\n+  }\n+\n+  @Override\n+  public void visitNode(Tree tree) {\n+    if (tree.is(Kind.COMPILATION_UNIT)) {\n+      classComplexity = 0;\n+      functionComplexity = 0;\n+      functionComplexityDistribution = new RangeDistributionBuilder(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, LIMITS_COMPLEXITY_FUNCTIONS);\n+      fileComplexityDistribution = new RangeDistributionBuilder(CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION, FILES_DISTRIBUTION_BOTTOM_LIMITS);\n+      inputFile = fs.inputFile(fs.predicates().is(context().file()));\n+\n+    } else if (tree.is(Kind.CLASS_DECLARATION)) {\n+      classComplexity += NewComplexityVisitor.complexity(tree);\n+\n+    } else if (tree.is(FUNCTION_NODES)) {\n+      int currentFunctionComplexity = NewComplexityVisitor.complexityWithoutNestedFunctions(tree);\n+      functionComplexity += currentFunctionComplexity;\n+      functionComplexityDistribution.add(currentFunctionComplexity);\n+    }\n+  }\n+\n+  @Override\n+  public void leaveNode(Tree tree) {\n+    if (tree.is(Kind.COMPILATION_UNIT)) {\n+      saveComplexityMetrics(context());\n+      saveCounterMetrics(context());\n+      saveLineMetrics(context());\n+    }\n+  }\n+\n+  private void saveCounterMetrics(CheckContext context) {","path":"php-frontend/src/main/java/org/sonar/php/metrics/MetricsVisitor.java","position":105,"original_position":105,"commit_id":"d0ea29687c658c85a1c71bb829ce1d8d05bc5229","original_commit_id":"d0ea29687c658c85a1c71bb829ce1d8d05bc5229","user":{"login":"SonarTech","id":1842438,"avatar_url":"https://avatars.githubusercontent.com/u/1842438?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarTech","html_url":"https://github.com/SonarTech","followers_url":"https://api.github.com/users/SonarTech/followers","following_url":"https://api.github.com/users/SonarTech/following{/other_user}","gists_url":"https://api.github.com/users/SonarTech/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarTech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarTech/subscriptions","organizations_url":"https://api.github.com/users/SonarTech/orgs","repos_url":"https://api.github.com/users/SonarTech/repos","events_url":"https://api.github.com/users/SonarTech/events{/privacy}","received_events_url":"https://api.github.com/users/SonarTech/received_events","type":"User","site_admin":false},"body":"![MAJOR](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/severity-major.png) Make \"saveCounterMetrics\" a \"static\" method. [![rule](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/rule.png)](https://dory.internal.sonarsource.com/coding_rules#rule_key=squid%3AS2325)\n","created_at":"2015-10-19T15:42:41Z","updated_at":"2015-10-19T15:42:41Z","html_url":"https://github.com/SonarCommunity/sonar-php/pull/66#discussion_r42387347","pull_request_url":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls/66","_links":{"self":{"href":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls/comments/42387347"},"html":{"href":"https://github.com/SonarCommunity/sonar-php/pull/66#discussion_r42387347"},"pull_request":{"href":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls/66"}}},"pull_request":{"url":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls/66","id":48071125,"html_url":"https://github.com/SonarCommunity/sonar-php/pull/66","diff_url":"https://github.com/SonarCommunity/sonar-php/pull/66.diff","patch_url":"https://github.com/SonarCommunity/sonar-php/pull/66.patch","issue_url":"https://api.github.com/repos/SonarCommunity/sonar-php/issues/66","number":66,"state":"open","locked":false,"title":"SONARPHP-497 Migrate metrics computation","user":{"login":"vilchik-elena","id":10108186,"avatar_url":"https://avatars.githubusercontent.com/u/10108186?v=3","gravatar_id":"","url":"https://api.github.com/users/vilchik-elena","html_url":"https://github.com/vilchik-elena","followers_url":"https://api.github.com/users/vilchik-elena/followers","following_url":"https://api.github.com/users/vilchik-elena/following{/other_user}","gists_url":"https://api.github.com/users/vilchik-elena/gists{/gist_id}","starred_url":"https://api.github.com/users/vilchik-elena/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vilchik-elena/subscriptions","organizations_url":"https://api.github.com/users/vilchik-elena/orgs","repos_url":"https://api.github.com/users/vilchik-elena/repos","events_url":"https://api.github.com/users/vilchik-elena/events{/privacy}","received_events_url":"https://api.github.com/users/vilchik-elena/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-19T13:27:18Z","updated_at":"2015-10-19T15:42:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b08299af7ee152cd23361d296daf61b326276e56","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls/66/commits","review_comments_url":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls/66/comments","review_comment_url":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SonarCommunity/sonar-php/issues/66/comments","statuses_url":"https://api.github.com/repos/SonarCommunity/sonar-php/statuses/d0ea29687c658c85a1c71bb829ce1d8d05bc5229","head":{"label":"SonarCommunity:SONARPHP-497","ref":"SONARPHP-497","sha":"d0ea29687c658c85a1c71bb829ce1d8d05bc5229","user":{"login":"SonarCommunity","id":1303819,"avatar_url":"https://avatars.githubusercontent.com/u/1303819?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarCommunity","html_url":"https://github.com/SonarCommunity","followers_url":"https://api.github.com/users/SonarCommunity/followers","following_url":"https://api.github.com/users/SonarCommunity/following{/other_user}","gists_url":"https://api.github.com/users/SonarCommunity/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarCommunity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarCommunity/subscriptions","organizations_url":"https://api.github.com/users/SonarCommunity/orgs","repos_url":"https://api.github.com/users/SonarCommunity/repos","events_url":"https://api.github.com/users/SonarCommunity/events{/privacy}","received_events_url":"https://api.github.com/users/SonarCommunity/received_events","type":"Organization","site_admin":false},"repo":{"id":4544982,"name":"sonar-php","full_name":"SonarCommunity/sonar-php","owner":{"login":"SonarCommunity","id":1303819,"avatar_url":"https://avatars.githubusercontent.com/u/1303819?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarCommunity","html_url":"https://github.com/SonarCommunity","followers_url":"https://api.github.com/users/SonarCommunity/followers","following_url":"https://api.github.com/users/SonarCommunity/following{/other_user}","gists_url":"https://api.github.com/users/SonarCommunity/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarCommunity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarCommunity/subscriptions","organizations_url":"https://api.github.com/users/SonarCommunity/orgs","repos_url":"https://api.github.com/users/SonarCommunity/repos","events_url":"https://api.github.com/users/SonarCommunity/events{/privacy}","received_events_url":"https://api.github.com/users/SonarCommunity/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarCommunity/sonar-php","description":"","fork":false,"url":"https://api.github.com/repos/SonarCommunity/sonar-php","forks_url":"https://api.github.com/repos/SonarCommunity/sonar-php/forks","keys_url":"https://api.github.com/repos/SonarCommunity/sonar-php/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarCommunity/sonar-php/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarCommunity/sonar-php/teams","hooks_url":"https://api.github.com/repos/SonarCommunity/sonar-php/hooks","issue_events_url":"https://api.github.com/repos/SonarCommunity/sonar-php/issues/events{/number}","events_url":"https://api.github.com/repos/SonarCommunity/sonar-php/events","assignees_url":"https://api.github.com/repos/SonarCommunity/sonar-php/assignees{/user}","branches_url":"https://api.github.com/repos/SonarCommunity/sonar-php/branches{/branch}","tags_url":"https://api.github.com/repos/SonarCommunity/sonar-php/tags","blobs_url":"https://api.github.com/repos/SonarCommunity/sonar-php/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarCommunity/sonar-php/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarCommunity/sonar-php/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarCommunity/sonar-php/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarCommunity/sonar-php/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarCommunity/sonar-php/languages","stargazers_url":"https://api.github.com/repos/SonarCommunity/sonar-php/stargazers","contributors_url":"https://api.github.com/repos/SonarCommunity/sonar-php/contributors","subscribers_url":"https://api.github.com/repos/SonarCommunity/sonar-php/subscribers","subscription_url":"https://api.github.com/repos/SonarCommunity/sonar-php/subscription","commits_url":"https://api.github.com/repos/SonarCommunity/sonar-php/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarCommunity/sonar-php/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarCommunity/sonar-php/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarCommunity/sonar-php/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarCommunity/sonar-php/contents/{+path}","compare_url":"https://api.github.com/repos/SonarCommunity/sonar-php/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarCommunity/sonar-php/merges","archive_url":"https://api.github.com/repos/SonarCommunity/sonar-php/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarCommunity/sonar-php/downloads","issues_url":"https://api.github.com/repos/SonarCommunity/sonar-php/issues{/number}","pulls_url":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarCommunity/sonar-php/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarCommunity/sonar-php/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarCommunity/sonar-php/labels{/name}","releases_url":"https://api.github.com/repos/SonarCommunity/sonar-php/releases{/id}","created_at":"2012-06-04T08:36:12Z","updated_at":"2015-09-24T13:22:53Z","pushed_at":"2015-10-19T15:38:45Z","git_url":"git://github.com/SonarCommunity/sonar-php.git","ssh_url":"git@github.com:SonarCommunity/sonar-php.git","clone_url":"https://github.com/SonarCommunity/sonar-php.git","svn_url":"https://github.com/SonarCommunity/sonar-php","homepage":"http://docs.codehaus.org/display/SONAR/PHP+Plugin","size":14670,"stargazers_count":41,"watchers_count":41,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":6,"forks":31,"open_issues":6,"watchers":41,"default_branch":"master"}},"base":{"label":"SonarCommunity:master","ref":"master","sha":"5593461de994cb600b0c8a5f8668a72a65a80314","user":{"login":"SonarCommunity","id":1303819,"avatar_url":"https://avatars.githubusercontent.com/u/1303819?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarCommunity","html_url":"https://github.com/SonarCommunity","followers_url":"https://api.github.com/users/SonarCommunity/followers","following_url":"https://api.github.com/users/SonarCommunity/following{/other_user}","gists_url":"https://api.github.com/users/SonarCommunity/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarCommunity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarCommunity/subscriptions","organizations_url":"https://api.github.com/users/SonarCommunity/orgs","repos_url":"https://api.github.com/users/SonarCommunity/repos","events_url":"https://api.github.com/users/SonarCommunity/events{/privacy}","received_events_url":"https://api.github.com/users/SonarCommunity/received_events","type":"Organization","site_admin":false},"repo":{"id":4544982,"name":"sonar-php","full_name":"SonarCommunity/sonar-php","owner":{"login":"SonarCommunity","id":1303819,"avatar_url":"https://avatars.githubusercontent.com/u/1303819?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarCommunity","html_url":"https://github.com/SonarCommunity","followers_url":"https://api.github.com/users/SonarCommunity/followers","following_url":"https://api.github.com/users/SonarCommunity/following{/other_user}","gists_url":"https://api.github.com/users/SonarCommunity/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarCommunity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarCommunity/subscriptions","organizations_url":"https://api.github.com/users/SonarCommunity/orgs","repos_url":"https://api.github.com/users/SonarCommunity/repos","events_url":"https://api.github.com/users/SonarCommunity/events{/privacy}","received_events_url":"https://api.github.com/users/SonarCommunity/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarCommunity/sonar-php","description":"","fork":false,"url":"https://api.github.com/repos/SonarCommunity/sonar-php","forks_url":"https://api.github.com/repos/SonarCommunity/sonar-php/forks","keys_url":"https://api.github.com/repos/SonarCommunity/sonar-php/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarCommunity/sonar-php/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarCommunity/sonar-php/teams","hooks_url":"https://api.github.com/repos/SonarCommunity/sonar-php/hooks","issue_events_url":"https://api.github.com/repos/SonarCommunity/sonar-php/issues/events{/number}","events_url":"https://api.github.com/repos/SonarCommunity/sonar-php/events","assignees_url":"https://api.github.com/repos/SonarCommunity/sonar-php/assignees{/user}","branches_url":"https://api.github.com/repos/SonarCommunity/sonar-php/branches{/branch}","tags_url":"https://api.github.com/repos/SonarCommunity/sonar-php/tags","blobs_url":"https://api.github.com/repos/SonarCommunity/sonar-php/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarCommunity/sonar-php/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarCommunity/sonar-php/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarCommunity/sonar-php/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarCommunity/sonar-php/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarCommunity/sonar-php/languages","stargazers_url":"https://api.github.com/repos/SonarCommunity/sonar-php/stargazers","contributors_url":"https://api.github.com/repos/SonarCommunity/sonar-php/contributors","subscribers_url":"https://api.github.com/repos/SonarCommunity/sonar-php/subscribers","subscription_url":"https://api.github.com/repos/SonarCommunity/sonar-php/subscription","commits_url":"https://api.github.com/repos/SonarCommunity/sonar-php/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarCommunity/sonar-php/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarCommunity/sonar-php/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarCommunity/sonar-php/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarCommunity/sonar-php/contents/{+path}","compare_url":"https://api.github.com/repos/SonarCommunity/sonar-php/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarCommunity/sonar-php/merges","archive_url":"https://api.github.com/repos/SonarCommunity/sonar-php/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarCommunity/sonar-php/downloads","issues_url":"https://api.github.com/repos/SonarCommunity/sonar-php/issues{/number}","pulls_url":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarCommunity/sonar-php/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarCommunity/sonar-php/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarCommunity/sonar-php/labels{/name}","releases_url":"https://api.github.com/repos/SonarCommunity/sonar-php/releases{/id}","created_at":"2012-06-04T08:36:12Z","updated_at":"2015-09-24T13:22:53Z","pushed_at":"2015-10-19T15:38:45Z","git_url":"git://github.com/SonarCommunity/sonar-php.git","ssh_url":"git@github.com:SonarCommunity/sonar-php.git","clone_url":"https://github.com/SonarCommunity/sonar-php.git","svn_url":"https://github.com/SonarCommunity/sonar-php","homepage":"http://docs.codehaus.org/display/SONAR/PHP+Plugin","size":14670,"stargazers_count":41,"watchers_count":41,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":6,"forks":31,"open_issues":6,"watchers":41,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls/66"},"html":{"href":"https://github.com/SonarCommunity/sonar-php/pull/66"},"issue":{"href":"https://api.github.com/repos/SonarCommunity/sonar-php/issues/66"},"comments":{"href":"https://api.github.com/repos/SonarCommunity/sonar-php/issues/66/comments"},"review_comments":{"href":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls/66/comments"},"review_comment":{"href":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SonarCommunity/sonar-php/pulls/66/commits"},"statuses":{"href":"https://api.github.com/repos/SonarCommunity/sonar-php/statuses/d0ea29687c658c85a1c71bb829ce1d8d05bc5229"}}}}