Search code examples
phpphing

Phing phpLocTask doesn't work even though PHPLoc is in the include_path


I am converting an Ant build.xml into a project using phing. One of the targets was using phploc which I converted into a target using <phploc/> task. I got the error message:

Execution of target "phploc" failed for the following reason: \
/Users/david/workspace/phoenix/build-test/build.xml:44:17: \ 
/Users/david/workspace/phoenix/build-test/build.xml:44:17: \
PHPLocTask depends on PHPLoc being installed and on include_path.

I downloaded PHPLoc which is distributed as a *.phar file, and followed the directions in the README.md.

$ phploc -help
phploc 2.0.6 by Sebastian Bergmann.

Usage:
  phploc [--names="..."] [--names-exclude="..."] [--count-tests] [--git-repository="..."] [--exclude="..."] [--log-csv="..."] [--log-xml="..."] [--progress] [values1] ... [valuesN]
...

I still get the same error message. I found my include_path:

$ php -i 2> /dev/null | grep "^include_path"
include_path => .:/usr/local/php/includes:/usr/local/pear/share/pear:/usr/lib/php/pear => .:/usr/local/php/includes:/usr/local/pear/share/pear:/usr/lib/php/pear

and copied phploc to /usr/local/php/includes, but I still get the same error message no matter if it's named PHPLoc or phploc.

I found the phploc task in /usr/lib/php/pear/phing/Phing/tasks/ext/phploc/PHPLoc.php:

public function main()
{
    /**
     * Find PHPLoc
     */
    if (!class_exists('\SebastianBergmann\PHPLOC\Analyser')) {
        if (!@include_once('SebastianBergmann/PHPLOC/autoload.php')) {
            if (!@include_once('PHPLOC/Analyser.php')) {
                throw new BuildException(
                    'PHPLocTask depends on PHPLoc being installed and on include_path.',
                    $this->getLocation()
                );
            } else {
                $this->oldVersion = true;
            }
        }
    }

The very first class_exists statement isn't returning a true value and the include_once is not getting the included file. I wonder if this is because phploc is a PHAR package and not individual files.

I can always do an <exec/> or <apply/> task, but I thought it would be better to use the already defined task.

What do I need to do to install phploc, so the <phploc> Phing task can find it?


Solution

  • The information wasn't on the phploc page, but after going through all the files and a bit of Googling, I found I could do the following:

    $ sudo pear channel-discover pear.phpunit.de
    $ sudo pear channel-discover pear.symfony.com
    $ sudo pear channel-discover pear.netpirates.net
    $ sudo pear install phpunit/phploc
    

    This installs phploc via Pear, and Phing is able to use it. Phar packages just don't seem to work with Phing.