[libcode-tidyall-perl] 330/374: add PHPCodeSniffer

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:26:45 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 7994097c6f967c5f42a07cf1f6052b93a2cbf8db
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Wed Oct 17 01:15:24 2012 -0700

    add PHPCodeSniffer
---
 .ispell_english                             |    6 ++++--
 Changes                                     |    3 +++
 lib/Code/TidyAll/Plugin/PHPCodeSniffer.pm   |   26 ++++++++++++++-----------
 lib/Code/TidyAll/t/Plugin/PHPCodeSniffer.pm |   28 +++++++++++++++++++++++++++
 xt/author/Plugin-PHPCodeSniffer.t           |    3 +++
 5 files changed, 53 insertions(+), 13 deletions(-)

diff --git a/.ispell_english b/.ispell_english
index 5c7fab9..0dbed4e 100644
--- a/.ispell_english
+++ b/.ispell_english
@@ -1,8 +1,8 @@
-Raggett
-sourceforge
 API
 CPAN
 JavaScript
+PHP
+Raggett
 STDERR
 STDIN
 STDOUT
@@ -33,12 +33,14 @@ params
 perlcritic
 perlcriticrc
 perltidy
+phpcs
 plugins
 podspell
 podtidy
 pre
 repo
 repos
+sourceforge
 svn
 tidiers
 tidyall
diff --git a/Changes b/Changes
index a945434..7efdc94 100644
--- a/Changes
+++ b/Changes
@@ -4,6 +4,9 @@ Revision history for Code-TidyAll
 
 0.16  Oct 11, 2012
 
+* Plugins
+  - Add PHPCodeSniffer plugin (Joseph Crotty)
+
 0.15  Oct 11, 2012
 
 * Fixes
diff --git a/lib/Code/TidyAll/Plugin/PHPCodeSniffer.pm b/lib/Code/TidyAll/Plugin/PHPCodeSniffer.pm
index 87cff83..674e6f3 100644
--- a/lib/Code/TidyAll/Plugin/PHPCodeSniffer.pm
+++ b/lib/Code/TidyAll/Plugin/PHPCodeSniffer.pm
@@ -1,5 +1,6 @@
 package Code::TidyAll::Plugin::PHPCodeSniffer;
-use Capture::Tiny qw(capture_merged);
+use IPC::System::Simple qw(runx EXIT_ANY);
+use Capture::Tiny qw(capture_stdout);
 use Moo;
 extends 'Code::TidyAll::Plugin';
 
@@ -8,9 +9,13 @@ 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/;
+    my $exit;
+    my @cmd = ( $self->cmd, $self->argv, $file );
+    my $output = capture_stdout { $exit = runx( EXIT_ANY, @cmd ) };
+    if ( $exit > 0 ) {
+        $output ||= "problem running " . $self->cmd;
+        die "$output\n";
+    }
 }
 
 1;
@@ -31,21 +36,20 @@ version 0.15
 
    In configuration:
 
-   ; Configure in-line
-   ;
    [PHPCodeSniffer]
-   select = /my/project/**/*.php
-   argv = --standard=/my/project/phpcs.xml --ignore=*/tests/*,*/data/*
+   select = htdocs/**/*.{php,js,css}
+   cmd = /usr/local/pear/bin/phpcs
+   argv = --severity 4
 
 =head1 DESCRIPTION
 
-Runs L<phpcs|http://pear.php.net/package/PHP_CodeSniffer> which tokenises PHP,
+Runs L<phpcs|http://pear.php.net/package/PHP_CodeSniffer> which analyzes PHP,
 JavaScript and CSS files and detects violations of a defined set of coding
 standards.
 
 =head1 INSTALLATION
 
-Install phpcs from PEAR.
+Install L<PEAR|http://pear.php.net/>, then install C<phpcs> from PEAR:
 
     pear install PHP_CodeSniffer
 
@@ -55,6 +59,6 @@ Install phpcs from PEAR.
 
 =item argv
 
-Arguments to pass to phpcs
+Arguments to pass to C<phpcs>
 
 =back
diff --git a/lib/Code/TidyAll/t/Plugin/PHPCodeSniffer.pm b/lib/Code/TidyAll/t/Plugin/PHPCodeSniffer.pm
new file mode 100644
index 0000000..2f1ef4a
--- /dev/null
+++ b/lib/Code/TidyAll/t/Plugin/PHPCodeSniffer.pm
@@ -0,0 +1,28 @@
+package Code::TidyAll::t::Plugin::PHPCodeSniffer;
+use Test::Class::Most parent => 'Code::TidyAll::t::Plugin';
+
+sub test_filename { 'foo.php' }
+
+sub test_main : Tests {
+    my $self   = shift;
+    my $cmd    = '/usr/local/pear/bin/phpcs';
+    my $source = '<?php function foo() { $bar = 5 } ?>';
+
+    $self->tidyall(
+        source    => $source,
+        conf      => { cmd => $cmd, argv => "--severity=6" },
+        expect_ok => 1,
+    );
+    $self->tidyall(
+        source       => $source,
+        conf         => { cmd => $cmd, argv => "--severity=3" },
+        expect_error => qr/Missing .* doc/,
+    );
+    $self->tidyall(
+        source       => $source,
+        conf         => { cmd => $cmd, argv => "--blahblah" },
+        expect_error => qr/not known/,
+    );
+}
+
+1;
diff --git a/xt/author/Plugin-PHPCodeSniffer.t b/xt/author/Plugin-PHPCodeSniffer.t
new file mode 100644
index 0000000..c22218d
--- /dev/null
+++ b/xt/author/Plugin-PHPCodeSniffer.t
@@ -0,0 +1,3 @@
+#!/usr/bin/perl
+use Code::TidyAll::t::Plugin::PHPCodeSniffer;
+Code::TidyAll::t::Plugin::PHPCodeSniffer->runtests;

-- 
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