Skip to content
Permalink
Browse files

Issue 1926 unused variable (#1967)

* add support for Psalter to remove UnusedVariable

* fix issues found by Psalm

* fix stylistic issues found by phpcs

* added more stylistic changes and suppressed UndefinedClass error for Psalm

* suppress TypeDoesNotContainType error for CheckTrivialExprVisitor

* fix whitespace issue raised by phpcs

* fix bug where partial removal of assignment by ref does not process '&' symbol

* Remove workspace files

* remove 'Array_' and 'ArrayItem' classes from blacklist and add 'New_' class to the blacklist
  • Loading branch information...
jeffreyyoo authored and muglug committed Jul 24, 2019
1 parent 82e79aa commit ed61bcafda2e3f60207319eb1f14a0efba34a774
@@ -12,3 +12,6 @@
/vendor-bin/*/composer.lock
/vendor-bin/*/vendor/
/tests/fixtures/symlinktest/*

.idea/inspectionProfiles/Project_Default.xml
.idea/workspace.xml
@@ -21,17 +21,26 @@ class FileManipulation
/** @var bool */
public $preserve_indentation;
/** @var bool */
public $remove_trailing_newline;
/**
* @param int $start
* @param int $end
* @param string $insertion_text
*/
public function __construct(int $start, int $end, string $insertion_text, bool $preserve_indentation = false)
{
public function __construct(
int $start,
int $end,
string $insertion_text,
bool $preserve_indentation = false,
bool $remove_trailing_newline = false
) {
$this->start = $start;
$this->end = $end;
$this->insertion_text = $insertion_text;
$this->preserve_indentation = $preserve_indentation;
$this->remove_trailing_newline = $remove_trailing_newline;
}
public function getKey() : string
@@ -55,6 +64,19 @@ public function transform(string $existing_contents) : string
}
}
if ($this->remove_trailing_newline && $existing_contents[$this->end] === "\n") {
$newline_pos = strrpos($existing_contents, "\n", $this->start - strlen($existing_contents));
$newline_pos = $newline_pos !== false ? $newline_pos + 1 : 0;
$indentation = substr($existing_contents, $newline_pos, $this->start - $newline_pos);
if (trim($indentation) === '') {
$this->start -= strlen($indentation);
$this->end++;
}
}
return substr($existing_contents, 0, $this->start)
. $this->insertion_text
. substr($existing_contents, $this->end);
@@ -27,6 +27,7 @@
use Psalm\Issue\PossiblyUnusedProperty;
use Psalm\Issue\UnusedMethod;
use Psalm\Issue\UnusedProperty;
use Psalm\Issue\UnusedVariable;
use Psalm\Progress\Progress;
use Psalm\Progress\VoidProgress;
use Psalm\Report;
@@ -205,6 +206,7 @@ class ProjectAnalyzer
PossiblyUnusedProperty::class,
UnusedMethod::class,
UnusedProperty::class,
UnusedVariable::class,
];
/**

0 comments on commit ed61bca

Please sign in to comment.
You can’t perform that action at this time.