-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a08cb3b
commit 554007d
Showing
4 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
analyzer-phpstan/src/main/java/io/codety/scanner/analyzer/phpstan/PhpstanCodeAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.codety.scanner.analyzer.phpstan; | ||
|
||
import io.codety.common.dto.CodeAnalyzerType; | ||
import io.codety.common.dto.LanguageType; | ||
import io.codety.scanner.analyzer.CodeAnalyzerInterface; | ||
import io.codety.scanner.analyzer.dto.AnalyzerConfigurationDetailDto; | ||
import io.codety.scanner.reporter.dto.CodeAnalysisIssueDto; | ||
import io.codety.scanner.reporter.dto.CodeAnalysisResultDto; | ||
import io.codety.scanner.service.dto.AnalyzerRequest; | ||
import io.codety.scanner.util.CodetyConsoleLogger; | ||
import io.codety.scanner.util.RuntimeExecUtil; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
Check warning on line 12 in analyzer-phpstan/src/main/java/io/codety/scanner/analyzer/phpstan/PhpstanCodeAnalyzer.java
|
||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
public class PhpstanCodeAnalyzer implements CodeAnalyzerInterface { | ||
@Override | ||
public List<CodeAnalysisResultDto> analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) { | ||
|
||
CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"..."); | ||
ArrayList<CodeAnalysisResultDto> list = new ArrayList(); | ||
|
||
String[] command; | ||
String localGitRepoPath = request.getLocalGitRepoPath(); | ||
//./vendor/bin/phpstan --memory-limit=1024000000 --no-interaction --no-progress --error-format=json analyse | ||
if(runnerConfiguration.getPayload() == null || runnerConfiguration.getPayload().isEmpty()){ | ||
command = new String[]{"./vendor/bin/phpsta", "--memory-limit=1024000000", "--no-interaction", "--no-progress", "--error-format=json", "analyse", localGitRepoPath}; | ||
}else{ | ||
//Use multiple rules: --check CKV_GCP_33,CKV_GCP_34,CKV_GCP_35 ... | ||
command = new String[]{"./vendor/bin/phpsta", "--memory-limit=1024000000", "--no-interaction", "--no-progress", "--error-format=json", "analyse", localGitRepoPath}; | ||
} | ||
try { | ||
RuntimeExecUtil.RuntimeExecResult runtimeExecResult = RuntimeExecUtil.exec(command, "/", 60, false, null); | ||
|
||
String errorOutput = runtimeExecResult.getErrorOutput(); | ||
String successOutput = runtimeExecResult.getSuccessOutput(); | ||
|
||
List<CodeAnalysisIssueDto> codeAnalysisIssueDtoList = PhpstanConverter.convertResult(successOutput, localGitRepoPath); | ||
|
||
CodeAnalysisResultDto resultDto = new CodeAnalysisResultDto(runnerConfiguration.getLanguage(), runnerConfiguration.getCodeAnalyzerType()); | ||
resultDto.setDisplayTitle("IaC"); | ||
resultDto.addIssues(codeAnalysisIssueDtoList); | ||
list.add(resultDto); | ||
|
||
} catch (Exception e) { | ||
CodetyConsoleLogger.info("Skip checkov analyzer due to exceptions"); | ||
CodetyConsoleLogger.debug("Skip checkov analyzer due to exceptions " + e.getMessage(), e); | ||
} | ||
|
||
return list; | ||
|
||
} | ||
|
||
@Override | ||
public List<CodeAnalysisResultDto> analyzeCode(AnalyzerRequest request) { | ||
return analyzeCode(new AnalyzerConfigurationDetailDto(LanguageType.php, CodeAnalyzerType.phpstan), request); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
analyzer-phpstan/src/main/java/io/codety/scanner/analyzer/phpstan/PhpstanConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.codety.scanner.analyzer.phpstan; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import io.codety.scanner.analyzer.phpstan.dto.PhpstanIssueDto; | ||
import io.codety.scanner.analyzer.phpstan.dto.PhpstanRoot; | ||
import io.codety.scanner.reporter.dto.CodeAnalysisIssueDto; | ||
import io.codety.scanner.util.JsonFactoryUtil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class PhpstanConverter { | ||
public static List<CodeAnalysisIssueDto> convertResult(String successOutput, String localGitRepoPath) throws JsonProcessingException { | ||
List<CodeAnalysisIssueDto> result = new ArrayList<>(); | ||
PhpstanRoot phpstanRoot = JsonFactoryUtil.objectMapper.readValue(successOutput, PhpstanRoot.class); | ||
|
||
Map<String, PhpstanIssueDto> files = phpstanRoot.getFiles(); | ||
for(String file : files.keySet()){ | ||
if(file.startsWith(localGitRepoPath)){ | ||
Check warning on line 20 in analyzer-phpstan/src/main/java/io/codety/scanner/analyzer/phpstan/PhpstanConverter.java
|
||
|
||
} | ||
|
||
} | ||
|
||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters