Search in sources :

Example 1 with PhpFileImpl

use of org.sonar.php.compat.PhpFileImpl in project sonar-php by SonarSource.

the class SymbolScanner method scanFile.

@Override
void scanFile(InputFile file) {
    PhpFileImpl phpFile = new PhpFileImpl(file);
    try {
        Tree ast = statistics.time("ProjectSymbolParsing", () -> parser.parse(phpFile.contents()));
        SymbolTableImpl symbolTable = statistics.time("ProjectSymbolTable", () -> SymbolTableImpl.create((CompilationUnitTree) ast, new ProjectSymbolData(), phpFile));
        symbolTable.classSymbolDatas().forEach(projectSymbolData::add);
        symbolTable.functionSymbolDatas().forEach(projectSymbolData::add);
    } catch (RecognitionException e) {
        LOG.debug("Parsing error in " + file);
    }
}
Also used : CompilationUnitTree(org.sonar.plugins.php.api.tree.CompilationUnitTree) ProjectSymbolData(org.sonar.php.symbols.ProjectSymbolData) PhpFileImpl(org.sonar.php.compat.PhpFileImpl) SymbolTableImpl(org.sonar.php.tree.symbols.SymbolTableImpl) CompilationUnitTree(org.sonar.plugins.php.api.tree.CompilationUnitTree) Tree(org.sonar.plugins.php.api.tree.Tree) RecognitionException(com.sonar.sslr.api.RecognitionException)

Example 2 with PhpFileImpl

use of org.sonar.php.compat.PhpFileImpl in project sonar-php by SonarSource.

the class PhpIniSensor method execute.

@VisibleForTesting
protected void execute(SensorContext context, Checks<PhpIniCheck> checks) {
    PhpIniParser parser = new PhpIniParser();
    FileSystem fs = context.fileSystem();
    Iterable<InputFile> inputFiles = fs.inputFiles(fs.predicates().matchesPathPattern("**/php.ini"));
    for (InputFile inputFile : inputFiles) {
        PhpIniFile phpIni;
        try {
            phpIni = parser.parse(new PhpFileImpl(inputFile));
        } catch (RecognitionException e) {
            LOG.error("Unable to parse file: " + inputFile.toString());
            LOG.error(e.getMessage());
            continue;
        }
        for (PhpIniCheck check : checks.all()) {
            List<PhpIniIssue> issues = check.analyze(phpIni);
            saveIssues(context, inputFile, checks.ruleKey(check), issues);
        }
    }
}
Also used : PhpIniFile(org.sonar.php.ini.tree.PhpIniFile) PhpIniCheck(org.sonar.php.ini.PhpIniCheck) PhpIniIssue(org.sonar.php.ini.PhpIniIssue) FileSystem(org.sonar.api.batch.fs.FileSystem) PhpFileImpl(org.sonar.php.compat.PhpFileImpl) PhpIniParser(org.sonar.php.ini.PhpIniParser) RecognitionException(com.sonar.sslr.api.RecognitionException) InputFile(org.sonar.api.batch.fs.InputFile) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

RecognitionException (com.sonar.sslr.api.RecognitionException)2 PhpFileImpl (org.sonar.php.compat.PhpFileImpl)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FileSystem (org.sonar.api.batch.fs.FileSystem)1 InputFile (org.sonar.api.batch.fs.InputFile)1 PhpIniCheck (org.sonar.php.ini.PhpIniCheck)1 PhpIniIssue (org.sonar.php.ini.PhpIniIssue)1 PhpIniParser (org.sonar.php.ini.PhpIniParser)1 PhpIniFile (org.sonar.php.ini.tree.PhpIniFile)1 ProjectSymbolData (org.sonar.php.symbols.ProjectSymbolData)1 SymbolTableImpl (org.sonar.php.tree.symbols.SymbolTableImpl)1 CompilationUnitTree (org.sonar.plugins.php.api.tree.CompilationUnitTree)1 Tree (org.sonar.plugins.php.api.tree.Tree)1