Guest User

Untitled

a guest
Dec 8th, 2011
431
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/php
  2. <?php
  3.  
  4.  
  5. $params = explode(' ', file_get_contents('php://stdin'));
  6. $ref = trim($params[1]);
  7.  
  8. $diff = array();
  9. $return = 0;
  10.  
  11. exec("git diff --name-only $params[0] $params[1] 2> /dev/null", $diff, $return);
  12.  
  13. if ($return > 0) {
  14.  
  15.   echo "Could not run git diff\n\n";
  16.   exit(1);
  17. }
  18.  
  19. $filename_pattern = '/\.php$/';
  20.  
  21. foreach ($diff as $file) {
  22.  
  23.     if (!preg_match($filename_pattern, $file)) {
  24.  
  25.         continue;
  26.     }
  27.  
  28.     $tree = array();
  29.     $return = 0;
  30.     exec("git ls-tree $ref $file 2> /dev/null", $tree, $return);
  31.     if ($return > 0 || empty($tree)) {
  32.  
  33.         echo "Deleted file '$file'! skipping test...\n\n";
  34.         continue;
  35.     }
  36.     echo "\nRunning php linter on '$file'...\n";
  37.     $tree = preg_split('/\s/', $tree[0]);
  38.  
  39.     $fileContents = array();
  40.     exec("git cat-file $tree[1] $tree[2] 2> /dev/null", $fileContents, $return);
  41.     if ($return > 0) {
  42.  
  43.         echo "Could not run git cat-file\n\n";
  44.         exit(1);
  45.     }
  46.     $fileContents = implode("\n", $fileContents);
  47.  
  48.     $pipes = array();
  49.     $proc = proc_open('php -l',
  50.                   array(0 => array('pipe', 'r'),
  51.                         1 => array('pipe', 'w')),
  52.                 $pipes);
  53.  
  54.     if (!is_resource($proc)) {
  55.  
  56.         echo "Could not creater php linter process\n\n";
  57.         exit(1);
  58.     }
  59.  
  60.     fwrite($pipes[0], $fileContents);
  61.     fclose($pipes[0]);
  62.     fclose($pipes[1]);
  63.     $resultCode = proc_close($proc);
  64.  
  65.     if ($resultCode != 0) {
  66.  
  67.         echo "Error parsing file '$file'\n\n";
  68.         exit($resultCode);
  69.     }
  70.     print "'$file' PASSED linter test..\n\n";
  71.  
  72.     print "Running code standard test on '$file'...\n\n";
  73.  
  74.     // also check coding standard
  75.     $pipes = array();
  76.     $proc = proc_open('phpcs --standard=drupalcs',
  77.                   array(0 => array('pipe', 'r'),
  78.                         1 => array('pipe', 'w')),
  79.                 $pipes);
  80.  
  81.     if (!is_resource($proc)) {
  82.  
  83.         echo "Could not creater phpcs process\n\n";
  84.         exit(1);
  85.     }
  86.  
  87.     fwrite($pipes[0], $fileContents);
  88.     fclose($pipes[0]);
  89.     echo stream_get_contents($pipes[1]);
  90.     fclose($pipes[1]);
  91.     $resultCode = proc_close($proc);
  92.     if ($resultCode != 0) {
  93.         echo "File '$file' does not follow drupal code standard\n\n";
  94.         exit($resultCode);
  95.     }
  96.    
  97.     print "'$file' PASSED code standard test...\n\n";
  98.  
  99. }
  100.  
  101. echo "No errors detected\n\n";
  102. exit(0);
  103.  
  104.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×