Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What to replace PHP_CodeSniffer_CLI() with? #2035

Closed
dingo-d opened this issue May 28, 2018 · 23 comments
Closed

What to replace PHP_CodeSniffer_CLI() with? #2035

dingo-d opened this issue May 28, 2018 · 23 comments

Comments

@dingo-d
Copy link

dingo-d commented May 28, 2018

I'm rewriting the Theme Sniffer plugin, and I'm getting errors due to missing PHP_CodeSniffer_CLI() class.

https://github.com/WPTRT/theme-sniffer/blob/a0af96a9f5217c11b04a22691d56e60c6ff257e1/inc/checks.php#L72

Now from what I gathered I should be using \PHP_CodeSniffer\Runner() class, but I'm unsure how to replace it exaclty.

The old way was:

$phpcs_cli = new PHP_CodeSniffer_CLI();
$phpcs_cli->checkRequirements();
ob_start();
$num_errors = $phpcs_cli->process( $values );
$raw_output = ob_get_clean();
$output     = '';
// Sniff theme files.
if ( 1 === absint( $args['raw_output'] ) ) {
	if ( ! empty( $raw_output ) ) {
		$output = '<pre>' . esc_html( $raw_output ) . '</pre>';
	}
} else {
	$output = json_decode( $raw_output );
} // End if().
return $output;

Now I'm trying

// Initialize CodeSniffer.
$runner = new \PHP_CodeSniffer\Runner();
$runner->checkRequirements();

ob_start();
$num_errors = $runner->processFile( $file );
$raw_output = ob_get_clean();
$output     = '';

And I've set some config like \PHP_CodeSniffer\Config::setConfigData( 'show_warnings', absint( $args['show_warnings'] ), true );

Do I need to set all CLI arguments in that way? Before there was an array $values that got passed to the process() method. Should I just set all the config using \PHP_CodeSniffer\Config::setConfigData?

@gsherwood
Copy link
Member

Here is an example of a custom runner: https://gist.github.com/gsherwood/aafd2c16631a8a872f0c4a23916962ac

It processes a PHP string using a dummy file object and grabs the report output itself, but you could also just call $runner->run() after setting up the config object to have it process files and reports as normal.

@dingo-d
Copy link
Author

dingo-d commented May 29, 2018

Thanks, I'll try that.

@dingo-d
Copy link
Author

dingo-d commented Jun 9, 2018

Ok, so I tried with this:

class Checks {

    ...

    public function run_sniffer {

        ...

        $ignored = array(
          '.*/node_modules/.*',
          '.*/vendor/.*',
          '.*/assets/build/.*',
          '.*/build/.*',
          '.*/bin/.*',
        );

        // Set up a PHPCS Runner and Config.
          $runner = new Runner();

        // Set default standard.
        \PHP_CodeSniffer\Config::setConfigData( 'default_standard', 'WordPress-Theme', true );

        // Ignoring warnings when generating the exit code.
        \PHP_CodeSniffer\Config::setConfigData( 'ignore_warnings_on_exit', true, true );

        // Show only errors?
        \PHP_CodeSniffer\Config::setConfigData( 'show_warnings', $show_warnings, true );

        // Set minimum supported PHP version.
        \PHP_CodeSniffer\Config::setConfigData( 'testVersion', $minimum_php_version . '-', true );

        // Set text domains.
        \PHP_CodeSniffer\Config::setConfigData( 'text_domain', implode( ',', $args['text_domains'] ), true );

        // Path to WordPress Theme coding standard.
        \PHP_CodeSniffer\Config::setConfigData( 'installed_paths', WP_PLUGIN_DIR . '/' . $this->plugin_name . '/vendor/wp-coding-standards/wpcs/', true );

        $runner->config = new Config();
        $runner->init();

        $runner->config->files      = implode( ',', $all_files );
        $runner->config->standards    = $standards_array;
        $runner->config->annotations  = $ignore_annotations;
        $runner->config->verbosity    = 1;
        $runner->config->parallel     = true;
        $runner->config->colors       = false;
        $runner->config->showProgress = true;
        $runner->config->reportWidth  = 110;
        $runner->config->ignored      = $ignored;

        $report = $runner->run();
        error_log( print_r( $report, true ) );
    }
}

