-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
590f4cb
commit 10bc397
Showing
12 changed files
with
299 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/.vscode/ | ||
/build/ | ||
/coverage/ | ||
/doc/ | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace SugaredRim\PHP\CodeSniffer; | ||
|
||
class Config extends \PHP_CodeSniffer\Config | ||
{ | ||
use SugaredRimConfigAwareTrait; | ||
|
||
public function __construct(array $cliArgs = [], $dieOnUnknownArg = true, callable $finderByConfig = null) | ||
{ | ||
$this->sugaredRimSetFinderByConfig($finderByConfig); | ||
parent::__construct($cliArgs, $dieOnUnknownArg); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace SugaredRim\PHP\CodeSniffer; | ||
|
||
class Runner extends \PHP_CodeSniffer\Runner | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $sugaredRimTrigger; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function init():void | ||
{ | ||
$this->config = new Config(); | ||
|
||
// v3.* and still sucks :-( | ||
if ($this->sugaredRimTrigger === 'runPHPCBF') { | ||
if ($this->config->stdin === true) { | ||
$this->config->verbosity = 0; | ||
} | ||
} | ||
|
||
parent::init(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function runPHPCS() | ||
{ | ||
$this->sugaredRimTrigger = 'runPHPCS'; | ||
return parent::runPHPCS(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function runPHPCBF() | ||
{ | ||
$this->sugaredRimTrigger = 'runPHPCBF'; | ||
return parent::runPHPCBF(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace SugaredRim\PHP\CodeSniffer; | ||
|
||
use Schnittstabil\ComposerExtra\ComposerExtra; | ||
use Schnittstabil\FinderByConfig\FinderByConfig; | ||
|
||
trait SugaredRimConfigAwareTrait | ||
{ | ||
protected $sugaredRimNamespace = 'sugared-rim/php_codesniffer'; | ||
protected $sugaredRimfinderByConfig; | ||
protected $sugaredRimDefaultConfig; | ||
protected $sugaredRimConfig; | ||
|
||
protected function sugaredRimSetFinderByConfig(callable $finderByConfig = null) | ||
{ | ||
if ($finderByConfig === null) { | ||
$finderByConfig = new FinderByConfig(); | ||
} | ||
$this->sugaredRimfinderByConfig = $finderByConfig; | ||
|
||
$this->sugaredRimDefaultConfig = new \stdClass(); | ||
$this->sugaredRimDefaultConfig->presets = [ | ||
'SugaredRim\\PHP\\CodeSniffer\\DefaultPreset::get', | ||
]; | ||
} | ||
|
||
protected function sugaredRimGetConfig($path = null, $default = null) | ||
{ | ||
if ($this->sugaredRimConfig === null) { | ||
$this->sugaredRimConfig = new ComposerExtra( | ||
$this->sugaredRimNamespace, | ||
$this->sugaredRimDefaultConfig, | ||
'presets' | ||
); | ||
} | ||
|
||
if ($path === null) { | ||
$path = array(); | ||
} | ||
|
||
return $this->sugaredRimConfig->get($path, $default); | ||
} | ||
|
||
public function processLongArgument($arg, $pos) | ||
{ | ||
if (substr($arg, 0, 10) === 'namespace=') { | ||
$this->sugaredRimNamespace = substr($arg, 10); | ||
|
||
return; | ||
} | ||
|
||
parent::processLongArgument($arg, $pos); | ||
} | ||
|
||
public function setCommandLineValues($args) | ||
{ | ||
parent::setCommandLineValues($args); | ||
|
||
if (isset($this->values) && !empty($this->values['files'])) { | ||
// v2.* | ||
return; | ||
} elseif (isset($this->files) && !empty($this->files)) { | ||
// v3.* | ||
return; | ||
} | ||
|
||
$files = $this->sugaredRimGetConfig('files', []); | ||
|
||
foreach (call_user_func($this->sugaredRimfinderByConfig, $files) as $file) { | ||
$this->processUnknownArgument($file->getPathname(), -1); | ||
} | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.StaticAccess) | ||
*/ | ||
protected function sugaredRimProcessConfig() | ||
{ | ||
foreach ($this->sugaredRimGetConfig() as $key => $value) { | ||
switch ($key) { | ||
case 'presets': | ||
case 'files': | ||
continue 2; | ||
case 'default_standard': | ||
if (is_array($value)) { | ||
$value = implode(',', $value); | ||
} | ||
} | ||
|
||
$this->sugaredRimSetConfigData($key, $value); | ||
} | ||
} | ||
|
||
abstract public function setConfigData($key, $value, $temp = false); | ||
|
||
protected function sugaredRimSetConfigData($key, $value) | ||
{ | ||
if (method_exists($this, 'setConfigData')) { | ||
$this->setConfigData($key, $value, true); | ||
} else { | ||
\PHP_CodeSniffer::setConfigData($key, $value, true); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.