Skip to content

CS/QA: always import all used classes #103

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

Merged
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
3 changes: 2 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHP_Parallel_Lint\PhpParallelLint;

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

Expand Down Expand Up @@ -65,7 +66,7 @@ public function run()
}
return self::FAILED;

} catch (\Exception $e) {
} catch (Exception $e) {
echo $e->getMessage(), PHP_EOL;
return self::FAILED;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Blame.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHP_Parallel_Lint\PhpParallelLint;

use JsonSerializable;
use ReturnTypeWillChange;

class Blame implements \JsonSerializable
class Blame implements JsonSerializable
{
public $name;

Expand Down
3 changes: 2 additions & 1 deletion src/Errors/ParallelLintError.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace PHP_Parallel_Lint\PhpParallelLint\Errors;

use JsonSerializable;
use ReturnTypeWillChange;

class ParallelLintError implements \JsonSerializable
class ParallelLintError implements JsonSerializable
{
/** @var string */
protected $filePath;
Expand Down
4 changes: 3 additions & 1 deletion src/Exceptions/ParallelLintException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace PHP_Parallel_Lint\PhpParallelLint\Exceptions;

use Exception;
use JsonSerializable;
use ReturnTypeWillChange;

class ParallelLintException extends \Exception implements \JsonSerializable
class ParallelLintException extends Exception implements JsonSerializable
{
#[ReturnTypeWillChange]
public function jsonSerialize()
Expand Down
4 changes: 3 additions & 1 deletion src/Iterators/ArrayIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PHP_Parallel_Lint\PhpParallelLint\Iterators;

class ArrayIterator extends \ArrayIterator
use ArrayIterator as PHPArrayIterator;

class ArrayIterator extends PHPArrayIterator
{
public function getNext()
{
Expand Down
15 changes: 9 additions & 6 deletions src/Iterators/RecursiveDirectoryFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

namespace PHP_Parallel_Lint\PhpParallelLint\Iterators;

use RecursiveDirectoryIterator;
use RecursiveFilterIterator;
use ReturnTypeWillChange;
use SplFileInfo;

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

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

/**
* @param \RecursiveDirectoryIterator $iterator
* @param RecursiveDirectoryIterator $iterator
* @param array $excluded
*/
public function __construct(\RecursiveDirectoryIterator $iterator, array $excluded)
public function __construct(RecursiveDirectoryIterator $iterator, array $excluded)
{
parent::__construct($iterator);
$this->iterator = $iterator;
Expand Down Expand Up @@ -61,7 +64,7 @@ public function hasChildren()
* 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.
* @return RecursiveFilterIterator containing the inner iterator's children.
*/
#[ReturnTypeWillChange]
public function getChildren()
Expand All @@ -81,7 +84,7 @@ private function getPathname($file)
$file = '.' . DIRECTORY_SEPARATOR . $file;
}

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

Expand Down
18 changes: 11 additions & 7 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace PHP_Parallel_Lint\PhpParallelLint;

use FilesystemIterator;
use PHP_Parallel_Lint\PhpParallelLint\Contracts\SyntaxErrorCallback;
use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError;
use PHP_Parallel_Lint\PhpParallelLint\Exceptions\ClassNotFoundException;
use PHP_Parallel_Lint\PhpParallelLint\Exceptions\PathNotFoundException;
use PHP_Parallel_Lint\PhpParallelLint\Exceptions\CallbackNotImplementedException;
use PHP_Parallel_Lint\PhpParallelLint\Exceptions\ClassNotFoundException;
use PHP_Parallel_Lint\PhpParallelLint\Exceptions\ParallelLintException;
use PHP_Parallel_Lint\PhpParallelLint\Exceptions\PathNotFoundException;
use PHP_Parallel_Lint\PhpParallelLint\Iterators\RecursiveDirectoryFilterIterator;
use PHP_Parallel_Lint\PhpParallelLint\Outputs\CheckstyleOutput;
use PHP_Parallel_Lint\PhpParallelLint\Outputs\GitLabOutput;
Expand All @@ -18,6 +19,9 @@
use PHP_Parallel_Lint\PhpParallelLint\Process\GitBlameProcess;
use PHP_Parallel_Lint\PhpParallelLint\Process\PhpExecutable;
use PHP_Parallel_Lint\PhpParallelLint\Writers\ConsoleWriter;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RegexIterator;

class Manager
{
Expand Down Expand Up @@ -159,17 +163,17 @@ protected function getFilesFromPaths(array $paths, array $extensions, array $exc
if (is_file($path)) {
$files[] = $path;
} elseif (is_dir($path)) {
$iterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS);
$iterator = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
if (!empty($excluded)) {
$iterator = new RecursiveDirectoryFilterIterator($iterator, $excluded);
}
$iterator = new \RecursiveIteratorIterator(
$iterator = new RecursiveIteratorIterator(
$iterator,
\RecursiveIteratorIterator::LEAVES_ONLY,
\RecursiveIteratorIterator::CATCH_GET_CHILD
RecursiveIteratorIterator::LEAVES_ONLY,
RecursiveIteratorIterator::CATCH_GET_CHILD
);

$iterator = new \RegexIterator($iterator, $regex);
$iterator = new RegexIterator($iterator, $regex);

/** @var \SplFileInfo[] $iterator */
foreach ($iterator as $directoryFile) {
Expand Down
1 change: 0 additions & 1 deletion src/Outputs/GitLabOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace PHP_Parallel_Lint\PhpParallelLint\Outputs;

use PHP_Parallel_Lint\PhpParallelLint\Outputs\OutputInterface;
use PHP_Parallel_Lint\PhpParallelLint\ErrorFormatter;
use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError;
use PHP_Parallel_Lint\PhpParallelLint\Result;
Expand Down
12 changes: 7 additions & 5 deletions src/Outputs/TextOutputColored.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

namespace PHP_Parallel_Lint\PhpParallelLint\Outputs;

use JakubOnderka\PhpConsoleColor\ConsoleColor as OldConsoleColor;
use PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor;
use PHP_Parallel_Lint\PhpParallelLint\Settings;
use PHP_Parallel_Lint\PhpParallelLint\Writers\WriterInterface;

class TextOutputColored extends TextOutput
{
/** @var \PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor|\JakubOnderka\PhpConsoleColor\ConsoleColor */
/** @var ConsoleColor|OldConsoleColor */
private $colors;

public function __construct(WriterInterface $writer, $colors = Settings::AUTODETECT)
{
parent::__construct($writer);

if (class_exists('\PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor')) {
$this->colors = new \PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor();
$this->colors = new ConsoleColor();
$this->colors->setForceStyle($colors === Settings::FORCED);
} elseif (class_exists('\JakubOnderka\PhpConsoleColor\ConsoleColor')) {
$this->colors = new \JakubOnderka\PhpConsoleColor\ConsoleColor();
$this->colors = new OldConsoleColor();
$this->colors->setForceStyle($colors === Settings::FORCED);
}
}
Expand All @@ -31,8 +33,8 @@ public function __construct(WriterInterface $writer, $colors = Settings::AUTODET
public function write($string, $type = self::TYPE_DEFAULT)
{
if (
!$this->colors instanceof \PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor
&& !$this->colors instanceof \JakubOnderka\PhpConsoleColor\ConsoleColor
!$this->colors instanceof ConsoleColor
&& !$this->colors instanceof OldConsoleColor
) {
parent::write($string, $type);
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/ParallelLint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHP_Parallel_Lint\PhpParallelLint;

use Exception;
use PHP_Parallel_Lint\PhpParallelLint\Contracts\SyntaxErrorCallback;
use PHP_Parallel_Lint\PhpParallelLint\Errors\ParallelLintError;
use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError;
Expand Down Expand Up @@ -46,7 +47,7 @@ public function __construct(PhpExecutable $phpExecutable, $parallelJobs = 10)
/**
* @param array $files
* @return Result
* @throws \Exception
* @throws Exception
*/
public function lint(array $files)
{
Expand Down Expand Up @@ -120,13 +121,13 @@ public function lint(array $files)

if ($skipLintProcess->isFail()) {
$message = "Error in skip-linting.php process\nError output: {$skipLintProcess->getErrorOutput()}";
throw new \Exception($message);
throw new Exception($message);
}

foreach ($waiting as $file => $process) {
$skipStatus = $skipLintProcess->isSkipped($file);
if ($skipStatus === null) {
throw new \Exception("File $file has empty skip status. Please contact the author of PHP Parallel Lint.");
throw new Exception("File $file has empty skip status. Please contact the author of PHP Parallel Lint.");

} elseif ($skipStatus === true) {
$skippedFiles[] = $file;
Expand Down
15 changes: 9 additions & 6 deletions src/Process/GitBlameProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace PHP_Parallel_Lint\PhpParallelLint\Process;

use DateInterval;
use DateTime;
use DateTimeZone;
use PHP_Parallel_Lint\PhpParallelLint\Exceptions\RuntimeException;

class GitBlameProcess extends Process
Expand Down Expand Up @@ -58,7 +61,7 @@ public function getAuthorEmail()
}

/**
* @return \DateTime
* @return DateTime
* @throws RuntimeException
*/
public function getAuthorTime()
Expand Down Expand Up @@ -123,26 +126,26 @@ public static function gitExists($gitExecutable)
*
* @param int $time
* @param string $zone
* @return \DateTime
* @return DateTime
* @throws \Exception
*/
protected function getDateTime($time, $zone)
{
$utcTimeZone = new \DateTimeZone('UTC');
$datetime = \DateTime::createFromFormat('U', $time, $utcTimeZone);
$utcTimeZone = new DateTimeZone('UTC');
$datetime = DateTime::createFromFormat('U', $time, $utcTimeZone);

$way = substr($zone, 0, 1);
$hours = (int) substr($zone, 1, 2);
$minutes = (int) substr($zone, 3, 2);

$interval = new \DateInterval("PT{$hours}H{$minutes}M");
$interval = new DateInterval("PT{$hours}H{$minutes}M");

if ($way === '+') {
$datetime->add($interval);
} else {
$datetime->sub($interval);
}

return new \DateTime($datetime->format('Y-m-d\TH:i:s') . $zone, $utcTimeZone);
return new DateTime($datetime->format('Y-m-d\TH:i:s') . $zone, $utcTimeZone);
}
}
3 changes: 2 additions & 1 deletion src/Process/LintProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHP_Parallel_Lint\PhpParallelLint\Process;

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

Expand All @@ -27,7 +28,7 @@ class LintProcess extends PhpProcess
public function __construct(PhpExecutable $phpExecutable, $fileToCheck, $aspTags = false, $shortTag = false, $deprecated = false)
{
if (empty($fileToCheck)) {
throw new \InvalidArgumentException("File to check must be set.");
throw new InvalidArgumentException("File to check must be set.");
}

$parameters = array(
Expand Down
3 changes: 2 additions & 1 deletion src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace PHP_Parallel_Lint\PhpParallelLint;

use JsonSerializable;
use PHP_Parallel_Lint\PhpParallelLint\Errors\ParallelLintError;
use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError;
use ReturnTypeWillChange;

class Result implements \JsonSerializable
class Result implements JsonSerializable
{
/** @var ParallelLintError[] */
private $errors;
Expand Down
5 changes: 3 additions & 2 deletions tests/Manager.run.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use PHP_Parallel_Lint\PhpParallelLint\Outputs\TextOutput;
use PHP_Parallel_Lint\PhpParallelLint\Settings;
use PHP_Parallel_Lint\PhpParallelLint\Writers\NullWriter;
use Tester\Assert;
use Tester\TestCase;

class ManagerRunTest extends Tester\TestCase
class ManagerRunTest extends TestCase
{
public function testBadPath()
{
Expand Down Expand Up @@ -118,7 +119,7 @@ class ManagerRunTest extends Tester\TestCase
}

/**
* @return PHP_Parallel_Lint\PhpParallelLint\Settings
* @return Settings
*/
private function prepareSettings()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Output.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use PHP_Parallel_Lint\PhpParallelLint\Outputs\GitLabOutput;
use PHP_Parallel_Lint\PhpParallelLint\Result;
use PHP_Parallel_Lint\PhpParallelLint\Writers\WriterInterface;
use Tester\Assert;
use Tester\TestCase;

class OutputTest extends Tester\TestCase
class OutputTest extends TestCase
{
/**
* @dataProvider getGitLabOutputData
Expand Down
9 changes: 6 additions & 3 deletions tests/ParallelLint.lint.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ require_once __DIR__ . '/../src/polyfill.php';
require __DIR__ . '/../vendor/autoload.php';

use PHP_Parallel_Lint\PhpParallelLint\ParallelLint;
use PHP_Parallel_Lint\PhpParallelLint\Process\PhpExecutable;
use Tester\Assert;
use Tester\Environment;
use Tester\TestCase;

class ParallelLintLintTest extends Tester\TestCase
class ParallelLintLintTest extends TestCase
{
public function testSettersAndGetters()
{
Expand Down Expand Up @@ -103,7 +106,7 @@ class ParallelLintLintTest extends Tester\TestCase
Assert::equal(0, count($result->getErrors()));

if (PHP_VERSION_ID < 70000 || PHP_VERSION_ID >= 80000) {
Tester\Environment::skip('test for php version 7.0-7.4');
Environment::skip('test for php version 7.0-7.4');
}

$parallelLint = new ParallelLint($this->getPhpExecutable());
Expand Down Expand Up @@ -131,7 +134,7 @@ class ParallelLintLintTest extends Tester\TestCase

private function getPhpExecutable()
{
return \PHP_Parallel_Lint\PhpParallelLint\Process\PhpExecutable::getPhpExecutable('php');
return PhpExecutable::getPhpExecutable('php');
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Settings.parseArguments.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ require __DIR__ . '/../vendor/autoload.php';

use PHP_Parallel_Lint\PhpParallelLint\Settings;
use Tester\Assert;
use Tester\TestCase;

class SettingsParseArgumentsTest extends Tester\TestCase
class SettingsParseArgumentsTest extends TestCase
{
public function testNoneArguments()
{
Expand Down
Loading