Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Aug 9, 2023

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

... 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 = '';
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@jrfnl jrfnl Aug 10, 2023

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.

Copy link
Contributor

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. 👍

@DannyvdSluijs
Copy link

Given my "approval" based on the description of the PR and the discussion about a default EOL character which all made sense.

@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 2, 2023

Closing as replaced by PHPCSStandards/PHP_CodeSniffer#81

@jrfnl jrfnl closed this Dec 2, 2023
@jrfnl jrfnl deleted the feature/tokenizer-fix-default-property-value branch December 2, 2023 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants