Skip to content

Generic/RequireStrictTypes: add XML documentation #236

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

Merged

Conversation

rodrigoprimo
Copy link
Contributor

Description

This PR adds documentation for the Generic.PHP.RequireStrictTypes sniff.

Suggested changelog entry

Add XML documentation for the Generic.PHP.RequireStrictTypes sniff.

Related issues/external references

Part of #148

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

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rodrigoprimo for this PR.

When looking at the actual sniff code and at the code samples, I'm wondering why you've elected to go for one standards block with one code comparison block ?

Some extra context about this sniff: #51 (recent change included in the 3.8.0 release)

@rodrigoprimo
Copy link
Contributor Author

Thanks for checking this PR, @jrfnl!

When looking at the actual sniff code and at the code samples, I'm wondering why you've elected to go for one standards block with one code comparison block ?

Even though the sniff shows different errors/warnings for missing required strict_types and for strict_types found but disabled, I opted to use one <standard> and one <code_comparison> block as the valid examples would be essentially the same (similar to what we discussed in #177 and #159 (comment)).

Some extra context about this sniff: #51 (recent change included in the 3.8.0 release)

Upon seeing this PR, I realized that there are some valid cases that are not covered in the examples (case-insensitive execution directives, docblocks at the top of the file). Would you like me to add those?

@jrfnl
Copy link
Member

jrfnl commented Jan 12, 2024

Even though the sniff shows different errors/warnings for missing required strict_types and for strict_types found but disabled, I opted to use one <standard> and one <code_comparison> block as the valid examples would be essentially the same (similar to what we discussed in #177 and #159 (comment)).

The difference between those sniffs and this sniff is one of PHP functionality.

The other sniffs where checking for exactly one space in a certain place and whether there is too much space or too little space, the basic principle of the check is still the same.

That's not the case for this sniff. This sniff is checking for two closely related, but distinctly different things:

  1. Is there a strict_types declaration ?
  2. Is the strict_types declaration configured to enable strict_types ?

It could be perfectly valid for a project to require strict_types declarations, but not require them to be set to enabled (1). It might be rare and an edge-case, but it would still be perfectly valid.

In my mind, that means these two different rules need to be separated in the docs.

Some extra context about this sniff: #51 (recent change included in the 3.8.0 release)

Upon seeing this PR, I realized that there are some valid cases that are not covered in the examples (case-insensitive execution directives, docblocks at the top of the file). Would you like me to add those?

No, those kind of things are implementation details for the sniff to function correctly and do not belong in the docs.

@rodrigoprimo
Copy link
Contributor Author

Thanks for the additional details, @jrfnl. After seeing your response, I agree that there is a significant difference between this sniff and the ones that I mentioned.

In my mind, that means these two different rules need to be separated in the docs.

There is one more thing that is making me unsure about separating these two rules in the docs that I want to check with you before proceeding with your suggestion. To facilitate the conversation, I pushed a temporary commit with a rough draft of how the XML documentation would look after the separation (3975274). Is this more or less what you have in mind?

It could be perfectly valid for a project to require strict_types declarations, but not require them to be set to enabled (1). It might be rare and an edge-case, but it would still be perfectly valid.

So far, all the documentation that I created for the sniffs describes only the default behavior of the sniff. I might be missing something, but I believe the behavior you described above is valid, but not possible without altering the default behavior and disabling Generic.PHP.RequiredStrictTypes.Disabled, no? My concern here is that this means that in the documentation, one of the valid examples for Generic.PHP.RequiredStrictTypes.MissingDeclaration (declare(<em>strict_types=0</em>);) is invalid when the sniff runs with the default configuration because of Generic.PHP.RequiredStrictTypes.Disabled.

@jrfnl
Copy link
Member

jrfnl commented Feb 23, 2024

@rodrigoprimo Sorry, I just realized I never got back to you after your comment. I'm going to leave some suggestions inline to see if we can move this PR forward.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some suggestions inline. Does that answer your questions sufficiently ?

@jrfnl
Copy link
Member

jrfnl commented Feb 23, 2024

Oh and I'm not sure the PHP open tags are needed in the code samples. The sniff (currently) just tries to find a declare() statement and doesn't actually check that it is the first statement in the file. (that might be something which could be added to the sniff, but is not currently checked)

@rodrigoprimo
Copy link
Contributor Author

Thanks for the review, @jrfnl!

I pushed a commit implementing your suggestions and another one with two minor changes that occurred to me while checking the docs again. Similar to your suggestion here, I removed a redundant example and also changed the <em> tag position in one of the examples.

Oh and I'm not sure the PHP open tags are needed in the code samples. The sniff (currently) just tries to find a declare() statement and doesn't actually check that it is the first statement in the file. (that might be something which could be added to the sniff, but is not currently checked)

I believe I had added the PHP open tags wrongly assuming that the sniff checked the declare() statement is the first statement in the file. I have removed them for now and I can look into changing the sniff to check that in a separate PR.

Left some suggestions inline. Does that answer your questions sufficiently ?

I'm still unsure about adding an example that will throw an error when the sniff is run with the default configuration. But if that is not a problem, we can proceed.

@jrfnl
Copy link
Member

jrfnl commented Feb 23, 2024

I believe I had added the PHP open tags wrongly assuming that the sniff checked the declare() statement is the first statement in the file. I have removed them for now and I can look into changing the sniff to check that in a separate PR.

I probably should have opened an issue about that after merging PR #51.

Note: updating the sniff for this should not be underestimated. There are some notes under "Future scope" in PR #51 which detail some things to take into account/choices which would need to be made.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit implementing your suggestions and another one with two minor changes that occurred to me while checking the docs again. Similar to your suggestion here, I removed a redundant example and also changed the <em> tag position in one of the examples.

I'm still unsure about adding an example that will throw an error when the sniff is run with the default configuration. But if that is not a problem, we can proceed.

@rodrigoprimo Thanks for the update. LGTM! I think the examples as they are now are clear and instructive.

I'll rebase (without changes) and will merge this once the build has passed.

@jrfnl jrfnl force-pushed the documentation-require-strict-types branch from f8e7859 to c7f8834 Compare February 24, 2024 07:07
@jrfnl jrfnl added this to the 3.9.1 milestone Feb 24, 2024
@jrfnl jrfnl merged commit 29cf01e into PHPCSStandards:master Feb 24, 2024
jrfnl pushed a commit that referenced this pull request Feb 24, 2024
* Generic/RequireStrictTypes: add XML documentation

* Rough draft of how the docs look like separating the two rules

* Generic/RequireStrictTypes: improve docs based on PR review suggestions

* Generic/RequireStrictTypes: further improvements to the docs

Remove one redundant invalid example and make one highlight more
meaningful.
@rodrigoprimo rodrigoprimo deleted the documentation-require-strict-types branch February 26, 2024 14:12
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.

2 participants