0

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?

Rob
  • 3,687
  • 2
  • 32
  • 40
  • 1
    I can't find which php linter you are using. There are many, can you link to the linter's main page or documentation? Also, if you add to your question your composer.json file as knowing which autoloader you are using may help us find an answer. A couple of things I see is that your directory structure needs to match your namespaces. Your PHPUnit will also need a --bootstrap file (your composer's vendor/autoload.php file). You can set this in the phpunit.xml file. Your linter will also need to load the vendor/autoload.php file. – iridian Jan 25 '16 at 03:40
  • @DillonGilmore Sorry about that, this is one of my problems coming from python where there there is one way to do things. I've added a link the phplint tool I found. Not sure if there are others, or if I should be using something different. I'm basically just looking for something like pylint to use in my PHP code. – Rob Jan 26 '16 at 15:23
  • Composer is to PIP as Packagist (https://packagist.org/) is to PyPI. Hopefully that helps. There also isn't anything like PEP8. The closest you can get is the community driven PHP-FIG 's PSR-1/PSR-2. – iridian Jan 27 '16 at 01:50
  • @DillonGilmore I've configured SublimeLinter to run phplint, phpcs, and phpmd. I think phpcs will do PSR checking? I think composer is sort of like pip, except half of the PHP examples I've seen don't use it, they use pear or just manual installing. It's frustrating coming from an exosystem like python where there are widely used standard processes. – Rob Jan 28 '16 at 14:53
  • It's probably not wise to compare the 2 ecosystems. PHP is PHP and Python is Python. Composer is quickly becoming the industry standard and Pecl/Pear are still around for installing C-based extensions even though the repos still exist and contain PHP-only code. Also, Composer can install ANY repo from version control including Git (and all of Github). – iridian Jan 28 '16 at 18:56

1 Answers1

-2

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

iridian
  • 669
  • 5
  • 13
  • `php -l` is just a syntax check and I am also concerned with style and standards. The require_module stuff is for `php -m` compiled modules not libraries. That line gives an error: "ERROR: require_module '../../../path/to/vendor/autoload.php': module name contains invalid characters. Hint: only letters, digits and underscore allowed; path not allowed." – Rob Jan 28 '16 at 14:56
  • I see, my bad. The library seems non-standard to me. I'll update the answer for a PSR alternative. – iridian Jan 28 '16 at 18:59
  • is there a way to exclude a folder from it? – TheCrazyProfessor Aug 01 '21 at 09:14