I'm calling the run_sniffer via ajax when I click on the button in the theme sniffer.

But I'm getting errors

[09-Jun-2018 14:20:52 UTC] PHP Notice: Undefined index: argv in /srv/www/personal/wordpress-plugin/public_html/wp-content/plugins/theme-sniffer/vendor/squizlabs/php_codesniffer/src/Config.php on line 330
[09-Jun-2018 14:20:52 UTC] PHP Warning: array_shift() expects parameter 1 to be array, null given in /srv/www/personal/wordpress-plugin/public_html/wp-content/plugins/theme-sniffer/vendor/squizlabs/php_codesniffer/src/Config.php on line 331
[09-Jun-2018 14:20:52 UTC] PHP Warning: count(): Parameter must be an array or an object that implements Countable in /srv/www/personal/wordpress-plugin/public_html/wp-content/plugins/theme-sniffer/vendor/squizlabs/php_codesniffer/src/Config.php on line 412
[09-Jun-2018 14:20:52 UTC] PHP Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting end of file in /srv/www/personal/wordpress-plugin/public_html/wp-content/plugins/theme-sniffer/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc on line 160

Some of the variables are set up on the start via $_POST variables (they can be modified in the sniffer).

I must be doing something wrong with the config. Also, should I use runPHPCS() method instead of run() which is private?

@gsherwood
Copy link
Member

Sorry, I didn't realise you were running this outside the CLI environment.

In that case, you need to pass something to the Config class constructor for the first argument. That first argument is where you would pass in a fake $_SERVER['argv'] array that you've constructed via your POST vars.

But you could also just use it to pass in a single command line arg and set the others the way you are already doing. So something like $runner->config = new Config(['-v']); should be enough to stop it looking for argv and letting you continue if you prefer that way.

@dingo-d
Copy link
Author

dingo-d commented Jun 12, 2018

Awesome will test that. Thanks!

@dingo-d
Copy link
Author

dingo-d commented Jun 12, 2018

Ok, this fixed the argv issue, but now I'm getting

PHP Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting end of file in /srv/www/personal/wordpress-plugin/public_html/wp-content/plugins/theme-sniffer/vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc on line 160

When runing the sniffer, which is odd.

I'll try to test a bit more, to see if the issue isn't with the Config().

@gsherwood
Copy link
Member

I don't know why any code would be trying to include test files. That only happens during a unit test run, and you can't kick one of those off without using phpunit. Do you have something that might be including all files inside the PHPCS directory and catching test files as well?

@dingo-d
Copy link
Author

dingo-d commented Jun 13, 2018

Not sure. I'm autoloading files using a classmap, and maybe I loaded something I shouldn't have. I added "vendor/squizlabs/php_codesniffer/" in the classmap, so that I can use

use PHP_CodeSniffer\Runner;
use PHP_CodeSniffer\Config;

In the file I'm using the Runner and Config classes.

I'll try to modify it and see if I'll get the error.

@gsherwood
Copy link
Member

PHPCS has it's own autoloader, so you'll probably want to include that. See the original gist I linked for an example of that.

@dingo-d
Copy link
Author

dingo-d commented Jun 13, 2018

Yeah, I wanted to automate it, by not having to manually use require_once __DIR__.'/autoload.php'; from the phpcs. This probably caused the issue.

@dingo-d
Copy link
Author

dingo-d commented Jun 13, 2018

Ok, the only way I can get it to run is by setting

$_SERVER['argv'] = array( '-v' );
$runner->config = new Config();
$runner->init();

And that returns 3 when I do

$report = $runner->runPHPCS();

error_log( print_r( $report, true ) );

I'll try to set manually through the $_SERVER var, because setting the config by just passing ['-v'] in the Config constructor returns the same argv error.

