You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Behind the scenes, a side-project has started to create a (GitHub Pages) website for this project with helpful information about the things PHPCompatibility detects and how to fix them.
@afilina has done amazing work creating a documentation generation engine which will create a page with the basic information about each sniff from the docblocks in the sniff code itself.
To enhance this basic information with details on how to fix issues, we are looking to introduce XML documentation files for each sniff.
The information contained in these XML files will be added to the GitHub Pages document for each sniff automatically via the engine created by Anna.
About the XML documentation
The choice for XML documentation files is rooted in the fact that PHPCS itself supports that format natively and can display the information on the command line.
To see an example of this in action, run the below command for the PHPCS native documentation about the sniffs in the PSR12 standard:
phpcs --standard=PSR12 --generator=Text
The sniff documentation for an individual sniff can be shown like so:
By complying with these naming conventions the sniff documentation will be usable, both from the PHPCS command-line using phpcs --standard=PHPCompatibility --generator=Text, as well as by the documentation generation engine which will generate the GitHub Pages site.
XML file format
Example taken from the PSR12 documentation in PHPCS itself:
<documentationtitle="Short Form Type Keywords">
<standard>
<![CDATA[ Short form of type keywords MUST be used i.e. bool instead of boolean, int instead of integer etc.]]>
</standard>
<code_comparison>
<codetitle="Valid: Short form type used.">
<![CDATA[$foo = <em>(bool)</em> $isValid;]]>
</code>
<codetitle="Invalid: Long form type type used.">
<![CDATA[$foo = <em>(boolean)</em> $isValid;]]>
</code>
</code_comparison>
</documentation>
Things to take note of:
The title attribute in the <documentation> tag should generally reflect the name of the sniff.
Each XML file can contain multiple <standard> blocks.
Each <standard> block can be accompanied by one or more <code_comparison> blocks.
Each code comparison block should have two <code> sets, the first one showing "valid" code, i.e. code which is PHP cross-version compatible, the second one showing "invalid" code, i.e. code which would be flagged by the PHPCompatibility sniff.
The "valid" code sample description should - in most cases - be prefixed with "Cross version compatible:".
The "invalid" code sample description should - in most cases - be prefixed with a version indication, like "PHP < 7.0" or "PHP >= 7.4".
Please be aware that the < and > characters will need to be encoded for use in XML, i.e. > and <.
If possible, the specific code which triggers the flagging by PHPCompatibility should be surrounded by <em> tags to highlight it (for non-text generators).
The first line of the code samples should not be indented. If the code sample calls for it, subsequent lines can be (space) indented.
Each line within the code sample should be max 48 characters as otherwise the display on the command-line can be off.
All indentation in the XML file should be four-space based indentation. Do not use tabs.
Also note:
The documentation in this repo is expected to have the following XML header (with the "title" value replaced by the sniff name):
Code samples should generally be "anonymized".
I.e. don't use code which can be traced back to a specific project.
You can use blank lines in the <standard> and <code> blocks to improve readability of the information.
There is no character limit, so if a sniff warrants an extensive explanation on how to create cross-version compatible code, feel free to be verbose.
What about complex sniffs ?
As a rule of thumb, each individual error code should get its own "standard" description and/or code sample.
For "simple" sniffs, i.e. sniffs which only look for only one or a few related things, a single XML file should be introduced following the above naming conventions.
For "complex" sniffs which look for a lot of different issues, like for instance, the RemovedFunctions sniff, a base XML file should be created following the above guidelines, then, specifically for use and display on the website, additional XML files for individual error codes can be created in a subdirectory.
PHPCompatibility.Upgrade.LowPHP (not a functional sniff)
PHPCompatibility.Upgrade.LowPHPCS (not a functional sniff)
Want to contribute ?
Leave a comment below to claim a sniff to start work on.
One of the admins of the repo will then move the sniff to the "Claimed" list and your GitHub handle will be added next to it.
How to contribute
Fork this repository
Clone your fork/this repository to your local machine & run composer install
Create a new branch off develop for your changes.
Create the XML file and place it in the correct PHPCompatibility/Docs/Category/ directory.
You may need to create the directory if it doesn't exist yet.
To verify what the sniff is checking for, look for addWarning(), addError() or addMessage() method calls in the sniff file in the PHPCompatibility/Sniffs/Category/ directory to see the error messages the sniff generates.
To get inspiration for code examples, open the sniff's PHPCompatibility/Tests/Category/SniffNameUnitTest.inc file.
If the sniff generates several error messages and you are unsure which error applies to which code, you can run the following command to get a better understanding of which code triggers which error/warning:
To find information about exactly what has changed and how to make the code cross-version compatible, use the links in the sniff class docblock to find the relevant information in the PHP RFCs and manual.
Once you have finished writing up the sniff documentation, be sure to test it on the command-line:
Do a final review of your documentation to make sure it follows all the guidelines in the above "XML file format" section.
Commit your changes, push the new branch up to your own fork and create a pull request to this repository.
Please mention this issue in your pull request description "Related to [Project] Add XML documentation for each sniff #1285" so your pull request will be linked to this issue.
The text was updated successfully, but these errors were encountered:
Project description
Behind the scenes, a side-project has started to create a (GitHub Pages) website for this project with helpful information about the things PHPCompatibility detects and how to fix them.
@afilina has done amazing work creating a documentation generation engine which will create a page with the basic information about each sniff from the docblocks in the sniff code itself.
To enhance this basic information with details on how to fix issues, we are looking to introduce XML documentation files for each sniff.
The information contained in these XML files will be added to the GitHub Pages document for each sniff automatically via the engine created by Anna.
About the XML documentation
The choice for XML documentation files is rooted in the fact that PHPCS itself supports that format natively and can display the information on the command line.
To see an example of this in action, run the below command for the PHPCS native documentation about the sniffs in the PSR12 standard:
The sniff documentation for an individual sniff can be shown like so:
Naming Conventions for the XML files
PHPCS has strict naming conventions for the XML files to allow the build-in documentation generators to work with them.
Standard/Sniffs/Category/SniffNameSniff.php
Standard/Docs/Category/SniffNameStandard.xml
PHPCompatibility/Sniffs/Lists/NewShortListSniff.php
PHPCompatibility/Docs/Lists/NewShortListStandard.xml
By complying with these naming conventions the sniff documentation will be usable, both from the PHPCS command-line using
phpcs --standard=PHPCompatibility --generator=Text
, as well as by the documentation generation engine which will generate the GitHub Pages site.XML file format
Example taken from the PSR12 documentation in PHPCS itself:
Things to take note of:
title
attribute in the<documentation>
tag should generally reflect the name of the sniff.<standard>
blocks.<standard>
block can be accompanied by one or more<code_comparison>
blocks.<code>
sets, the first one showing "valid" code, i.e. code which is PHP cross-version compatible, the second one showing "invalid" code, i.e. code which would be flagged by the PHPCompatibility sniff.Please be aware that the
<
and>
characters will need to be encoded for use in XML, i.e.>
and<
.<em>
tags to highlight it (for non-text generators).Also note:
I.e. don't use code which can be traced back to a specific project.
<standard>
and<code>
blocks to improve readability of the information.What about complex sniffs ?
As a rule of thumb, each individual error code should get its own "standard" description and/or code sample.
For "simple" sniffs, i.e. sniffs which only look for only one or a few related things, a single XML file should be introduced following the above naming conventions.
For "complex" sniffs which look for a lot of different issues, like for instance, the
RemovedFunctions
sniff, a base XML file should be created following the above guidelines, then, specifically for use and display on the website, additional XML files for individual error codes can be created in a subdirectory.This would look like this:
Note: The additional "error code"-based XML files will not display on the command line. They will only be used for the website.
Action list
To do
Claimed/Work in Progress
Done
PHPCompatibility.Classes.ForbiddenExtendingFinalClass
sniff #1486PHPCompatibility.Classes.NewConstructorPropertyPromotion
sniff #1417PHPCompatibility.Classes.NewFinalClassConstants
sniff #1317PHPCompatibility.Classes.NewReadonlyClasses
sniff #1453PHPCompatibility.Classes.NewReadonlyProperties
sniff #1426PHPCompatibility.Constants.NewConstantsInTraits
sniff #1443PHPCompatibility.FunctionDeclarations.RemovedReturnByReferenceFromVoid
sniff #1316PHPCompatibility.Numbers.NewExplicitOctalNotation
sniff #1420PHPCompatibility.ParameterValues.ForbiddenGetClassNoArgsOutsideOO
sniff #1602PHPCompatibility.ParameterValues.NewArrayMergeRecursiveWithGlobalsVar
sniff #1488PHPCompatibility.ParameterValues.NewHTMLEntitiesFlagsDefault
sniff #1419PHPCompatibility.ParameterValues.RemovedGetClassNoArgs
sniff (RFC) #1614PHPCompatibility.ParameterValues.RemovedLdapConnectSignatures
sniff (RFC) #1620PHPCompatibility.ParameterValues.RemovedMbCheckEncodingNoArgs
sniff #1315PHPCompatibility.ParameterValues.RemovedMbStrimWidthNegativeWidth
sniff (RFC) #1615PHPCompatibility.ParameterValues.RemovedVersionCompareOperators
sniff #1418PHPCompatibility.Syntax.NewFirstClassCallables
sniff #1425PHPCompatibility.TextStrings.RemovedDollarBraceStringEmbeds
sniff #1424No Action Needed
PHPCompatibility.Extensions.RemovedExtensions(sniff will be removed)PHPCompatibility.FunctionDeclarations.NewArrowFunction(sniff will be removed)PHPCompatibility.Keywords.ForbiddenNamesAsDeclared(sniff removed)PHPCompatibility.Keywords.ForbiddenNamesAsInvokedFunctions(sniff removed)Want to contribute ?
Leave a comment below to claim a sniff to start work on.
One of the admins of the repo will then move the sniff to the "Claimed" list and your GitHub handle will be added next to it.
How to contribute
composer install
develop
for your changes.PHPCompatibility/Docs/Category/
directory.You may need to create the directory if it doesn't exist yet.
addWarning()
,addError()
oraddMessage()
method calls in the sniff file in thePHPCompatibility/Sniffs/Category/
directory to see the error messages the sniff generates.PHPCompatibility/Tests/Category/SniffNameUnitTest.inc
file.If the sniff generates several error messages and you are unsure which error applies to which code, you can run the following command to get a better understanding of which code triggers which error/warning:
Please mention this issue in your pull request description "Related to [Project] Add XML documentation for each sniff #1285" so your pull request will be linked to this issue.
The text was updated successfully, but these errors were encountered: