[libcode-tidyall-perl] 326/374: PHPCodeSniffer support.
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 22:26:44 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libcode-tidyall-perl.
commit 89dd4827e10648a2ba09a7ca472bae938984da81
Author: Joe Crotty <joe.crotty at returnpath.net>
Date: Mon Oct 15 08:20:20 2012 -0600
PHPCodeSniffer support.
Good start, but not sure how to handle cases where phpcs says
the code is clean. The difference is phpcs will exit 0 when code
is clean and non zero otherwise. Don't know how in TidyAll to trap
on that.
A sample of some clean code sniffed by phpcs:
$ tidyall -a
[checked] views/TwigExtensionFilters.class.php
Time: 0 seconds, Memory: 3.00Mb
$ echo $?
0
Change-Id: I15d72fce2223994055dee5aa79c9d96a24e8f996
---
lib/Code/TidyAll/Plugin/PHPCodeSniffer.pm | 60 +++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/lib/Code/TidyAll/Plugin/PHPCodeSniffer.pm b/lib/Code/TidyAll/Plugin/PHPCodeSniffer.pm
new file mode 100644
index 0000000..87cff83
--- /dev/null
+++ b/lib/Code/TidyAll/Plugin/PHPCodeSniffer.pm
@@ -0,0 +1,60 @@
+package Code::TidyAll::Plugin::PHPCodeSniffer;
+use Capture::Tiny qw(capture_merged);
+use Moo;
+extends 'Code::TidyAll::Plugin';
+
+sub _build_cmd { 'phpcs' }
+
+sub validate_file {
+ my ( $self, $file ) = @_;
+
+ my $cmd = sprintf( "%s %s %s", $self->cmd, $self->argv, $file );
+ my $output = capture_merged { system($cmd) };
+ die "$output\n" if $output !~ /^.* source OK\n/;
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Code::TidyAll::Plugin::PHPCodeSniffer - use phpcs with tidyall
+
+=head1 VERSION
+
+version 0.15
+
+=head1 SYNOPSIS
+
+ In configuration:
+
+ ; Configure in-line
+ ;
+ [PHPCodeSniffer]
+ select = /my/project/**/*.php
+ argv = --standard=/my/project/phpcs.xml --ignore=*/tests/*,*/data/*
+
+=head1 DESCRIPTION
+
+Runs L<phpcs|http://pear.php.net/package/PHP_CodeSniffer> which tokenises PHP,
+JavaScript and CSS files and detects violations of a defined set of coding
+standards.
+
+=head1 INSTALLATION
+
+Install phpcs from PEAR.
+
+ pear install PHP_CodeSniffer
+
+=head1 CONFIGURATION
+
+=over
+
+=item argv
+
+Arguments to pass to phpcs
+
+=back
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcode-tidyall-perl.git
More information about the Pkg-perl-cvs-commits
mailing list