2013-05-22 22:43:19 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2014-05-12 18:26:17 +02:00
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2014, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link https://www.phptesting.org/
|
|
|
|
*/
|
2013-05-22 22:43:19 +02:00
|
|
|
|
|
|
|
namespace PHPCI\Plugin;
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
use PHPCI\Builder;
|
|
|
|
use PHPCI\Model\Build;
|
|
|
|
|
2013-05-22 22:43:19 +02:00
|
|
|
/**
|
|
|
|
* PHP CS Fixer - Works with the PHP CS Fixer for testing coding standards.
|
|
|
|
* @author Gabriel Baker <gabriel@autonomicpilot.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Plugins
|
|
|
|
*/
|
|
|
|
class PhpCsFixer implements \PHPCI\Plugin
|
|
|
|
{
|
2014-05-02 15:48:40 +02:00
|
|
|
/**
|
|
|
|
* @var \PHPCI\Builder
|
|
|
|
*/
|
2013-05-22 22:43:19 +02:00
|
|
|
protected $phpci;
|
|
|
|
|
2014-05-02 15:48:40 +02:00
|
|
|
/**
|
|
|
|
* @var \PHPCI\Model\Build
|
|
|
|
*/
|
|
|
|
protected $build;
|
|
|
|
|
2013-05-22 22:53:56 +02:00
|
|
|
protected $workingDir = '';
|
2013-10-10 02:01:06 +02:00
|
|
|
protected $level = ' --level=all';
|
|
|
|
protected $verbose = '';
|
|
|
|
protected $diff = '';
|
2013-05-22 22:53:56 +02:00
|
|
|
protected $levels = array('psr0', 'psr1', 'psr2', 'all');
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
public function __construct(Builder $phpci, Build $build, array $options = array())
|
2013-05-22 22:43:19 +02:00
|
|
|
{
|
|
|
|
$this->phpci = $phpci;
|
2014-05-02 15:48:40 +02:00
|
|
|
$this->build = $build;
|
|
|
|
|
2013-05-22 22:43:19 +02:00
|
|
|
$this->workingdir = $this->phpci->buildPath;
|
|
|
|
$this->buildArgs($options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute()
|
|
|
|
{
|
2013-05-22 22:53:56 +02:00
|
|
|
$curdir = getcwd();
|
2013-05-22 22:43:19 +02:00
|
|
|
chdir($this->workingdir);
|
|
|
|
|
2013-10-08 09:50:10 +02:00
|
|
|
$phpcsfixer = $this->phpci->findBinary('php-cs-fixer');
|
|
|
|
|
|
|
|
if (!$phpcsfixer) {
|
|
|
|
$this->phpci->logFailure('Could not find php-cs-fixer.');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
$cmd = $phpcsfixer . ' fix . %s %s %s';
|
|
|
|
$success = $this->phpci->executeCommand($cmd, $this->verbose, $this->diff, $this->level);
|
2013-05-22 22:43:19 +02:00
|
|
|
|
|
|
|
chdir($curdir);
|
|
|
|
|
|
|
|
return $success;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildArgs($options)
|
|
|
|
{
|
2013-10-10 02:01:06 +02:00
|
|
|
if (isset($options['verbose']) && $options['verbose']) {
|
|
|
|
$this->verbose = ' --verbose';
|
2013-05-22 22:53:56 +02:00
|
|
|
}
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
if (isset($options['diff']) && $options['diff']) {
|
|
|
|
$this->diff = ' --diff';
|
2013-05-22 22:53:56 +02:00
|
|
|
}
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
if (isset($options['level']) && in_array($options['level'], $this->levels)) {
|
|
|
|
$this->level = ' --level='.$options['level'];
|
2013-05-22 22:53:56 +02:00
|
|
|
}
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
if (isset($options['workingdir']) && $options['workingdir']) {
|
|
|
|
$this->workingdir = $this->phpci->buildPath . $options['workingdir'];
|
2013-05-22 22:53:56 +02:00
|
|
|
}
|
2013-05-22 22:43:19 +02:00
|
|
|
|
|
|
|
}
|
2013-10-10 02:01:06 +02:00
|
|
|
}
|