Recommend this page to a friend! |
Classes of Adeleye Ayodeji | Download Installed Plugin | vendor/phpcsstandards/phpcsutils/README.md | Download |
|
DownloadPHPCSUtils: A suite of utility functions for use with PHP_CodeSniffer<div aria-hidden="true"> [][phpcsutils-packagist] [][phpcsutils-releases] :construction: [][phpcsutils-web] [][phpcsutils-tests-gha] [][phpcsutils-packagist] [][phpcsutils-tests-gha] </div>
Features[PHPCSUtils][phpcsutils-repo] is a set of utilities to aid developers of sniffs for PHP_CodeSniffer. This package offers the following features: <div id="feature-list"> An ever-growing number of utility functions for use with PHP_CodeSnifferWhether you need to split an Includes improved versions of the PHPCS native utility functions and plenty of new utility functions. These functions are compatible with PHPCS 3.10.0 up to PHPCS A collection of static properties and methods for often-used token groupsCollections of related tokens often-used and needed for sniffs.
These are additional "token groups" to compliment the ones available through the PHPCS native Several abstract sniff classes which your sniffs can extendThese classes take most of the heavy lifting away for some frequently occurring sniff types. Test utilitiesAn abstract Use the latest version of PHP_CodeSniffer native utility functionsNormally to use the latest version of PHP_CodeSniffer native utility functions, you would have to raise the minimum requirements of your external PHPCS standard. Now you won't have to anymore. This package allows you to use the latest version of those utility functions in all PHP_CodeSniffer versions from PHPCS 3.10.0 and up. Fully documentedTo see detailed information about all the available abstract sniffs, utility functions and PHPCS helper functions, have a read through the [extensive documentation][phpcsutils-web]. </div> Minimum Requirements
Integrating PHPCSUtils in your external PHPCS standardComposer-basedIf your external PHP_CodeSniffer standard only supports Composer-based installs, integrating PHPCSUtils is pretty straight forward. Run the following from the root of your external PHPCS standard's project:
No further action needed. You can start using all the utility functions, abstract sniff classes and other features of PHPCSUtils straight away. > :information_source: The PHPCSUtils package includes the [Composer PHPCS plugin].
>
> This plugin will automatically register PHPCSUtils (and your own external standard) with PHP_CodeSniffer, so you and your users don't have to worry about this anymore.
>
> :warning: Note: if your end-user installation instructions include instructions on adding a Composer PHPCS plugin or on manually registering your standard with PHPCS using the Running your unit testsIf your unit tests use the PHP_CodeSniffer native unit test suite, all is good. If you have your own unit test suite to test your sniffs, make sure to load the Composer If you intend to use the test utilities provided in the Non-Composer based integrationIn this case, more than anything, you will need to update the non-Composer installation instructions for your end-users. To use a non-Composer based installation for your sniff development environment, the same instructions would apply. Your installation instructions for a non-Composer based installation will probably look similar to this: > * Install [PHP_CodeSniffer] via your preferred method.
> * Register the path to PHPCS in your system For things to continue working when you add PHPCSUtils to your standard, you need to replace the last bullet with this: > Next, download the [latest PHPCSUtils release][phpcsutils-releases] and unzip/untar it into an arbitrary directory.*
> You can also choose to clone the repository using git.
> Add the path to thedirectoriesin which you placed your copy of the _YourStandardName_ repoand the PHPCSUtils repo* to the PHP_CodeSniffer configuration using the below command:
>
> Running your unit testsTo support non-Composer based installs for running your sniff unit tests, you will need to adjust the PHPUnit <details> <summary><b>Example bootstrap code using a <code>PHPCSUtils_DIR</code> environment variable</b></summary>
</details> Once that's done, you will need to make a small tweak to your own dev environment to get the unit tests running for a non-Composer based install:
Frequently Asked Questions<div class="faq"> Q: How does this all work without an external standard needing to register an autoloader?A: As PHPCSUtils is registered with PHPCS as an external standard and PHPCSUtils complies with the naming requirements of PHPCS, the PHPCS native autoloader will automatically take care of loading the classes used from PHPCSUtils. Q: Does using PHPCSUtils have any effect on the PHPCS native sniffs?A: No. PHPCSUtils will only work for those sniffs which explicitly use the PHPCSUtils functionality. If your standard includes both PHPCS native sniffs as well as your own sniffs, your own sniffs can benefit from the back-compat layer offered by PHPCSUtils, as well as from the additional utility functions. However, the PHPCS native sniffs will not receive those benefits, as PHPCS itself does not use PHPCSUtils. Q: Do the utilities work with javascript/CSS files?A: JS/CSS support will be removed from Q: Are all file encodings supported?A: No. The UTF-8 file encoding is the only officially supported encoding. Support for other encodings may incidentally work, but is not officially supported. > It is recommended to advise your users to save their files as UTF-8 encoded for the best results. Note: </div> Potential Support Questions from your End-Users<div class="faq"> Q: A user reports a fatal "class not found" error for a class from PHPCSUtils
> :bulb: Pro-tip: if you want to prevent the fatal error and show a _friendlier_ error message instead, add > :bulb: Pro-tip: provide upgrade instructions for your end-users. For Composer-based installs, those should look like this:
>
> </div> ContributingContributions to this project are welcome. Clone the repo, branch off from If you are unsure whether the changes you are proposing would be welcome, please open an issue first to discuss your proposal. LicenseThis code is released under the GNU Lesser General Public License (LGPLv3). [PHP_CodeSniffer]: https://github.com/PHPCSStandards/PHP_CodeSniffer [Composer PHPCS plugin]: https://github.com/PHPCSStandards/composer-installer [phpcsutils-repo]: https://github.com/PHPCSStandards/PHPCSUtils [phpcsutils-web]: https://phpcsutils.com/ [phpcsutils-packagist]: https://packagist.org/packages/phpcsstandards/phpcsutils [phpcsutils-releases]: https://github.com/PHPCSStandards/PHPCSUtils/releases [phpcsutils-tests-gha]: https://github.com/PHPCSStandards/PHPCSUtils/actions/workflows/test.yml |