Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split files for PSR-4 compliance #45

Merged
merged 5 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"sort-packages": true
},
"autoload": {
"classmap": [
"./src/"
]
"psr-4": {
"PHP_Parallel_Lint\\PhpParallelLint\\": "src/"
}
},
"autoload-dev": {
"classmap": [
Expand Down
6 changes: 3 additions & 3 deletions doc/syntax-error-callback.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Syntax Error Callback

1. Set a path to a file with custom error callback to `--syntax-error-callback` option.
1. Create a class implementing `JakubOnderka\PhpParallelLint\Contracts\SyntaxErrorCallback` interface. File with the class must have the same name as the class inside.
1. Create a class implementing `PHP_Parallel_Lint\PhpParallelLint\Contracts\SyntaxErrorCallback` interface. File with the class must have the same name as the class inside.
1. Modify error before it is printed to the output.

## Example configuration
Expand All @@ -11,8 +11,8 @@ The content should look like:

```php

use JakubOnderka\PhpParallelLint\Contracts\SyntaxErrorCallback;
use JakubOnderka\PhpParallelLint\SyntaxError;
use PHP_Parallel_Lint\PhpParallelLint\Contracts\SyntaxErrorCallback;
use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError;

class MyCustomErrorHandler implements SyntaxErrorCallback {
/**
Expand Down
2 changes: 1 addition & 1 deletion parallel-lint
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ if (!$loaded) {

require_once __DIR__ . '/src/polyfill.php';

$app = new JakubOnderka\PhpParallelLint\Application();
$app = new PHP_Parallel_Lint\PhpParallelLint\Application();
exit($app->run());
7 changes: 5 additions & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

namespace JakubOnderka\PhpParallelLint;
namespace PHP_Parallel_Lint\PhpParallelLint;

use PHP_Parallel_Lint\PhpParallelLint\Exceptions\InvalidArgumentException;
use PHP_Parallel_Lint\PhpParallelLint\Exceptions\ParallelLintException;

class Application
{
Expand Down Expand Up @@ -54,7 +57,7 @@ public function run()
$this->showOptions();
return self::FAILED;

} catch (Exception $e) {
} catch (ParallelLintException $e) {
if (isset($settings) && $settings->format === Settings::FORMAT_JSON) {
echo json_encode($e);
} else {
Expand Down
37 changes: 37 additions & 0 deletions src/Blame.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace PHP_Parallel_Lint\PhpParallelLint;

use ReturnTypeWillChange;

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.
*/
#[ReturnTypeWillChange]
function jsonSerialize()
{
return array(
'name' => $this->name,
'email' => $this->email,
'datetime' => $this->datetime,
'commitHash' => $this->commitHash,
'summary' => $this->summary,
);
}
}
4 changes: 2 additions & 2 deletions src/Contracts/SyntaxErrorCallback.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace JakubOnderka\PhpParallelLint\Contracts;
namespace PHP_Parallel_Lint\PhpParallelLint\Contracts;

use JakubOnderka\PhpParallelLint\SyntaxError;
use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError;

interface SyntaxErrorCallback
{
Expand Down
8 changes: 5 additions & 3 deletions src/ErrorFormatter.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
namespace JakubOnderka\PhpParallelLint;
namespace PHP_Parallel_Lint\PhpParallelLint;

use JakubOnderka\PhpConsoleColor\ConsoleColor as OldConsoleColor;
use JakubOnderka\PhpConsoleHighlighter\Highlighter as OldHighlighter;
use PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor;
use PHP_Parallel_Lint\PhpConsoleHighlighter\Highlighter;
use PHP_Parallel_Lint\PhpParallelLint\Errors\ParallelLintError;
use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError;

class ErrorFormatter
{
Expand All @@ -25,10 +27,10 @@ public function __construct($useColors = Settings::AUTODETECT, $translateTokens
}

/**
* @param Error $error
* @param ParallelLintError $error
* @return string
*/
public function format(Error $error)
public function format(ParallelLintError $error)
{
if ($error instanceof SyntaxError) {
return $this->formatSyntaxErrorMessage($error);
Expand Down
71 changes: 71 additions & 0 deletions src/Errors/ParallelLintError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
namespace PHP_Parallel_Lint\PhpParallelLint\Errors;

use ReturnTypeWillChange;

class ParallelLintError 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.
*/
#[ReturnTypeWillChange]
public function jsonSerialize()
{
return array(
'type' => 'error',
'file' => $this->getFilePath(),
'message' => $this->getMessage(),
);
}
}
108 changes: 3 additions & 105 deletions src/Error.php → src/Errors/SyntaxError.php
Original file line number Diff line number Diff line change
@@ -1,111 +1,9 @@
<?php
namespace JakubOnderka\PhpParallelLint;
namespace PHP_Parallel_Lint\PhpParallelLint\Errors;

use ReturnTypeWillChange;
use PHP_Parallel_Lint\PhpParallelLint\Blame;

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.
*/
#[ReturnTypeWillChange]
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.
*/
#[ReturnTypeWillChange]
function jsonSerialize()
{
return array(
'name' => $this->name,
'email' => $this->email,
'datetime' => $this->datetime,
'commitHash' => $this->commitHash,
'summary' => $this->summary,
);
}


}

class SyntaxError extends Error
class SyntaxError extends ParallelLintError
{
/** @var Blame */
private $blame;
Expand Down
18 changes: 18 additions & 0 deletions src/Exceptions/CallbackNotImplementedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace PHP_Parallel_Lint\PhpParallelLint\Exceptions;

class CallbackNotImplementedException extends ParallelLintException
{
protected $className;

public function __construct($className)
{
$this->className = $className;
$this->message = "Class '$className' does not implement SyntaxErrorCallback interface.";
}

public function getClassName()
{
return $this->className;
}
}
25 changes: 25 additions & 0 deletions src/Exceptions/ClassNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace PHP_Parallel_Lint\PhpParallelLint\Exceptions;

class ClassNotFoundException extends ParallelLintException
{
protected $className;
protected $fileName;

public function __construct($className, $fileName)
{
$this->className = $className;
$this->fileName = $fileName;
$this->message = "Class with name '$className' does not exists in file '$fileName'";
}

public function getClassName()
{
return $this->className;
}

public function getFileName()
{
return $this->fileName;
}
}
18 changes: 18 additions & 0 deletions src/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace PHP_Parallel_Lint\PhpParallelLint\Exceptions;

class InvalidArgumentException extends ParallelLintException
{
protected $argument;

public function __construct($argument)
{
$this->argument = $argument;
$this->message = "Invalid argument $argument";
}

public function getArgument()
{
return $this->argument;
}
}
Loading