Skip to content

Commit

Permalink
Merge pull request #1 from mzk/deprecated-warnings
Browse files Browse the repository at this point in the history
report deprecated warnings
  • Loading branch information
mzk authored Apr 21, 2017
2 parents ac6f757 + 1b1857c commit 7f8b8e1
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 12 deletions.
2 changes: 1 addition & 1 deletion phpcs-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="125"/>
<property name="lineLimit" value="135"/>
<property name="absoluteLineLimit" value="200"/>
</properties>
</rule>
Expand Down
1 change: 1 addition & 0 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function run(Settings $settings = null)
$parallelLint = new ParallelLint($phpExecutable, $settings->parallelJobs);
$parallelLint->setAspTagsEnabled($settings->aspTags);
$parallelLint->setShortTagEnabled($settings->shortTag);
$parallelLint->setShowDeprecated($settings->showDeprecated);

$parallelLint->setProcessCallback(function ($status, $file) use ($output) {
if ($status === ParallelLint::STATUS_OK) {
Expand Down
36 changes: 30 additions & 6 deletions src/ParallelLint.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class ParallelLint
/** @var callable */
private $processCallback;

/** @var bool */
private $showDeprecated = false;

public function __construct(PhpExecutable $phpExecutable, $parallelJobs = 10)
{
$this->phpExecutable = $phpExecutable;
Expand Down Expand Up @@ -95,7 +98,8 @@ public function lint(array $files)
$this->phpExecutable,
$file,
$this->aspTagsEnabled,
$this->shortTagEnabled
$this->shortTagEnabled,
$this->showDeprecated
);
}
}
Expand All @@ -115,14 +119,15 @@ public function lint(array $files)
$skippedFiles[] = $file;
$processCallback(self::STATUS_SKIP, $file);

} else if ($process->containsError()) {
$checkedFiles[] = $file;
$errors[] = new SyntaxError($file, $process->getSyntaxError());
$processCallback(self::STATUS_ERROR, $file);

} else if ($process->isSuccess()) {
$checkedFiles[] = $file;
$processCallback(self::STATUS_OK, $file);

} else if ($process->hasSyntaxError()) {
$checkedFiles[] = $file;
$errors[] = new SyntaxError($file, $process->getSyntaxError());
$processCallback(self::STATUS_ERROR, $file);

} else {
$errors[] = new Error($file, $process->getOutput());
Expand Down Expand Up @@ -153,7 +158,7 @@ public function lint(array $files)
$checkedFiles[] = $file;
$processCallback(self::STATUS_OK, $file);

} else if ($process->hasSyntaxError()) {
} else if ($process->containsError()) {
$checkedFiles[] = $file;
$errors[] = new SyntaxError($file, $process->getSyntaxError());
$processCallback(self::STATUS_ERROR, $file);
Expand Down Expand Up @@ -264,4 +269,23 @@ public function setShortTagEnabled($shortTagEnabled)

return $this;
}

/**
* @return boolean
*/
public function isShowDeprecated()
{
return $this->showDeprecated;
}

