-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Tokenizer::$eolChar: change default value #3870
Conversation
... to be a more logical one. The property is supposed to be a `string`, so having an array as a default value is confusing.
@@ -27,7 +27,7 @@ abstract class Tokenizer | |||
* | |||
* @var string | |||
*/ | |||
protected $eolChar = []; | |||
protected $eolChar = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the default value be non-empty? What are your thoughts on using PHP_EOL
here instead of an empty string. Or perhaps null
or unset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did consider those options, but those were all rejected out of hand.
- The property is documented as a string, so the default should also be a string.
- Setting the default to
null
may lead to PHP 8.1 "passing null to non-nullable" deprecations in unexpected places. - Setting the default to
PHP_EOL
is plain wrong as that depends on the OS on which PHPCS is run, while the property is about the EOL character of the file under scan.
Setting it to an empty string prevents any problems with a wrong value being used and still complies with the documented property type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, the property is the first thing which will be set once the class is instantiated via the contructor, so the default value isn't even that interesting, though it should definitely not be one of an incorrect type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. This all makes sense. 👍
Given my "approval" based on the description of the PR and the discussion about a default |
Closing as replaced by PHPCSStandards/PHP_CodeSniffer#81 |
Description
Tokenizer::$eolChar: change default value to be a more logical one. The property is supposed to be a
string
, so having an array as a default value is confusing.Suggested changelog entry
N/A
Types of changes