CS Fixer
This commit is contained in:
parent
d218554bfa
commit
e8d043fdfd
|
@ -18,40 +18,40 @@ class TechnicalDebt extends Plugin implements ZeroConfigPluginInterface
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $suffixes;
|
protected $suffixes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $directory;
|
protected $directory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected $allowed_errors;
|
protected $allowed_errors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array - paths to ignore
|
* @var array - paths to ignore
|
||||||
*/
|
*/
|
||||||
protected $ignore;
|
protected $ignore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array - terms to search for
|
* @var array - terms to search for
|
||||||
*/
|
*/
|
||||||
protected $searches;
|
protected $searches;
|
||||||
|
|
||||||
public $errorPerFile = [];
|
protected $errorPerFile = [];
|
||||||
public $currentLineSize = 0;
|
protected $currentLineSize = 0;
|
||||||
public $lineNumber = 0;
|
protected $lineNumber = 0;
|
||||||
public $numberOfAnalysedFile = 0;
|
protected $numberOfAnalysedFile = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function pluginName()
|
public static function pluginName()
|
||||||
{
|
{
|
||||||
return 'technical_debt';
|
return 'technical_debt';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Store the statu of the file :
|
* Store the statu of the file :
|
||||||
* . : checked no errors
|
* . : checked no errors
|
||||||
|
@ -59,20 +59,20 @@ class TechnicalDebt extends Plugin implements ZeroConfigPluginInterface
|
||||||
*
|
*
|
||||||
* @param string $char
|
* @param string $char
|
||||||
*/
|
*/
|
||||||
protected function buildLogString($char)
|
protected function buildLogString($char)
|
||||||
{
|
{
|
||||||
if (isset($this->errorPerFile[$this->lineNumber])){
|
if (isset($this->errorPerFile[$this->lineNumber])) {
|
||||||
$this->errorPerFile[$this->lineNumber].= $char;
|
$this->errorPerFile[$this->lineNumber].= $char;
|
||||||
}else{
|
} else {
|
||||||
$this->errorPerFile[$this->lineNumber] = $char;
|
$this->errorPerFile[$this->lineNumber] = $char;
|
||||||
|
}
|
||||||
|
$this->currentLineSize++;
|
||||||
|
$this->numberOfAnalysedFile++;
|
||||||
|
if ($this->currentLineSize>59) {
|
||||||
|
$this->currentLineSize = 0;
|
||||||
|
$this->lineNumber++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->currentLineSize++;
|
|
||||||
$this->numberOfAnalysedFile++;
|
|
||||||
if ($this->currentLineSize>59){
|
|
||||||
$this->currentLineSize = 0;
|
|
||||||
$this->lineNumber++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a visual representation of file with Todo
|
* Create a visual representation of file with Todo
|
||||||
|
@ -80,61 +80,62 @@ class TechnicalDebt extends Plugin implements ZeroConfigPluginInterface
|
||||||
*
|
*
|
||||||
* @return string The visual representation
|
* @return string The visual representation
|
||||||
*/
|
*/
|
||||||
protected function returnResult()
|
protected function returnResult()
|
||||||
{
|
{
|
||||||
$string='';
|
$string='';
|
||||||
$nb=0;
|
$fileNumber=0;
|
||||||
foreach ($this->errorPerFile as $id => $uneLigne){
|
foreach ($this->errorPerFile as $uneLigne) {
|
||||||
$nb+=strlen($uneLigne);
|
$fileNumber+=strlen($uneLigne);
|
||||||
$string.=str_pad($uneLigne,60, ' ', STR_PAD_RIGHT);;
|
$string.=str_pad($uneLigne, 60, ' ', STR_PAD_RIGHT);
|
||||||
$string.=str_pad($nb,4, ' ', STR_PAD_LEFT);
|
;
|
||||||
$string.="/".$this->numberOfAnalysedFile." (".floor($nb*100/$this->numberOfAnalysedFile)." %)\n";
|
$string.=str_pad($fileNumber, 4, ' ', STR_PAD_LEFT);
|
||||||
|
$string.="/".$this->numberOfAnalysedFile." (".floor($fileNumber*100/$this->numberOfAnalysedFile)." %)\n";
|
||||||
|
}
|
||||||
|
$string.= "Checked $fileNumber files\n";
|
||||||
|
return $string;
|
||||||
}
|
}
|
||||||
$string.= "Checked $nb files\n";
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||||
{
|
{
|
||||||
parent::__construct($builder, $build, $options);
|
parent::__construct($builder, $build, $options);
|
||||||
|
|
||||||
$this->suffixes = ['php'];
|
$this->suffixes = ['php'];
|
||||||
$this->directory = $this->builder->buildPath;
|
$this->directory = $this->builder->buildPath;
|
||||||
$this->ignore = $this->builder->ignore;
|
$this->ignore = $this->builder->ignore;
|
||||||
$this->allowed_errors = 0;
|
$this->allowed_errors = 0;
|
||||||
$this->searches = ['TODO', 'FIXME', 'TO DO', 'FIX ME'];
|
$this->searches = ['TODO', 'FIXME', 'TO DO', 'FIX ME'];
|
||||||
|
|
||||||
if (!empty($options['suffixes']) && is_array($options['suffixes'])) {
|
if (!empty($options['suffixes']) && is_array($options['suffixes'])) {
|
||||||
$this->suffixes = $options['suffixes'];
|
$this->suffixes = $options['suffixes'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($options['searches']) && is_array($options['searches'])) {
|
||||||
|
$this->searches = $options['searches'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($options['zero_config']) && $options['zero_config']) {
|
||||||
|
$this->allowed_errors = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setOptions($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($options['searches']) && is_array($options['searches'])) {
|
|
||||||
$this->searches = $options['searches'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($options['zero_config']) && $options['zero_config']) {
|
|
||||||
$this->allowed_errors = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setOptions($options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle this plugin's options.
|
* Handle this plugin's options.
|
||||||
*
|
*
|
||||||
* @param $options
|
* @param $options
|
||||||
*/
|
*/
|
||||||
protected function setOptions($options)
|
protected function setOptions($options)
|
||||||
{
|
{
|
||||||
foreach (['directory', 'ignore', 'allowed_errors'] as $key) {
|
foreach (['directory', 'ignore', 'allowed_errors'] as $key) {
|
||||||
if (array_key_exists($key, $options)) {
|
if (array_key_exists($key, $options)) {
|
||||||
$this->{$key} = $options[$key];
|
$this->{$key} = $options[$key];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this plugin can be executed.
|
* Check if this plugin can be executed.
|
||||||
|
@ -145,108 +146,106 @@ class TechnicalDebt extends Plugin implements ZeroConfigPluginInterface
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function canExecute($stage, Builder $builder, Build $build)
|
public static function canExecute($stage, Builder $builder, Build $build)
|
||||||
{
|
{
|
||||||
if ($stage == Build::STAGE_TEST) {
|
if ($stage == Build::STAGE_TEST) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the plugin
|
* Runs the plugin
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
$success = true;
|
$success = true;
|
||||||
$errorCount = $this->getErrorList();
|
$errorCount = $this->getErrorList();
|
||||||
|
|
||||||
$this->builder->log($this->returnResult()."Found $errorCount instances of " . implode(', ', $this->searches));
|
$this->builder->log($this->returnResult()."Found $errorCount instances of " . implode(', ', $this->searches));
|
||||||
|
|
||||||
$this->build->storeMeta('technical_debt-warnings', $errorCount);
|
$this->build->storeMeta('technical_debt-warnings', $errorCount);
|
||||||
|
|
||||||
if ($this->allowed_errors !== -1 && $errorCount > $this->allowed_errors) {
|
if ($this->allowed_errors !== -1 && $errorCount > $this->allowed_errors) {
|
||||||
$success = false;
|
$success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number and list of errors returned from the search
|
* Gets the number and list of errors returned from the search
|
||||||
*
|
*
|
||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
protected function getErrorList()
|
protected function getErrorList()
|
||||||
{
|
{
|
||||||
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory));
|
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory));
|
||||||
|
|
||||||
$this->builder->logDebug("Ignored path: ".json_encode($this->ignore,true));
|
$this->builder->logDebug("Ignored path: ".json_encode($this->ignore, true));
|
||||||
$errorCount = 0;
|
$errorCount = 0;
|
||||||
|
|
||||||
/** @var \SplFileInfo $file */
|
/** @var \SplFileInfo $file */
|
||||||
foreach ($iterator as $file) {
|
foreach ($iterator as $file) {
|
||||||
$filePath = $file->getRealPath();
|
$filePath = $file->getRealPath();
|
||||||
$relativePath = (string)$file->getPathname();
|
$extension = $file->getExtension();
|
||||||
$extension = $file->getExtension();
|
|
||||||
|
|
||||||
$ignored = false;
|
$ignored = false;
|
||||||
foreach ($this->suffixes as $suffix) {
|
foreach ($this->suffixes as $suffix) {
|
||||||
if ($suffix !== $extension) {
|
if ($suffix !== $extension) {
|
||||||
$ignored = true;
|
$ignored = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->ignore as $ignore) {
|
|
||||||
if ('/' === $ignore{0}) {
|
|
||||||
if (0 === strpos($filePath, $ignore)) {
|
|
||||||
$ignored = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$ignore = $this->directory.$ignore;
|
|
||||||
if (0 === strpos($filePath, $ignore)) {
|
|
||||||
$ignored = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$ignored){
|
|
||||||
$handle = fopen($filePath, "r");
|
|
||||||
$lineNumber = 1;
|
|
||||||
$found=false;
|
|
||||||
while (false === feof($handle)) {
|
|
||||||
$line = fgets($handle);
|
|
||||||
foreach ($this->searches as $search) {
|
|
||||||
if ($technicalDeptLine = trim(strstr($line, $search))) {
|
|
||||||
$fileName = str_replace($this->directory, '', $filePath);
|
|
||||||
$this->build->reportError(
|
|
||||||
$this->builder,
|
|
||||||
'technical_debt',
|
|
||||||
$technicalDeptLine,
|
|
||||||
PHPCensor\Model\BuildError::SEVERITY_LOW,
|
|
||||||
$fileName,
|
|
||||||
$lineNumber
|
|
||||||
);
|
|
||||||
$found=true;
|
|
||||||
$errorCount++;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$lineNumber++;
|
|
||||||
}
|
|
||||||
fclose ($handle);
|
|
||||||
if ($found === true){
|
|
||||||
$this->buildLogString('X');
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$this->buildLogString('.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $errorCount;
|
foreach ($this->ignore as $ignore) {
|
||||||
}
|
if ('/' === $ignore{0}) {
|
||||||
|
if (0 === strpos($filePath, $ignore)) {
|
||||||
|
$ignored = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$ignore = $this->directory.$ignore;
|
||||||
|
if (0 === strpos($filePath, $ignore)) {
|
||||||
|
$ignored = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$ignored) {
|
||||||
|
$handle = fopen($filePath, "r");
|
||||||
|
$lineNumber = 1;
|
||||||
|
$found=false;
|
||||||
|
while (false === feof($handle)) {
|
||||||
|
$line = fgets($handle);
|
||||||
|
foreach ($this->searches as $search) {
|
||||||
|
if ($technicalDeptLine = trim(strstr($line, $search))) {
|
||||||
|
$fileName = str_replace($this->directory, '', $filePath);
|
||||||
|
$this->build->reportError(
|
||||||
|
$this->builder,
|
||||||
|
'technical_debt',
|
||||||
|
$technicalDeptLine,
|
||||||
|
PHPCensor\Model\BuildError::SEVERITY_LOW,
|
||||||
|
$fileName,
|
||||||
|
$lineNumber
|
||||||
|
);
|
||||||
|
$found=true;
|
||||||
|
$errorCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$lineNumber++;
|
||||||
|
}
|
||||||
|
fclose($handle);
|
||||||
|
if ($found === true) {
|
||||||
|
$this->buildLogString('X');
|
||||||
|
} else {
|
||||||
|
$this->buildLogString('.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errorCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue