Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

PSR-4 #122

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
34 changes: 34 additions & 0 deletions src/Error/Blame.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
namespace JakubOnderka\PhpParallelLint\Error;

class Blame implements \JsonSerializable
{
public $name;

public $email;

/** @var \DateTime */
public $datetime;

public $commitHash;

public $summary;

/**
* (PHP 5 &gt;= 5.4.0)<br/>
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
*/
function jsonSerialize()
{
return array(
'name' => $this->name,
'email' => $this->email,
'datetime' => $this->datetime,
'commitHash' => $this->commitHash,
'summary' => $this->summary,
);
}
}
68 changes: 68 additions & 0 deletions src/Error/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
namespace JakubOnderka\PhpParallelLint\Error;

class Error implements \JsonSerializable
{
/** @var string */
protected $filePath;

/** @var string */
protected $message;

/**
* @param string $filePath
* @param string $message
*/
public function __construct($filePath, $message)
{
$this->filePath = $filePath;
$this->message = rtrim($message);
}

/**
* @return string
*/
public function getMessage()
{
return $this->message;
}

/**
* @return string
*/
public function getFilePath()
{
return $this->filePath;
}

/**
* @return string
*/
public function getShortFilePath()
{
$cwd = getcwd();

if ($cwd === '/') {
// For root directory in unix, do not modify path
return $this->filePath;
}

return preg_replace('/' . preg_quote($cwd, '/') . '/', '', $this->filePath, 1);
}

/**
* (PHP 5 &gt;= 5.4.0)<br/>
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
*/
public function jsonSerialize()
{
return array(
'type' => 'error',
'file' => $this->getFilePath(),
'message' => $this->getMessage(),
);
}
}
104 changes: 2 additions & 102 deletions src/Error.php → src/Error/SyntaxError.php
Original file line number Diff line number Diff line change
@@ -1,105 +1,5 @@
<?php
namespace JakubOnderka\PhpParallelLint;

class Error implements \JsonSerializable
{
/** @var string */
protected $filePath;

/** @var string */
protected $message;

/**
* @param string $filePath
* @param string $message
*/
public function __construct($filePath, $message)
{
$this->filePath = $filePath;
$this->message = rtrim($message);
}

/**
* @return string
*/
public function getMessage()
{
return $this->message;
}

/**
* @return string
*/
public function getFilePath()
{
return $this->filePath;
}

/**
* @return string
*/
public function getShortFilePath()
{
$cwd = getcwd();

if ($cwd === '/') {
// For root directory in unix, do not modify path
return $this->filePath;
}

return preg_replace('/' . preg_quote($cwd, '/') . '/', '', $this->filePath, 1);
}

/**
* (PHP 5 &gt;= 5.4.0)<br/>
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
*/
public function jsonSerialize()
{
return array(
'type' => 'error',
'file' => $this->getFilePath(),
'message' => $this->getMessage(),
);
}
}

class Blame implements \JsonSerializable
{
public $name;

public $email;

/** @var \DateTime */
public $datetime;

public $commitHash;

public $summary;

/**
* (PHP 5 &gt;= 5.4.0)<br/>
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
*/
function jsonSerialize()
{
return array(
'name' => $this->name,
'email' => $this->email,
'datetime' => $this->datetime,
'commitHash' => $this->commitHash,
'summary' => $this->summary,
);
}


}
namespace JakubOnderka\PhpParallelLint\Error;

class SyntaxError extends Error
{
Expand Down Expand Up @@ -219,4 +119,4 @@ public function jsonSerialize()
'blame' => $this->blame,
);
}
}
}
2 changes: 2 additions & 0 deletions src/ErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use JakubOnderka\PhpConsoleColor\ConsoleColor;
use JakubOnderka\PhpConsoleHighlighter\Highlighter;
use JakubOnderka\PhpParallelLint\Error\Error;
use JakubOnderka\PhpParallelLint\Error\SyntaxError;

