Is phplint compatible with composer's autoloader?

1.5k views Asked by At

I'm just getting back into PHP and trying to do things the correct way from the beginning. So I've installed PHPLint 2.1_20151116 and I cannot seem to get it to work with composer's autoload. Is it possible?

For example I am trying to add a test case to Laravel/Envoy, but I cannot get past an error "undeclared parent class TestCase".

The folder structure is:

envoy
├── tests
│   ├── RemoteProcessorTest.php
│   ├── SSHConfigFileTest.php
│   └── TestCase.php

The contents of RemoteProcessorTest.php is:

<?php
namespace Laravel\Envoy;
class RemoteProcessTest extends TestCase
{
}

If I run ./vendor/bin/phpunit then I get the error: No tests found in class "Laravel\Envoy\RemoteProcessTest".. Which isn't a syntax error so it looks like everything is valid. But phplint still complains.

$ cd envoy
$ phpl --php-version 5 --print-path relative --print-column-number --tab-size 4 --no-overall tests/RemoteProcessorTest.php 
BEGIN parsing of tests/RemoteProcessorTest.php
1:  <?php
2:  namespace Laravel\Envoy;
3:  
4:  class RemoteProcessTest extends TestCase
5:  {

    {
    \_ HERE
==== 5:1: ERROR: undeclared parent class TestCase
6:  }
END parsing of tests/RemoteProcessorTest.php

Is there a work around for this?

1

There are 1 answers

3
iridian On

I may not be able to answer the question directly as the repo in question seems too limited to give you what you seek. I'll leave it to the community to answer the question directly.

Here are some alternatives that hopefully will help.

If you want to syntax check PHP has a built-in linter. Simply:

$ php -l filename.php

or --syntax-check instead of -l.

There is also this on packagist as a viable alternative. https://packagist.org/packages/gamegos/php-code-sniffer

It has a configuration file named phpcs.xml that you can check into your repo and include via composer.

# composer.json
...
require-dev {
    "gamegos/php-code-sniffer": "0.4.0"
}
...

The phpcs.xml file has a bootstrap tag that will give it the information to find the Laravel classes among your own.

<?xml version="1.0" encoding="UTF-8"?>
<ruleset>
    <rule ref="Gamegos" />
    <arg name="bootstrap" value="vendor/autoload.php" />
</ruleset>

After installing with Composer you'll have 3 binaries:

  • vendor/bin/phpcbf
  • vendor/bin/phpcs
  • vendor/bin/phpcs-pre-commit

You can find a lot of customization options on the Github repo. https://github.com/gamegos/php-code-sniffer