Skip to content

Commit

Permalink
Testing removal of PHPCS from the composer autoloader
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Feb 5, 2017
1 parent 4fc2515 commit 566a0cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
9 changes: 5 additions & 4 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,17 @@ class Autoload
*/
public static function load($class)
{
// Include the composer autoloader if there is one, but unregister it
// as we need to include all files so we can figure out what
// the class/interface/trait name is.
// Include the composer autoloader if there is one, but re-register it
// so this autoloader runs before the composer one as we need to include
// all files so we can figure out what the class/interface/trait name is.
if (self::$composerAutoloader === null) {
if (strpos(__DIR__, 'phar://') !== 0
&& file_exists(__DIR__.'/../../autoload.php') === true
) {
self::$composerAutoloader = include __DIR__.'/../../autoload.php';
if (self::$composerAutoloader instanceof \Composer\Autoload\ClassLoader) {
self::$composerAutoloader->unregister();
#self::$composerAutoloader->unregister();
#self::$composerAutoloader->register();
} else {
// Something went wrong, so keep going without the autoloader
// although namespaced sniffs might error.
Expand Down
7 changes: 0 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@
"dev-master": "3.x-dev"
}
},
"autoload": {
"psr-4": {
"PHP_CodeSniffer\\": "src/",
"PHP_CodeSniffer\\Tests\\": "tests/"
},
"files": ["autoload.php"]
},
"require": {
"php": ">=5.4.0",
"ext-tokenizer": "*",
Expand Down

7 comments on commit 566a0cd

@TomasVotruba
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for that? Now I have to autoload these classes extra manually :(

@gsherwood
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomasVotruba Part of #1333

If you need to include PHPCS directly, include the autoload.php file. For anyone not using PHPCS as a lib, they shouldn't include this file or else PHPCS will try and autoload and track classes, which is why it was removed.

@TomasVotruba
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see solution in breaking non-framework usage.

@TomasVotruba
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anyone else looking for solution for this composer break, you can find it on StackOverfelow.

Let me know there if you find better one or if this was already solved.

@photodude
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is the root of the issue that is causing our 3.x development to error as follows

PHP Fatal error:  Class 'Joomla\Sniffs\Commenting\FileCommentSniff' not found in /home/travis/build/joomla/coding-standards/Joomla/Sniffs/Commenting/ClassCommentSniff.php on line 20

@jrfnl
Copy link
Contributor

@jrfnl jrfnl commented on 566a0cd Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@photodude I think your issue is probably related to #1564 which should be fixed in the latest PHPCS master.

@gsherwood
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@photodude @jrfnl That issue was only during testing. So if you are getting this problem during a normal phpcs run, then you've probably got a namespace issue somewhere. Namespace requirements are described in the upgrade guide (https://github.com/squizlabs/PHP_CodeSniffer/wiki/Version-3.0-Upgrade-Guide#upgrading-custom-sniffs) but please create a new issue with a link to your coding standard (if possible) if you are having a problems.

Please sign in to comment.