@gsherwood
Copy link
Member

@dingo-d Any luck? Do you still need help or should I close this?

@dingo-d
Copy link
Author

dingo-d commented Jul 4, 2018

It looks like my config isn't being passed when I just do the $runner->config = new Config();

So I tried some hacks like this

$class = new \ReflectionClass( $runner );
$run = $class->getMethod( 'run' );
$run->setAccessible( true );
$run->invoke( $runner );

$report = $runner->run();
$output = ob_get_clean();

And with that I can get some of the config in the PHP_CodeSniffer, but I doubt I should be using this.

At first I thought that the files aren't passed down correctly (path issue), but that wasn't it.

Any idea why the config isn't working?

The PR I'm working on is this: WPTT/theme-sniffer#83, and my branch is: https://github.com/dingo-d/theme-sniffer/tree/feature/use-namespace

@gsherwood
Copy link
Member

t looks like my config isn't being passed when I just do the $runner->config = new Config();

You can pass an array of CLI args to the Config constructor. If you do this, it wont go searching for $_SERVER['argv']. That's what I mentioned in a previous comment and you said that solved your problem. But you later said it wasn't working and you were getting an argv error again, but there isn't anywhere else in the Config class where $_SERVER is referenced, so I would need to see the error to help out. I'd still suggest passing the array as the right way to achieve this.

@dingo-d
Copy link
Author

dingo-d commented Jul 5, 2018

Oh, so basically, instead of doing this

$runner->config = new Config();
        $runner->init();

        $runner->config->files      = implode( ',', $all_files );
        $runner->config->standards    = $standards_array;
        $runner->config->annotations  = $ignore_annotations;
        $runner->config->verbosity    = 1;
        $runner->config->parallel     = true;
        $runner->config->colors       = false;
        $runner->config->showProgress = true;
        $runner->config->reportWidth  = 110;
        $runner->config->ignored      = $ignored;

I should add the config inside the $_SERVER['argv'] as an associative array?

@gsherwood
Copy link
Member

gsherwood commented Jul 5, 2018

I think we've come full circle :) This previous comment is what I think you should be trying:

In that case, you need to pass something to the Config class constructor for the first argument. That first argument is where you would pass in a fake $_SERVER['argv'] array that you've constructed via your POST vars.

But you could also just use it to pass in a single command line arg and set the others the way you are already doing. So something like $runner->config = new Config(['-v']); should be enough to stop it looking for argv and letting you continue if you prefer that way.

So you could either pass everything into the constructor, or pass at least one option and then continuing setting config vars using $runner->config->...

@dingo-d
Copy link
Author

dingo-d commented Jul 6, 2018

I'll test it this weekend and report back :)

@dingo-d
Copy link
Author

dingo-d commented Jul 7, 2018

I think I narrowed down the problem. I am calling the phpcs with $runner->runPHPCS(); and this will call the $this->config = new Config(); which will delete all the config data I passed down.

So I did it like this:

$ignored = '.*/node_modules/.*,.*/vendor/.*,.*/assets/build/.*,.*/build/.*,.*/bin/.*';

ob_start();
// Set up a PHPCS Runner and Config.
$runner = new Runner();

// Set default standard.
Config::setConfigData( 'default_standard', 'WordPress-Theme', true );

// Ignoring warnings when generating the exit code.
Config::setConfigData( 'ignore_warnings_on_exit', true, true );

// Show only errors?
Config::setConfigData( 'show_warnings', $show_warnings, true );

// Set minimum supported PHP version.
Config::setConfigData( 'testVersion', $minimum_php_version . '-', true );

// Set text domains.
Config::setConfigData( 'text_domain', implode( ',', $args['text_domains'] ), true );

if ( $theme_prefixes !== '' ) {
	// Set prefix.
	Config::setConfigData( 'prefixes', $theme_prefixes, true );
}