/**
* @param $showDeprecated
* @return ParallelLint
*/
public function setShowDeprecated($showDeprecated)
{
$this->showDeprecated = $showDeprecated;

return $this;
}
}
28 changes: 23 additions & 5 deletions src/Process/LintProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ class LintProcess extends PhpProcess
{
const FATAL_ERROR = 'Fatal error';
const PARSE_ERROR = 'Parse error';
const DEPRECATED_ERROR = 'Deprecated:';

/**
* @var bool
*/
private $showDeprecatedErrors;

/**
* @param PhpExecutable $phpExecutable
* @param string $fileToCheck Path to file to check
* @param bool $aspTags
* @param bool $shortTag
* @param bool $deprecated
*/
public function __construct(PhpExecutable $phpExecutable, $fileToCheck, $aspTags = false, $shortTag = false)
public function __construct(PhpExecutable $phpExecutable, $fileToCheck, $aspTags = false, $shortTag = false, $deprecated = false)
{
if (empty($fileToCheck)) {
throw new \InvalidArgumentException("File to check must be set.");
Expand All @@ -29,13 +36,14 @@ public function __construct(PhpExecutable $phpExecutable, $fileToCheck, $aspTags
escapeshellarg($fileToCheck),
);

$this->showDeprecatedErrors = $deprecated;
parent::__construct($phpExecutable, $parameters);
}

/**
* @return bool
*/
public function hasSyntaxError()
public function containsError()
{
return $this->containsParserOrFatalError($this->getOutput());
}
Expand All @@ -46,7 +54,7 @@ public function hasSyntaxError()
*/
public function getSyntaxError()
{
if ($this->hasSyntaxError()) {
if ($this->containsError()) {
foreach (explode("\n", $this->getOutput()) as $line) {
if ($this->containsParserOrFatalError($line)) {
return $line;
Expand Down Expand Up @@ -82,6 +90,16 @@ public function isSuccess()
private function containsParserOrFatalError($string)
{
return strpos($string, self::FATAL_ERROR) !== false ||
strpos($string, self::PARSE_ERROR) !== false;
strpos($string, self::PARSE_ERROR) !== false ||
$this->containsDeprecatedError($string);
}

private function containsDeprecatedError($string)
{
if ($this->showDeprecatedErrors === false) {
return false;
}

return strpos($string, self::DEPRECATED_ERROR) !== false;
}
}
}
9 changes: 9 additions & 0 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ class Settings
*/
public $ignoreFails = false;

/**
* @var bool
*/
public $showDeprecated = false;

/**
* @param array $paths
*/
Expand Down Expand Up @@ -194,6 +199,10 @@ public static function parseArguments(array $arguments)
$settings->ignoreFails = true;
break;

case '--show-deprecated':
$settings->showDeprecated = true;
break;

default:
throw new InvalidArgumentException($argument);
}
Expand Down
22 changes: 22 additions & 0 deletions tests/ParallelLint.lint.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ class ParallelLintLintTest extends Tester\TestCase
Assert::equal(1, count($result->getErrors()));
}

public function testDeprecated()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(__DIR__ . '/examples/example-05/Foo.php'));
Assert::equal(1, $result->getCheckedFilesCount());
Assert::equal(0, $result->getFilesWithSyntaxErrorCount());
Assert::false($result->hasSyntaxError());
Assert::equal(0, count($result->getErrors()));

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

$parallelLint = new ParallelLint($this->getPhpExecutable());
$parallelLint->setShowDeprecated(true);
$result = $parallelLint->lint(array(__DIR__ . '/examples/example-05/Foo.php'));
Assert::equal(1, $result->getCheckedFilesCount());
Assert::equal(1, $result->getFilesWithSyntaxErrorCount());
Assert::true($result->hasSyntaxError());
Assert::equal(1, count($result->getErrors()));
}

public function testValidAndInvalidFiles()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
Expand Down
2 changes: 2 additions & 0 deletions tests/Settings.parseArguments.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SettingsParseArgumentsTest extends Tester\TestCase
$expectedSettings->excluded = array('vendor');
$expectedSettings->colors = Settings::DISABLED;
$expectedSettings->json = false;
$expectedSettings->deprecated = false;

Assert::equal($expectedSettings->phpExecutable, $settings->phpExecutable);
Assert::equal($expectedSettings->shortTag, $settings->shortTag);
Expand All @@ -65,6 +66,7 @@ class SettingsParseArgumentsTest extends Tester\TestCase
Assert::equal($expectedSettings->excluded, $settings->excluded);
Assert::equal($expectedSettings->colors, $settings->colors);
Assert::equal($expectedSettings->json, $settings->json);
Assert::equal($expectedSettings->showDeprecated, $settings->showDeprecated);
}

public function testColorsForced()
Expand Down
15 changes: 15 additions & 0 deletions tests/examples/example-05/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

class Foo
{

/**
* @var string
*/
private $bar;

public function Foo($bar)
{
$this->bar = $bar;
}
}

0 comments on commit 7f8b8e1

Please sign in to comment.