Skip to content

Instantly share code, notes, and snippets.

@dongilbert
Last active March 22, 2016 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dongilbert/6186988 to your computer and use it in GitHub Desktop.
Save dongilbert/6186988 to your computer and use it in GitHub Desktop.
PhpLint Plugin for PHPCI
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2013, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/
*/
namespace PHPCI\Plugin;
/**
* PHP Lint - Allows PHP syntax checking.
* @author Don Gilbert <don@dongilbert.net>
* @package PHPCI
* @subpackage Plugins
*/
class PhpLint implements \PHPCI\Plugin
{
/**
* @var string
*/
protected $directories = array();
/**
* @var \PHPCI\Builder
*/
protected $phpci;
protected $disallowed = array('.git', '.svn');
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
$this->directories = isset($options['directories']) ? $options['directories'] : array('');
}
/**
* Runs PHP Lint in the specified directories.
*/
public function execute()
{
$success = true;
foreach ($this->directories as $dir) {
$checkDirectory = realpath($this->phpci->buildPath . $dir);
$this->phpci->log('Checking directory: "'.$checkDirectory.'"', ' ');
$dirIterator = new \RecursiveDirectoryIterator($checkDirectory);
$iteIterator = new \RecursiveIteratorIterator($dirIterator);
$regIterator = new \RegexIterator($iteIterator, '/^.+\.php$/i');
foreach ($regIterator as $file) {
$output = array();
$status = 0;
exec('php -d display_errors=0 -l '.$file, $output, $status);
$output = str_replace($checkDirectory, '', $output[0]);
if ($status === 0) {
$this->phpci->logSuccess($output, ' ');
} else {
$this->phpci->logError($output, ' ');
$success = false;
}
}
}
return ($success === false) ? false : true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment