Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add use relationship #3

Draft
wants to merge 17 commits into
base: development
Choose a base branch
from
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# jqa-php-plugin

[![GitHub license](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](LICENSE)
[![Build Status](https://api.travis-ci.com/softvis-research/jqa-php-plugin.svg?branch=development)](https://travis-ci.com/softvis-research/jqa-php-plugin)
[![Build Status](https://api.travis-ci.com/softvis-research/jqa-php-plugin.svg?branch=master)](https://travis-ci.com/softvis-research/jqa-php-plugin)

This is a php parser of jQAssistant. It enables jQAssistant to scan and to analyze php files.
This is a php parser for jQAssistant. It enables jQAssistant to scan and to analyze php files.

![graph](material/graph.png)
47 changes: 24 additions & 23 deletions material/graph.graphml

Large diffs are not rendered by default.

Binary file modified material/graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/presentation.odp
Binary file not shown.
Binary file added material/presentation.pdf
Binary file not shown.
274 changes: 274 additions & 0 deletions material/tree.graphml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.jqassistant.contrib.plugin.php</groupId>
<artifactId>jqa-php-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.0.9</version>

<name>php</name>
<!-- FIXME change it to the project's website -->
Expand Down Expand Up @@ -111,7 +111,7 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<version>3.0.0-M3</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import java.io.File;
import java.io.InputStream;

/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't work on this plugin before. Is there a good reason to keep this file? Otherwise feel free to remove it.

* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author falk
*/
public class Main {
public static void main(String[] args) {
System.out.println("Main.main()");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
*/
@Label("File")
public interface PHPFileDescriptor extends PHPDescriptor, NamedDescriptor, FileDescriptor {

// /**
// * lines of code
// * @return set of lines
// */
// @Relation("HAS_LINE")
// Set<PHPLineDescriptor> getLines();

/**
* included functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ public interface PHPFunctionDescriptor extends PHPDescriptor, FullQualifiedNameD
String getName();
void setName(String name);

/**
* count of lines
* @return integer
*/
@Property("linesOfCode")
int getLinesOfCode();
void setLinesOfCode(int linesOfCode);

/**
* Return all declared parameters of this method.
*
Expand Down Expand Up @@ -57,8 +49,34 @@ public interface PHPFunctionDescriptor extends PHPDescriptor, FullQualifiedNameD
* Number of first line in source file
* @return integer
*/
@Property("lineNumber")
int getLineNumber();
void setLineNumber(int lineNumber);
@Property("firstLineNumber")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the improvement. That is way clearer than before :)

After improving the property name, the documentation does not add any value - it's redundant. Please remove it.

int getFirstLineNumber();
void setFirstLineNumber(int firstLineNumber);

/**
* Number of last line in source file
* @return integer
*/
@Property("lastLineNumber")
int getLastLineNumber();
void setLastLineNumber(int lastLineNumber);


/**
* count of lines with commands
* @return integer
*/
@Property("effectiveLineCount")
int getEffectiveLineCount();
void setEffectiveLineCount(int effectiveLineCount);

/**
* Signature of function
* @return integer
*/
@Property("signature")
String getSignature();
void setSignature(String signature);


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
@Label("Parameter")
public interface PHPFunctionParameterDescriptor extends PHPDescriptor{

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation does not provide value.

* Position of parameter
* @return Integer
*/
@Property("index")
int getIndex();

void setIndex(int index);

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation does not provide value.

* Name of parameter
* @return String
*/
String getName();
void setName(String name);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
@Label(value = "Namespace", usingIndexedPropertyOf = FullQualifiedNameDescriptor.class)
public interface PHPNamespaceDescriptor extends PHPDescriptor, FullQualifiedNameDescriptor {

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant as well.

* Name of namespace
* @return String
*/
String getName();
void setName(String name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
@Label("Field")
public interface PHPPropertyDescriptor extends PHPDescriptor {

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant as well.

* Name of field
* @return String
*/
String getName();
void setName(String name);

Expand All @@ -34,6 +38,14 @@ public interface PHPPropertyDescriptor extends PHPDescriptor {
Boolean isStatic();
void setStatic(Boolean s);

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant as well.

* is property constant
* @return boolean
*/
@Property("constant")
Boolean isConstant();
void setConstant(Boolean c);

/**
* Number of line in source file
* @return integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
@Label(value = "Type", usingIndexedPropertyOf = FullQualifiedNameDescriptor.class)
public interface PHPTypeDescriptor extends PHPDescriptor, FullQualifiedNameDescriptor {

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant as well.

* Name
* @return String
*/
String getName();
void setName(String name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,44 @@
*/
package org.jqassistant.contrib.plugin.php.scanner;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.buschmais.jqassistant.core.scanner.api.Scanner;
import com.buschmais.jqassistant.core.scanner.api.ScannerPlugin;
import com.buschmais.jqassistant.core.scanner.api.Scope;
import com.buschmais.jqassistant.core.store.api.Store;
import com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor;
import com.buschmais.jqassistant.plugin.common.api.scanner.AbstractScannerPlugin;
import com.buschmais.jqassistant.plugin.common.api.scanner.filesystem.FileResource;
import java.io.File;
import java.io.InputStream;
import org.jqassistant.contrib.plugin.php.model.PHPFileDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static java.util.Arrays.asList;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.apache.commons.io.FileUtils;
import org.jqassistant.contrib.plugin.php.PhpLexer;
import org.jqassistant.contrib.plugin.php.PhpParser;
import org.jqassistant.contrib.plugin.php.scanner.parser.PHPFileParser;

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation can be removed.

* PHP file scanner
* @author falk
*/
@ScannerPlugin.Requires(FileDescriptor.class)
public class PHPFileScannerPlugin extends AbstractScannerPlugin<FileResource, PHPFileDescriptor> {

private static final Logger LOGGER = LoggerFactory.getLogger(PHPFileScannerPlugin.class);

public static final String JQASSISTANT_PLUGIN_PHP_SUFFIXES = "jqassistant.plugin.php.suffixes";

private static List<String> suffixes = asList("php", "phtml");


/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no explanation for params or return values you can remove the lines accordingly.

Something like that would be useful:

Decides if a file gets accepted by the PHP plugin. Therefore, we check if the file name ends with certain suffixes defined in <i>JQASSISTANT_PLUGIN_PHP_SUFFIXES</i>.

* check if file accepted by this plugin
* @param item
* @param path
* @param scope
* @return boolean
* @throws IOException
*/
@Override
public boolean accepts(final FileResource item, final String path, final Scope scope) throws IOException {
int beginIndex = path.lastIndexOf(".");
Expand All @@ -61,19 +60,20 @@ public boolean accepts(final FileResource item, final String path, final Scope s
return false;
}

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation does not provide any value.

* scan php file
* @param item
* @param path
* @param scope
* @param scanner
* @return PHPFileDescriptor
* @throws IOException
*/
@Override
public PHPFileDescriptor scan(final FileResource item, final String path, final Scope scope, final Scanner scanner) throws IOException {
final Store store = scanner.getContext().getStore();
FileDescriptor fileDescriptor = scanner.getContext().getCurrentDescriptor();
final PHPFileDescriptor phpFileDescriptor = store.addDescriptorType(fileDescriptor, PHPFileDescriptor.class);

// try (BufferedReader reader = new BufferedReader(new InputStreamReader(item.createStream()))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for cleaning this up!

// final PHPLineParser pumlLineParser = new PHPLineParser(store, phpFileDescriptor);
// String line;
// while ((line = reader.readLine()) != null) {
// pumlLineParser.parseLine(line);
// }
// }
FileDescriptor fileDescriptor = scanner.getContext().getCurrentDescriptor();
final PHPFileDescriptor phpFileDescriptor = store.addDescriptorType(fileDescriptor, PHPFileDescriptor.class);

phpFileDescriptor.setName(item.getFile().getName());

Expand All @@ -83,6 +83,9 @@ public PHPFileDescriptor scan(final FileResource item, final String path, final
return phpFileDescriptor;
}

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation does not provide any value.

* configuration
*/
@Override
protected void configure() {
super.configure();
Expand All @@ -97,5 +100,4 @@ protected void configure() {

LOGGER.info(String.format("php plugin looks for files with suffixes '%s'", suffixes.toString()));
}

}
}

This file was deleted.

Loading