tags:

views:

157

answers:

4

Background:

PHPDoc ( http://www.phpdoc.org/ ) is a brilliant tool for extracting html documentation of your classes or methods from comments in your files. Adding PHPDoc comments also has other advantages - if you use an IDE like Zend or Netbeans, it will use the PHPDocs to show you autocompletion tips.

Most Issue trackers have a feature where you can commit into your version control system with a special comment, and it will automatically link that commit to that issue.

So here's what I want in a system: I commit some code with a special comment, my issue tracker links it to an issue. It then looks at the commit and works out what Methods and Classes I have changed. It then says "If you are looking for documentation around this issue, try these bits of PHPDoc: ClassX.FunctionY, ClassZ.VariableP". It automatically points users to documentation that might be relevant. I think this would be a great feature.

Question:

So the piece that is missing is something to take a PHP code diff, and work out what classes and methods have changed. Anyone got any pointers on some code that can do that?

Thanks in advance, James

+1  A: 

If you are using subversion, you can see a diff of all the files that have changed in the project. And see how they are different.

There are software with integrated subversion support, like Trac.

Here's a picture of TracDiff

Ólafur Waage
Unfortunately, knowing what files have changed IS NOT the same as knowing what classes and functions have changed. There could be multiple classes and functions in each file. You have to parse the PHP and this is not trivial, hence my question. Sorry, but thanks for your time.
James
+1  A: 

You need a tool that understands the structure of PHP deeply, that is, can parse the PHP source text just like the PHP engine does.

Our "Smart Diff" does this, enabling one compare pairs of PHP files that you know are the original and changed version. It compares ASTs and finds the minimal edits to map one into another. If the old and new methods are at all similar, it will discover that and tell you how one was edited to get the other. See http://www.semdesigns.com/Products/SmartDifferencer/index.html

Ira Baxter
That does sound brilliant, but I need it to identify Class and Method structures, and it's not clear whether it does this. I guess this is something they could provide easily tho.But the general idea sounds like a brilliant one: as a programmer I got annoyed by some of the things they are talking about. Sometimes I even think about formatting my source code purely to get as neat a diff as possible. Thanks.
James
If you want to go that far, what you need to do is to take the minimal diffs, determine which class/functions they are in, and then compute a call graph a-call-b so that if b is changed, you know that a is affected. This requires a pretty sophisticated analysis of the PHP source code. A tool that has the ability to determine this kind of thing is the DMS Software Reengineering Toolkit (http://www.semanticdesigns.com/Products/DMS/DMSToolkit.html). Check out the discussion at the site on flow analysis, including global call graphs.
Ira Baxter
A: 

http://uk3.php.net/reflection

PHP5 has methods to take a class apart and examine all the methods, including giving me the line numbers I need to match against the diff. Using this I can start to hand roll my own solution.

James
A: 

you can write a post commit script that receives the files modiefied and looks into them to do what you want

solomongaby
See my comment to Ólafur Waage
James