grom358 / pharborist

A PHP library to query and transform source code via tree operations.
GNU General Public License v3.0
44 stars 10 forks source link

Restore the ability to retrieve the filename from a Node #228

Closed pfrenssen closed 9 years ago

pfrenssen commented 9 years ago

In commit 14f0fee3aa NodeInterface::getSourcePosition() was removed. Originally the SourcePosition object that was returned by this method contained the source filename as well as some other properties such as the line number and column number. All properties apart from the filename are now made part of NodeInterface proper. The filename is now completely handled by Parser.

It makes sense though to keep the filename associated with NodeInterface. After all, the line number and column number are also part of it.

Internally in Pharborist there is no need store the filename on the node, since the Parser is only dealing with a single file at a time, and is always aware to which file a certain node belongs. There might be more advanced use cases however where nodes are being passed to other classes and the filename may be lost. This is a pattern we commonly use in the Drupal Module Upgrader. We were able to retrieve the original filename from the node, but this is no longer possible. We would now have to pass the filename as a string in addition to the NodeInterface object which feels wrong since the filename is closely bound to the node.

grom358 commented 9 years ago

Added a getFilename() method to NodeInterface

pfrenssen commented 9 years ago

Thanks!