class ErrorFormatter
{
Expand Down
109 changes: 12 additions & 97 deletions src/Manager.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php
namespace JakubOnderka\PhpParallelLint;

use JakubOnderka\PhpParallelLint\Error\Blame;
use JakubOnderka\PhpParallelLint\Error\SyntaxError;
use JakubOnderka\PhpParallelLint\Output;
use JakubOnderka\PhpParallelLint\Process\GitBlameProcess;
use JakubOnderka\PhpParallelLint\Process\PhpExecutable;

class Manager
{
/** @var Output */
/** @var Output\Output */
protected $output;

/**
Expand Down Expand Up @@ -62,31 +65,31 @@ public function run(Settings $settings = null)
}

/**
* @param Output $output
* @param Output\Output $output
*/
public function setOutput(Output $output)
public function setOutput(Output\Output $output)
{
$this->output = $output;
}

/**
* @param Settings $settings
* @return Output
* @return Output\Output
*/
protected function getDefaultOutput(Settings $settings)
{
$writer = new ConsoleWriter;
$writer = new Output\ConsoleWriter;
switch ($settings->format) {
case Settings::FORMAT_JSON:
return new JsonOutput($writer);
return new Output\JsonOutput($writer);
case Settings::FORMAT_CHECKSTYLE:
return new CheckstyleOutput($writer);
return new Output\CheckstyleOutput($writer);
}

if ($settings->colors === Settings::DISABLED) {
$output = new TextOutput($writer);
$output = new Output\TextOutput($writer);
} else {
$output = new TextOutputColored($writer, $settings->colors);
$output = new Output\TextOutputColored($writer, $settings->colors);
}

$output->showProgress = $settings->showProgress;
Expand Down Expand Up @@ -166,91 +169,3 @@ protected function getFilesFromPaths(array $paths, array $extensions, array $exc
return $files;
}
}

class RecursiveDirectoryFilterIterator extends \RecursiveFilterIterator
{
/** @var \RecursiveDirectoryIterator */
private $iterator;

/** @var array */
private $excluded = array();

/**
* @param \RecursiveDirectoryIterator $iterator
* @param array $excluded
*/
public function __construct(\RecursiveDirectoryIterator $iterator, array $excluded)
{
parent::__construct($iterator);
$this->iterator = $iterator;
$this->excluded = array_map(array($this, 'getPathname'), $excluded);
}

/**
* (PHP 5 &gt;= 5.1.0)<br/>
* Check whether the current element of the iterator is acceptable
*
* @link http://php.net/manual/en/filteriterator.accept.php
* @return bool true if the current element is acceptable, otherwise false.
*/
public function accept()
{
$current = $this->current()->getPathname();
$current = $this->normalizeDirectorySeparator($current);

if ('.' . DIRECTORY_SEPARATOR !== $current[0] . $current[1]) {
$current = '.' . DIRECTORY_SEPARATOR . $current;
}

return !in_array($current, $this->excluded);
}

/**
* (PHP 5 &gt;= 5.1.0)<br/>
* Check whether the inner iterator's current element has children
*
* @link http://php.net/manual/en/recursivefilteriterator.haschildren.php
* @return bool true if the inner iterator has children, otherwise false
*/
public function hasChildren()
{
return $this->iterator->hasChildren();
}

/**
* (PHP 5 &gt;= 5.1.0)<br/>
* Return the inner iterator's children contained in a RecursiveFilterIterator
*
* @link http://php.net/manual/en/recursivefilteriterator.getchildren.php
* @return \RecursiveFilterIterator containing the inner iterator's children.
*/
public function getChildren()
{
return new self($this->iterator->getChildren(), $this->excluded);
}

/**
* @param string $file
* @return string
*/
private function getPathname($file)
{
$file = $this->normalizeDirectorySeparator($file);

if ('.' . DIRECTORY_SEPARATOR !== $file[0] . $file[1]) {
$file = '.' . DIRECTORY_SEPARATOR . $file;
}

$directoryFile = new \SplFileInfo($file);
return $directoryFile->getPathname();
}

/**
* @param string $file
* @return string
*/
private function normalizeDirectorySeparator($file)
{
return str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $file);
}
}
Loading