DocBlock/Tags/Source: remove redundant code #288
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PHPStan flags the code within the
Source::__toString()
method:I have investigated this and can confirm that these flags are correct.
$this->startingLine
is cast to an integer in the__construct()
method (line 45) and subsequently cast to a string in__toString()
(line 105).This means that it can only ever be a non-empty ("truthy") string or the string '0', so the
$startingLine || $startingLine === '0'
condition used in two places is redundant.$this->lineCount
is either an integer ornull
after the__construct()
method (line 46).In the
__toString()
method, if thelineCount
is an integer, it is effectively cast to a string by the concatenation with an empty string on line 107, while if thelineCount
wasnull
, it is turned into an empty string.By changing the concatenation from concatenating with an empty string to concatenating with a one-space string, we can remove the ternary in the
return
statement checking for$lineCount
being empty.The existing unit tests already cover this code and still pass after this change.