Fixed PhpCsFixer directory. Issue #75.
This commit is contained in:
parent
92e535dffd
commit
41f7597c05
|
@ -13,6 +13,7 @@ Configuration
|
||||||
* **directory** [string, optional] - The directory in which PHP CS Fixer should work (default: `%BUILD_PATH%`)
|
* **directory** [string, optional] - The directory in which PHP CS Fixer should work (default: `%BUILD_PATH%`)
|
||||||
* **rules** [string, optional] - Fixer rules (default: `@PSR2`)
|
* **rules** [string, optional] - Fixer rules (default: `@PSR2`)
|
||||||
* **args** [string, optional] - Command line args (in string format) to pass to PHP Coding Standards Fixer (default: ``)
|
* **args** [string, optional] - Command line args (in string format) to pass to PHP Coding Standards Fixer (default: ``)
|
||||||
|
* **config** [string, optional] - Special config file (default: `%BUILD_PATH%./.php_cs` or `%BUILD_PATH%./.php_cs.dist`)
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
|
@ -31,3 +32,9 @@ test:
|
||||||
diff: true
|
diff: true
|
||||||
rules: "@PSR2"
|
rules: "@PSR2"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```yml
|
||||||
|
test:
|
||||||
|
php_cs_fixer:
|
||||||
|
config: "./my/dir/.php_cs.special"
|
||||||
|
```
|
||||||
|
|
|
@ -16,6 +16,12 @@ class PhpCsFixer extends Plugin
|
||||||
protected $directory = null;
|
protected $directory = null;
|
||||||
protected $args = '';
|
protected $args = '';
|
||||||
|
|
||||||
|
protected $config = false;
|
||||||
|
protected $configs = [
|
||||||
|
'.php_cs',
|
||||||
|
'.php_cs.dist',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -47,6 +53,11 @@ class PhpCsFixer extends Plugin
|
||||||
$this->args .= ' --rules=' . $options['rules'];
|
$this->args .= ' --rules=' . $options['rules'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($options['config']) && $options['config']) {
|
||||||
|
$this->config = true;
|
||||||
|
$this->args .= ' --config=' . $builder->interpolate($options['config']);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($options['directory']) && $options['directory']) {
|
if (isset($options['directory']) && $options['directory']) {
|
||||||
$this->directory = $builder->interpolate($options['directory']);
|
$this->directory = $builder->interpolate($options['directory']);
|
||||||
}
|
}
|
||||||
|
@ -55,17 +66,31 @@ class PhpCsFixer extends Plugin
|
||||||
/**
|
/**
|
||||||
* Run PHP CS Fixer.
|
* Run PHP CS Fixer.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
$cmd = '';
|
$directory = '';
|
||||||
if (!empty($this->directory)) {
|
if (!empty($this->directory)) {
|
||||||
$cmd = 'cd ' . $this->directory . ' && ';
|
$directory = $this->directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->config) {
|
||||||
|
foreach ($this->configs as $config) {
|
||||||
|
if (file_exists($this->builder->buildPath . '/' . $config)) {
|
||||||
|
$this->config = true;
|
||||||
|
$this->args .= ' --config=./' . $config;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->config && !$directory) {
|
||||||
|
$directory = '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
$phpCsFixer = $this->builder->findBinary('php-cs-fixer');
|
$phpCsFixer = $this->builder->findBinary('php-cs-fixer');
|
||||||
$cmd .= $phpCsFixer . ' fix . %s';
|
$cmd = $phpCsFixer . ' fix ' . $directory . ' %s';
|
||||||
$success = $this->builder->executeCommand($cmd, $this->args);
|
$success = $this->builder->executeCommand($cmd, $this->args);
|
||||||
|
|
||||||
return $success;
|
return $success;
|
||||||
|
|
Loading…
Reference in a new issue