squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

Broken on PHP 5.2 due to Composer autoload #942

Closed Rarst closed 8 years ago

Rarst commented 8 years ago

https://github.com/squizlabs/PHP_CodeSniffer/commit/0ade7697cf4a982c08f96957e2fa8a08da140c71 breaks on PHP 5.2 since Composer autoload is not compatible with it.

$ if [[ "$PHPLINT" == "1" ]]; then vendor/bin/phpcs -v; fi

Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /tmp/wordpress/src/wp-content/plugins/wordpress-seo/vendor/autoload.php on line 5

Warning: require_once(__DIR__/composer/autoload_real.php): failed to open stream: No such file or directory in /tmp/wordpress/src/wp-content/plugins/wordpress-seo/vendor/autoload.php on line 5

Fatal error: require_once(): Failed opening required '__DIR__/composer/autoload_real.php' (include_path='.:/home/travis/.phpenv/versions/5.2.17/pear') in /tmp/wordpress/src/wp-content/plugins/wordpress-seo/vendor/autoload.php on line 5

The command "if [[ "$PHPLINT" == "1" ]]; then vendor/bin/phpcs -v; fi" exited with 255.
gsherwood commented 8 years ago

I don't think I can't both support composer autoloading and not support it at the same time. If composer doesn't support PHP 5.2, why would you be installing PHP_CodeSniffer using composer under 5.2?

Rarst commented 8 years ago

Installing and running are separate actions. We install with Composer, but we support running result on PHP 5.2 version, using a package that generates 5.2–compatible autoload.

So it would make sense for me if including Composer autoload was conditional on PHP >=5.3, because it's presence doesn't guarantee PHP environment that can execute it. People like us who have to support PHP 5.2 :cry: will deal with autoload themselves.

In this specific case we decided to exclude CS check from 5.2 on Travis, version not important to it. So this is just reporting to make it more robust and handle edge case better, not something critical for us.

gsherwood commented 8 years ago

We install with Composer, but we support running result on PHP 5.2 version, using a package that generates 5.2–compatible autoload.

I didn't know that was possible. Thanks for letting me know.

So it would make sense for me if including Composer autoload was conditional on PHP >=5.3

Sounds like a good idea.