diff --git a/PHPCI/Plugin/PhpCsFixer.php b/PHPCI/Plugin/PhpCsFixer.php new file mode 100644 index 00000000..b4d298e9 --- /dev/null +++ b/PHPCI/Plugin/PhpCsFixer.php @@ -0,0 +1,89 @@ + +* @package PHPCI +* @subpackage Plugins +*/ +class PhpCsFixer implements \PHPCI\Plugin +{ + protected $phpci; + + protected $args = ''; + + protected $workingDir = ''; + protected $level = 'all'; + protected $dryRun = true; + protected $verbose = false; + protected $diff = false; + protected $levels = array('psr0', 'psr1', 'psr2', 'all'); + + public function __construct(\PHPCI\Builder $phpci, array $options = array()) + { + $this->phpci = $phpci; + $this->workingdir = $this->phpci->buildPath; + $this->buildArgs($options); + } + + public function execute() + { + $success = false; + + $curdir = getcwd(); + chdir($this->workingdir); + + $cmd = PHPCI_BIN_DIR . 'php-cs-fixer fix . %s'; + $success = $this->phpci->executeCommand($cmd, $this->args); + + chdir($curdir); + + return $success; + } + + public function buildArgs($options) + { + $argstring = ""; + + if ( array_key_exists('verbose', $options) && $options['verbose'] ) + { + $this->verbose = true; + $this->args .= ' --verbose'; + } + + if ( array_key_exists('diff', $options) && $options['diff'] ) + { + $this->diff = true; + $this->args .= ' --diff'; + } + + if ( array_key_exists('level', $options) && array_key_exists($options['level'], $this->levels) ) + { + $this->level = $options['level']; + $this->args .= ' --level='.$options['level']; + } + + if ( array_key_exists('dryrun', $options) && $options['dryrun'] ) + { + $this->dryRun = true; + $this->args .= ' --dry-run'; + } + + if ( array_key_exists('workingdir', $options) + && $options['workingdir'] + && is_dir($this->phpci->buildPath.$options['workingdir']) ) + { + $this->workingdir = $this->phpci->buildPath.$options['workingdir']; + } + + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index 03e9ec38..7b8c37b3 100644 --- a/composer.json +++ b/composer.json @@ -1,36 +1,37 @@ { - "name": "block8/phpci", - "description": "Simple continuous integration for PHP projects.", + "name" : "block8/phpci", + "description" : "Simple continuous integration for PHP projects.", "minimum-stability": "dev", - "type": "library", - "keywords": ["php", "phpci", "ci", "continuous", "integration", "testing", "phpunit", "continuous integration", "jenkins", "travis"], - "homepage": "http://www.phptesting.org/", - "license": "BSD-2-Clause", + "type" : "library", + "keywords" : ["php", "phpci", "ci", "continuous", "integration", "testing", "phpunit", "continuous integration", "jenkins", "travis"], + "homepage" : "http://www.phptesting.org/", + "license" : "BSD-2-Clause", "authors": [ { - "name": "Dan Cryer", - "email": "dan.cryer@block8.co.uk", + "name" : "Dan Cryer", + "email" : "dan.cryer@block8.co.uk", "homepage": "http://www.block8.co.uk", - "role": "Developer" + "role" : "Developer" } ], "support": { - "email": "hello+phpci@block8.co.uk", + "email" : "hello+phpci@block8.co.uk", "issues": "https://github.com/Block8/PHPCI/issues", "source": "https://github.com/Block8/PHPCI" }, "require": { - "block8/b8framework": "dev-master", - "phpunit/phpunit": "3.*", - "phpmd/phpmd" : "1.*", - "sebastian/phpcpd": "1.*", + "block8/b8framework" : "dev-master", + "phpunit/phpunit" : "3.*", + "phpmd/phpmd" : "1.*", + "sebastian/phpcpd" : "1.*", "squizlabs/php_codesniffer": "1.*", "ircmaxell/password-compat": "1.x", - "phpspec/phpspec": "2.*", - "symfony/yaml": "2.2.x-dev", - "symfony/console": "2.2.*" + "phpspec/phpspec" : "2.*", + "symfony/yaml" : "2.2.x-dev", + "symfony/console" : "2.2.*", + "fabpot/php-cs-fixer" : "0.3.*@dev" } }