// Path to WordPress Theme coding standard.
Config::setConfigData( 'installed_paths', WP_PLUGIN_DIR . '/' . $this->plugin_name . '/vendor/wp-coding-standards/wpcs/', true );

$standards_list = implode( ',', $standards_array );

$cliArgs[] = "--standard={$standards_list}"; // List of standards.

// Ignora annotations.
if ( $ignore_annotations ) {
	$cliArgs[] = '--ignore-annotations';
}

$cliArgs[] = '-vv'; // Verbosity.
$cliArgs[] = '--parallel=5'; // Number of files to run in parallel.
$cliArgs[] = '--no-colors'; // No colors on the output.
$cliArgs[] = '-p'; // Show progress.
$cliArgs[] = '--report-width=110'; // Report width.
$cliArgs[] = "--ignore={$ignored}"; // List of ignored patterns.
$cliArgs[] = implode( ',', $all_files ); // List of files to sniff.

$runner->config = new Config( $cliArgs );
$runner->init();

$report = $runner->runPHPCS();
$output = ob_get_clean();

And now I see this error

[07-Jul-2018 15:53:58 UTC] PHP Warning: Use of undefined constant PHP_CODESNIFFER_CBF - assumed 'PHP_CODESNIFFER_CBF' (this will throw an Error in a future version of PHP) in /srv/www/personal/wordpress-plugin/public_html/wp-content/plugins/theme-sniffer/vendor/squizlabs/php_codesniffer/src/Config.php on line 965
[07-Jul-2018 15:53:58 UTC] PHP Stack trace:
[07-Jul-2018 15:53:58 UTC] PHP 1. {main}() /srv/www/personal/wordpress-plugin/public_html/wp-admin/admin-ajax.php:0
[07-Jul-2018 15:53:58 UTC] PHP 2. do_action($tag = 'wp_ajax_run_sniffer', $arg = uninitialized) /srv/www/personal/wordpress-plugin/public_html/wp-admin/admin-ajax.php:99
[07-Jul-2018 15:53:58 UTC] PHP 3. WP_Hook->do_action($args = array (0 => '')) /srv/www/personal/wordpress-plugin/public_html/wp-includes/plugin.php:453
[07-Jul-2018 15:53:58 UTC] PHP 4. WP_Hook->apply_filters($value = '', $args = array (0 => '')) /srv/www/personal/wordpress-plugin/public_html/wp-includes/class-wp-hook.php:310
[07-Jul-2018 15:53:58 UTC] PHP 5. Theme_Sniffer\Admin\Checks->run_sniffer('') /srv/www/personal/wordpress-plugin/public_html/wp-includes/class-wp-hook.php:286
[07-Jul-2018 15:53:58 UTC] PHP 6. PHP_CodeSniffer\Config->__construct($cliArgs = array (0 => '--standard=WordPress-Theme,WordPress-Extra', 1 => '--ignore-annotations', 2 => '-vv', 3 => '--parallel=5', 4 => '--no-colors', 5 => '-p', 6 => '--report-width=110', 7 => '--ignore=./node_modules/.,./vendor/.,./assets/build/.,./build/.,./bin/.', 8 => '/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/404.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/archive.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/customize-controls.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/customize-preview.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/global.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/html5.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/jquery.scrollTo.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/navigation.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/skip-link-focus-fix.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/comments.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/footer.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/front-page.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/functions.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/header.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/back-compat.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/color-patterns.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/custom-header.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/customizer.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/icon-functions.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/template-functions.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/template-tags.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/index.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/page.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/search.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/searchform.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/sidebar.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/single.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/footer/footer-widgets.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/footer/site-info.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/header/header-image.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/header/site-branding.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/navigation/navigation-top.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/page/content-front-page-panels.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/page/content-front-page.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/page/content-page.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content-audio.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content-excerpt.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content-gallery.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content-image.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content-none.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content-video.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content.php'), $dieOnUnknownArg = uninitialized) /srv/www/personal/wordpress-plugin/public_html/wp-content/plugins/theme-sniffer/admin/class-checks.php:381
[07-Jul-2018 15:53:58 UTC] PHP 7. PHP_CodeSniffer\Config->setCommandLineValues($args = array (0 => '--standard=WordPress-Theme,WordPress-Extra', 1 => '--ignore-annotations', 2 => '-vv', 3 => '--parallel=5', 4 => '--no-colors', 5 => '-p', 6 => '--report-width=110', 7 => '--ignore=./node_modules/.,./vendor/.,./assets/build/.,./build/.,./bin/.', 8 => '/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/404.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/archive.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/customize-controls.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/customize-preview.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/global.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/html5.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/jquery.scrollTo.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/navigation.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/skip-link-focus-fix.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/comments.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/footer.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/front-page.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/functions.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/header.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/back-compat.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/color-patterns.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/custom-header.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/customizer.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/icon-functions.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/template-functions.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/inc/template-tags.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/index.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/page.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/search.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/searchform.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/sidebar.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/single.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/footer/footer-widgets.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/footer/site-info.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/header/header-image.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/header/site-branding.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/navigation/navigation-top.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/page/content-front-page-panels.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/page/content-front-page.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/page/content-page.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content-audio.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content-excerpt.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content-gallery.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content-image.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content-none.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content-video.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/template-parts/post/content.php')) /srv/www/personal/wordpress-plugin/public_html/wp-content/plugins/theme-sniffer/vendor/squizlabs/php_codesniffer/src/Config.php:335
[07-Jul-2018 15:53:58 UTC] PHP 8. PHP_CodeSniffer\Config->processLongArgument($arg = 'standard=WordPress-Theme,WordPress-Extra', $pos = 0) /srv/www/personal/wordpress-plugin/public_html/wp-content/plugins/theme-sniffer/vendor/squizlabs/php_codesniffer/src/Config.php:440

