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

Fix usage example in README (again :)) #227

Closed webchick closed 9 years ago

webchick commented 9 years ago

Similar problem as #169; the usage example in README.md doesn't seem to work.

  1. $filename is not defined (maybe point it at one of Pharborist's internal files as an example?)
  2. Even if you manually hack in a $filename (for example, 'src/Node.php') you just get a blank screen back.
  3. This is because if ($namespaces->count() > 1) { returns false, since $namespaces->count() /is/ 1 (which is odd, since if you var_dump($namespaces) you see all kinds of things in there.)
  4. And finally, even if you could get this condition to trigger true (for example, change it from > 1 to == 1), you'd end up with a notice and parse error:

( ! ) Notice: Undefined offset: 1 in /Users/webchick/Sites/7.x/pharborist/src/NodeCollection.php on line 73 ( ! ) Fatal error: Call to a member function getSourcePosition() on a non-object in /Users/webchick/Sites/7.x/pharborist/far.php on line 14

getSourcePosition seems to have been removed in https://github.com/grom358/pharborist/commit/14f0fee3aa1a3921528451434f7ebd5310ce43a1

grom358 commented 9 years ago

I have fixed the example up :)

In regards to point 3. If you only have one namespace (in the filename being parsed) you should see one element in the protected $nodes property. Its just what you see is a tree so you will see all kinds of things in there, but at very top level there should be the one node.

The below test file should trigger the die..

<?php
namespace MyNamespace {
}

namespace FailHere {
}