Last active
March 22, 2016 09:40
-
-
Save dongilbert/6186988 to your computer and use it in GitHub Desktop.
PhpLint Plugin for PHPCI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 <[email protected]> | |
* @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