EDIT

I added

        if ( defined( 'PHP_CODESNIFFER_CBF' ) === false ) {
            define( 'PHP_CODESNIFFER_CBF', false );
        }

        if ( defined( 'PHP_CODESNIFFER_VERBOSITY' ) === false ) {
            define( 'PHP_CODESNIFFER_VERBOSITY', 2 );
        }

After the ob_start() and now I have

[07-Jul-2018 16:11:29 UTC] PHP Fatal error: Uncaught PHP_CodeSniffer\Exceptions\DeepExitException: ERROR: The file "/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/404.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/archive.php,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/customize-controls.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/customize-preview.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/global.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/html5.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/jquery.scrollTo.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/navigation.js,/srv/www/personal/wordpress-plugin/public_html/wp-content/themes/twentyseventeen/assets/js/skip-link-focus-fix.js,/srv/www/person in /srv/www/personal/wordpress-plugin/public_html/wp-content/plugins/theme-sniffer/vendor/squizlabs/php_codesniffer/src/Config.php on line 1299

@gsherwood
Copy link
Member

I think I narrowed down the problem. I am calling the phpcs with $runner->runPHPCS(); and this will call the $this->config = new Config(); which will delete all the config data I passed down.

You can't call runPHPCS when you are writing your own runner. That method is what kicks off the main CLI processing code. That's why my original sample gist didn't do that either. You'll need to replicate the parts of functionality you want in your own code.

@dingo-d
Copy link
Author

dingo-d commented Jul 9, 2018

Oh, basically, I'll have to see how that method works, and copy its behavior in my class. Thanks for the help, I'll try to see what else I need.

@gsherwood
Copy link
Member

@dingo-d Just checking in to see if you need more help. This is a long running issue so I'd like to try and resolve it so I can close it. Thanks.

@dingo-d
Copy link
Author

dingo-d commented Jul 31, 2018

I managed to get something by packing the CLI arguments in an array and then passing it to the Config, but I didn't have the time to explore this in detail. Once I'm back from my vacation I'll work on it some more.

Thanks for all the suggestions, they helped :)

@gsherwood
Copy link
Member

Thanks for all the suggestions, they helped :)

No problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants