PHP 8.1 | Runner::processChildProcs(): fix passing null to non-nullable bug #3425
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.
The
DummyFile::__construct()
method expects astring
as the first parameter, subsequently passes it to theFile::setContent()
method, which also expects astring
, which then passes it to theCommon::detectLineEndings()
method, which again expects astring
.Within the
Common::detectLineEndings()
method, the string is then passed to the PHP nativepreg_match()
function, which (again) expects astring
for the$subject
parameter.When using PHPCS with parallel processing turned on, on a system which allows for parallel processing, the
DummyFile
class was, however, being instantiated in theRunner::processChildProcs()
method withnull
as the content of the first parameter, which on PHP 8.1 leads topreg_match(): Passing null to parameter #2 ($subject) of type string is deprecated
deprecation notices.This deprecation notice was then caught as a
RuntimeException
in theFile::setContent()
method and passed on to theFile::addWarningOnLine()
, which called theFile::addMessage()
method.The
File::addMessage()
parameter then ran into trouble as the$this->config
property has not been set up yet, asDummyFile::__construct()
callsFile::setContent()
before calling theparent::__construct()
method, leading to theUndefined array key "cache"
notices which were making the build fail.Fixed now by passing an empty string instead of
null
as the$content
for theDummyFile
in theRunner::processChildProcs()
method.This then leaves one more issue: the
DummyFile::__construct()
method contains a conditional code block which was only run when$content !== null
. As this conditional code block is also not necessary to be run when an empty string would be passed to the constructor, changing this condition to$content !== ''
makes that the condition can still match and maintains the efficiency tweak the condition was safeguarding.This fixes the last, currently known, PHP 8.1 runtime issue. This does not make PHPCS fully compatible with PHP 8.1 yet as there are syntax changes in PHP 8.1 for which the
Tokenizer
will need adjusting, as well as sniff adjustments still needed, but at least the runtime issues should be out of the way now.