├── .gitattributes ├── CHANGELOG.md ├── LICENSE ├── README.md ├── WPForms ├── Sniffs │ ├── BaseSniff.php │ ├── Comments │ │ ├── DeprecatedTagHooksSniff.php │ │ ├── DeprecatedTagSniff.php │ │ ├── DescriptionStopSymbolPropertySniff.php │ │ ├── DescriptionStopSymbolSniff.php │ │ ├── LanguageInjectionSniff.php │ │ ├── NoSpacesAfterParamTagSniff.php │ │ ├── NoSpacesAfterReturnTagSniff.php │ │ ├── PHPDocDefineSniff.php │ │ ├── PHPDocHooksSniff.php │ │ ├── ParamTagHooksSniff.php │ │ ├── ShortDescriptionHooksSniff.php │ │ ├── SinceTagDefineSniff.php │ │ ├── SinceTagHooksSniff.php │ │ ├── SinceTagPropertySniff.php │ │ ├── SinceTagSniff.php │ │ └── TranslatorsSniff.php │ ├── Formatting │ │ ├── EmptyLineAfterAssigmentVariablesSniff.php │ │ ├── EmptyLineAfterFunctionDeclarationSniff.php │ │ ├── EmptyLineBeforeReturnSniff.php │ │ └── SwitchSniff.php │ ├── PHP │ │ ├── BackSlashSniff.php │ │ ├── ConditionsYodaDisableSniff.php │ │ ├── HooksMethodSniff.php │ │ ├── UseStatementSniff.php │ │ ├── ValidateDomainSniff.php │ │ └── ValidateHooksSniff.php │ └── PropertyBaseSniff.php ├── Traits │ ├── CommentTag.php │ ├── Description.php │ ├── DuplicateHook.php │ ├── GetEntityName.php │ └── Version.php └── ruleset.xml └── composer.json /.gitattributes: -------------------------------------------------------------------------------- 1 | .github export-ignore 2 | WPForms/Tests export-ignore 3 | .gitignore export-ignore 4 | .phpcs.xml export-ignore 5 | composer.lock export-ignore 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file and formatted via [this recommendation](https://keepachangelog.com/). 3 | 4 | ## [1.5.0] - 2025-03-28 5 | ### Changed 6 | - The minimum supported PHP version is now 7.2. 7 | 8 | ## [1.4.0] - 2024-12-20 9 | ### Changed 10 | - ReturnTagHooksSniff is removed. 11 | 12 | ## [1.3.0] - 2024-12-16 13 | ### Changed 14 | - The minimum supported PHP version is now 7.1. 15 | 16 | ### Fixed 17 | - Return tag hook sniff did not work. 18 | 19 | ## [1.2.3] - 2024-08-29 20 | - Rule "WordPressVIPMinimum.Performance.WPQueryParams" is added as required by Plugin Check Plugin. 21 | - Rule "WordPress.DB.DirectDatabaseQuery.DirectQuery" is not suppressed anymore as required by the Plugin Check Plugin. 22 | - Rule "WordPress.WP.EnqueuedResourceParameters.MissingVersion" is not suppressed anymore as required by Plugin Check Plugin. 23 | - Rule "WordPress.WP.EnqueuedResourceParameters.NoExplicitVersion" is not suppressed anymore as required by Plugin Check Plugin. 24 | 25 | ## [1.2.2] - 2024-08-22 26 | ### Changed 27 | - Rule WordPress.WP.EnqueuedResourceParameters.NotInFooter is not suppressed anymore as it is required now by the Plugin Check Plugin. 28 | 29 | ## [1.2.1] - 2024-08-19 30 | ### Added 31 | - Support of WP Coding Standard 3.1.0. 32 | 33 | ## [1.2.0] - 2024-02-08 34 | ### Fixed 35 | - Function return type broke WPForms.Formatting.EmptyLineBeforeReturn sniff. 36 | - The phpcs did not work locally with PHP 8+. 37 | 38 | ## [1.1.0] - 2023-09-07 39 | ### Fixed 40 | - Extract _plugin from hook name for main plugin class like Plugin.php. 41 | 42 | ## [1.0.7] - 2023-08-23 43 | ### Added 44 | - Support of WP Coding Standard 3.0. 45 | 46 | ## [1.0.6] - 2022-09-20 47 | ### Fixed 48 | - Validation of text domains in addons. 49 | 50 | ## [1.0.5] - 2022-09-12 51 | ### Fixed 52 | - Lowercase classname without namespace. 53 | - Since tag processing. 54 | - Expected domain calculation for dirs not specified in the ValidateDomain property. 55 | - Fix expected domain calculation for the same dir where phpcs.xml is. 56 | 57 | ### Added 58 | - Respect PhpDoc comments in switch statement. 59 | 60 | ## [1.0.4] - 2022-03-09 61 | ### Added 62 | - Allow comment before switch and case statements. 63 | 64 | ## [1.0.3] - 2022-02-24 65 | ### Added 66 | - Exclude comment lines from consideration. 67 | 68 | ### Changed 69 | - Improve skipping parenthesis in arguments. 70 | 71 | ### Fixed 72 | - Wrong claiming of short syntax. 73 | - Wrong counting of hook params with nested parenthesis. 74 | - Fix InvalidParamTagsQuantity sniff. 75 | - Respect /** This action is documented in some-class.php */ comment. 76 | - Alignment of @param tags. 77 | 78 | ## [1.0.2] - 2022-01-11 79 | ### Fixed 80 | - Prevent endless loop in HooksMethodSniff. 81 | 82 | ## [1.0.1] - 2022-01-11 83 | ### Fixed 84 | - Validation of text domain via property in phpcs.xml. 85 | 86 | ## [1.0.0] - 2022-01-06 87 | - Initial release. 88 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WPForms Coding Standards 2 | 3 | Maintainers: The WPForms team 4 | 5 | License: GPLv2 any later version.
6 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 7 | 8 | ## Description 9 | 10 | WPForms coding standards are based on the [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards) and the [PHPCompatibility Coding Standards](https://github.com/PHPCompatibility/PHPCompatibility) and help create strict and high-quality code. 11 | 12 | ## Installation 13 | 14 | ``` 15 | composer config repositories.repo-name vcs https://github.com/awesomemotive/wpforms-phpcs.git 16 | composer require awesomemotive/wpforms-phpcs --dev 17 | ``` 18 | 19 | ## Configuration 20 | 21 | Create the `.phpcs.xml` or `phpcs.xml` file at the root of your project: 22 | 23 | ```xml 24 | 25 | 26 | The WPForms coding standard. 27 | 28 | \vendor/* 29 | \.github/* 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | ``` 45 | 46 | ## Sniffs detail 47 | 48 | ### Validate Text Domain Sniff 49 | 50 | The `WPForms.PHP.ValidateDomain` sniff validates that you are using the correct text domain for `i18n` functions such as `__()`, `_e()`, `_n()`, etc. 51 | 52 | By default, this sniff works for one domain in the project. We get a directory name based on the `vendor` directory or the location of the `phpcs.xml`/`.phpcs.xml` file. 53 | 54 | You can install our package to the `plugins` directory and enable the multi-domain mode. in this case, the text domain will be the next folder name in the path. Structure: 55 | 56 | ``` 57 | ../wp-content/plugins/ # → Root 58 | ├── wpforms/ # → `wpforms` domain. 59 | └── wpforms-stripe/ # → `wpforms-stripe` domain. 60 | ``` 61 | 62 | In your config you should enable the `multi_domains` property: 63 | 64 | ```xml 65 | 66 | 67 | 68 | 69 | 70 | 71 | ``` 72 | 73 | If you have different domains for directories inside your project (for example, for free and paid versions) and want to redefine the text domain for some paths: 74 | ``` 75 | ../wp-content/plugins/ # → Root 76 | ├── wpforms/ # → `wpforms-lite` domain. 77 | │ ├── pro/ # → `wpforms` domain. 78 | │ └── src/ # → `wpforms-lite` domain. 79 | │ ├── Admin/ # → `wpforms-lite` domain. 80 | │ └── Pro/ # → `wpforms` domain. 81 | └── wpforms-stripe/ # → `wpforms-stripe` domain. 82 | ``` 83 | 84 | In this case, you should add to the config file the property with `name` as a text domain and `value` as a path. If a domain has several paths, then list them via commas. 85 | 86 | ```xml 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | ``` 100 | -------------------------------------------------------------------------------- /WPForms/Sniffs/BaseSniff.php: -------------------------------------------------------------------------------- 1 | ruleset ) || 39 | empty( $phpcsFile->ruleset->paths[0] ) 40 | ) { 41 | return ''; 42 | } 43 | 44 | $filePath = realpath( $phpcsFile->ruleset->paths[0] ); 45 | 46 | if ( 'ruleset.xml' !== basename( $filePath ) ) { 47 | return dirname( $filePath ); 48 | } 49 | 50 | foreach ( 51 | [ 52 | '.vendor', 53 | 'vendor', 54 | '.packages', 55 | 'packages', 56 | 'WPForms', // For tests. 57 | ] as $dir 58 | ) { 59 | if ( false !== stripos( $filePath, $dir ) ) { 60 | preg_match( '/(.*[\/\\\][\w.-]+[\/\\\])' . $dir . '[\/\\\]/u', $filePath, $rootPath ); 61 | 62 | return ! empty( $rootPath[1] ) ? $rootPath[1] : ''; 63 | } 64 | } 65 | 66 | return ''; 67 | } 68 | 69 | /** 70 | * Get a relative path from project root directory. 71 | * 72 | * @since 1.0.0 73 | * 74 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 75 | * 76 | * @return string 77 | */ 78 | protected function getRelativePath( $phpcsFile ) { 79 | 80 | $filePath = realpath( $phpcsFile->path ); 81 | $root = $this->getRootDirectory( $phpcsFile ); 82 | 83 | $csFolder = 'php_codesniffertemp_folder'; 84 | 85 | if ( stripos( $filePath, $csFolder ) !== false ) { 86 | // Special case for processing temp file in the PhpStorm temp folder. 87 | $filePath = preg_replace( '#.+[/\\\]' . $csFolder . '\d+[/\\\]#i', '', $filePath ); 88 | 89 | $rootArr = array_filter( explode( DIRECTORY_SEPARATOR, $root ) ); 90 | 91 | $count = count( $rootArr ); 92 | 93 | for ( $i = 0; $i < $count; $i++ ) { 94 | $rootPart = implode( DIRECTORY_SEPARATOR, array_slice( $rootArr, $i ) ); 95 | 96 | if ( strpos( $filePath, $rootPart ) === 0 ) { 97 | return str_replace( $rootPart, '', $filePath ); 98 | } 99 | } 100 | 101 | return $filePath; 102 | } 103 | 104 | return str_replace( $root, '', $filePath ); 105 | } 106 | 107 | /** 108 | * Return filename with current OS directory separators. 109 | * 110 | * @since 1.0.0 111 | * 112 | * @param string $filename Filename. 113 | * 114 | * @return string 115 | */ 116 | protected function normalizeFilename( $filename ) { 117 | 118 | return str_replace( '/', DIRECTORY_SEPARATOR, $filename ); 119 | } 120 | 121 | /** 122 | * Get the first argument of a function. 123 | * 124 | * @since 1.0.0 125 | * 126 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 127 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 128 | * 129 | * @return string 130 | */ 131 | protected function getFirstArgument( $phpcsFile, $stackPtr ) { 132 | 133 | $blankTokens = [ T_WHITESPACE, T_COMMENT, T_PHPCS_IGNORE ]; 134 | 135 | $tokens = $phpcsFile->getTokens(); 136 | $openPtr = $phpcsFile->findNext( T_OPEN_PARENTHESIS, $stackPtr ); 137 | $closePtr = $tokens[ $openPtr ]['parenthesis_closer']; 138 | $commaPtr = $phpcsFile->findNext( T_COMMA, $openPtr, $closePtr ); 139 | 140 | if ( $commaPtr ) { 141 | $closePtr = $commaPtr; 142 | } 143 | 144 | $openPtr = $phpcsFile->findNext( $blankTokens, $openPtr + 1, $closePtr, true ); 145 | $closePtr = $phpcsFile->findPrevious( $blankTokens, $closePtr - 1, $openPtr, true ); 146 | 147 | $firstArgument = trim( $phpcsFile->getTokensAsString( $openPtr, $closePtr - $openPtr + 1 ) ); 148 | 149 | return strtolower( 150 | preg_replace( '/[\'\"]/', '', $firstArgument ) 151 | ); 152 | } 153 | 154 | /** 155 | * Check whether the token is break in the switch statement. 156 | * 157 | * @since 1.0.4 158 | * 159 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 160 | * @param array $token First token on the next line. 161 | * 162 | * @return bool 163 | */ 164 | protected function isBreakInSwitch( $phpcsFile, $token ) { 165 | 166 | $tokens = $phpcsFile->getTokens(); 167 | 168 | if ( $token['code'] !== T_BREAK ) { 169 | return false; 170 | } 171 | 172 | return ( 173 | isset( $token['scope_condition'] ) && 174 | in_array( $tokens[ $token['scope_condition'] ]['code'], [ T_CASE, T_DEFAULT ], true ) 175 | ); 176 | } 177 | 178 | /** 179 | * Get a fully qualified class name. 180 | * 181 | * @since 1.0.0 182 | * 183 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 184 | * 185 | * @return string 186 | */ 187 | protected function getFullyQualifiedClassName( $phpcsFile ) { 188 | 189 | $namespace = ''; 190 | $stackPtr = 0; 191 | $namespacePtr = $phpcsFile->findNext( T_NAMESPACE, $stackPtr ); 192 | 193 | if ( $namespacePtr !== false ) { 194 | $nsEnd = $phpcsFile->findNext( 195 | [ T_NS_SEPARATOR, T_STRING, T_WHITESPACE ], 196 | $namespacePtr + 1, 197 | null, 198 | true 199 | ); 200 | 201 | $namespace = trim( $phpcsFile->getTokensAsString( $namespacePtr + 1, $nsEnd - $namespacePtr - 1 ) ); 202 | $stackPtr = $nsEnd; 203 | } 204 | 205 | $classPtr = $phpcsFile->findNext( T_CLASS, $stackPtr ); 206 | 207 | if ( $classPtr === false ) { 208 | return ''; 209 | } 210 | 211 | $classEnd = $phpcsFile->findNext( 212 | [ T_EXTENDS, T_IMPLEMENTS, 'PHPCS_T_OPEN_CURLY_BRACKET' ], 213 | $classPtr + 1 214 | ); 215 | 216 | $class = trim( $phpcsFile->getTokensAsString( $classPtr + 1, $classEnd - $classPtr - 1 ) ); 217 | $class = $this->convertClassName( $class ); 218 | 219 | $fqcn = $this->camelToSnake( str_replace( '\\', '', $namespace ) ) . '_' . $class; 220 | 221 | // Fix WPForms. 222 | // Remove _plugin for the main plugin class, which is usually Plugin. 223 | $fqcn = str_replace( [ 'wp_forms', '_plugin' ], [ 'wpforms', '' ], $fqcn ); 224 | 225 | $fqcnArr = explode( '_', $fqcn ); 226 | 227 | $prevItem = ''; 228 | 229 | // Remove repetitions. 230 | foreach ( $fqcnArr as $key => $item ) { 231 | if ( $prevItem === $item ) { 232 | unset( $fqcnArr[ $key ] ); 233 | } 234 | 235 | $prevItem = $item; 236 | } 237 | 238 | return implode( '_', $fqcnArr ); 239 | } 240 | 241 | /** 242 | * Convert class name to snake case. 243 | * 244 | * @since 1.0.2 245 | * 246 | * @param string $className Class name. 247 | * 248 | * @return string 249 | */ 250 | private function convertClassName( $className ) { 251 | 252 | if ( strpos( $className, '_' ) !== false ) { 253 | return strtolower( $className ); 254 | } 255 | 256 | return $this->camelToSnake( $className ); 257 | } 258 | 259 | /** 260 | * Convert string from CamelCase to snake_case. 261 | * 262 | * @since 1.0.2 263 | * 264 | * @param string $s A string. 265 | * 266 | * @return string 267 | */ 268 | private function camelToSnake( $s ) { 269 | 270 | return strtolower( preg_replace( [ '/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/' ], '$1_$2', $s ) ); 271 | } 272 | } 273 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/DeprecatedTagHooksSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 74 | 75 | if ( ! in_array( $tokens[ $stackPtr ]['content'], self::HOOK_FUNCTIONS, true ) ) { 76 | return; 77 | } 78 | 79 | $commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr ); 80 | 81 | if ( ! $commentEnd || $tokens[ $commentEnd ]['line'] !== $tokens[ $stackPtr ]['line'] - 1 ) { 82 | return; 83 | } 84 | 85 | $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $commentEnd ); 86 | $deprecated = $this->findTag( '@deprecated', $commentStart, $tokens ); 87 | $hookNamePtr = $phpcsFile->findNext( T_CONSTANT_ENCAPSED_STRING, $stackPtr + 1 ); 88 | $hookName = trim( $tokens[ $hookNamePtr ]['content'], '"\'' ); 89 | 90 | if ( $this->isDuplicateHook( $commentStart, $tokens ) ) { 91 | return; 92 | } 93 | 94 | $this->processTagPosition( $phpcsFile, $hookName, $stackPtr, $deprecated ); 95 | 96 | if ( empty( $deprecated ) ) { 97 | return; 98 | } 99 | 100 | $this->processVersion( $phpcsFile, $hookName, $deprecated ); 101 | $this->processLines( $phpcsFile, $hookName, $deprecated ); 102 | } 103 | 104 | /** 105 | * Check deprecated tag position. 106 | * 107 | * @since 1.0.0 108 | * 109 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 110 | * @param string $hookName Hook name. 111 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 112 | * @param array $deprecated Deprecated tag data. 113 | */ 114 | private function processTagPosition( $phpcsFile, $hookName, $stackPtr, $deprecated ) { 115 | 116 | $tokens = $phpcsFile->getTokens(); 117 | 118 | if ( ! empty( $deprecated ) && ! in_array( $tokens[ $stackPtr ]['content'], self::REQUIRED_DEPRECATED_FUNCTIONS, true ) ) { 119 | $phpcsFile->addError( 120 | sprintf( 121 | 'The @deprecated not allowed here. Use %s instead.', 122 | implode( '/', self::REQUIRED_DEPRECATED_FUNCTIONS ) 123 | ), 124 | $stackPtr, 125 | 'DeprecatedTagNotAllowed' 126 | ); 127 | 128 | return; 129 | } 130 | 131 | if ( ! empty( $deprecated ) || ! in_array( $tokens[ $stackPtr ]['content'], self::REQUIRED_DEPRECATED_FUNCTIONS, true ) ) { 132 | return; 133 | } 134 | 135 | $phpcsFile->addError( 136 | sprintf( 137 | 'The @deprecated tag is required for the %s hook.', 138 | $hookName 139 | ), 140 | $stackPtr, 141 | 'MissDeprecatedTag' 142 | ); 143 | } 144 | 145 | /** 146 | * Process version. 147 | * 148 | * @since 1.0.0 149 | * 150 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 151 | * @param string $hookName Hook name. 152 | * @param array $deprecated Deprecated tag data. 153 | */ 154 | private function processVersion( $phpcsFile, $hookName, $deprecated ) { 155 | 156 | $tokens = $phpcsFile->getTokens(); 157 | 158 | if ( ! $this->hasVersion( $deprecated, $tokens ) ) { 159 | $phpcsFile->addError( 160 | sprintf( 161 | 'Missing version for @deprecated tag in a comment for the %s hook.', 162 | $hookName 163 | ), 164 | $deprecated['tag'], 165 | 'MissDeprecatedVersion' 166 | ); 167 | 168 | return; 169 | } 170 | 171 | if ( $this->isValidVersion( $deprecated, $tokens ) ) { 172 | return; 173 | } 174 | 175 | $phpcsFile->addError( 176 | sprintf( 177 | 'Invalid version for @deprecated tag in a comment for the %s hook.', 178 | $hookName 179 | ), 180 | $deprecated['tag'], 181 | 'InvalidDeprecatedVersion' 182 | ); 183 | } 184 | 185 | /** 186 | * Process empty lines after tag. 187 | * 188 | * @since 1.0.0 189 | * 190 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 191 | * @param string $hookName Hook name. 192 | * @param array $deprecated Deprecated tag data. 193 | */ 194 | private function processLines( $phpcsFile, $hookName, $deprecated ) { 195 | 196 | if ( 197 | $this->isLastTag( $phpcsFile, $deprecated ) || 198 | $this->hasEmptyLineAfterInComment( $phpcsFile, $deprecated ) 199 | ) { 200 | return; 201 | } 202 | 203 | $phpcsFile->addError( 204 | sprintf( 205 | 'Add empty line after @deprecated tag for the %s hook.', 206 | $hookName 207 | ), 208 | $deprecated['tag'], 209 | 'MissingEmptyLineAfterDeprecated' 210 | ); 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/DeprecatedTagSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 54 | $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $stackPtr ); 55 | $deprecated = $this->findTag( '@deprecated', $commentStart, $tokens ); 56 | 57 | if ( empty( $deprecated ) ) { 58 | return; 59 | } 60 | 61 | if ( ! $this->hasVersion( $deprecated, $tokens ) ) { 62 | $phpcsFile->addError( 63 | sprintf( 64 | 'Missing version for @deprecated tag in a comment for the %s hook.', 65 | $tokens[ $stackPtr ]['content'] 66 | ), 67 | $deprecated['tag'], 68 | 'MissDeprecatedVersion' 69 | ); 70 | 71 | return; 72 | } 73 | 74 | if ( ! $this->isValidVersion( $deprecated, $tokens ) ) { 75 | $phpcsFile->addError( 76 | sprintf( 77 | 'Invalid version for @deprecated tag in a comment for %s.', 78 | $tokens[ $stackPtr ]['content'] 79 | ), 80 | $deprecated['tag'], 81 | 'InvalidDeprecatedVersion' 82 | ); 83 | 84 | return; 85 | } 86 | 87 | if ( 88 | ! $this->isLastTag( $phpcsFile, $deprecated ) && 89 | ! $this->hasEmptyLineAfterInComment( $phpcsFile, $deprecated ) 90 | ) { 91 | $phpcsFile->addError( 92 | sprintf( 93 | 'Add empty line after @deprecated tag for %s.', 94 | $this->getEntityFullName( $phpcsFile, $stackPtr, $tokens ) 95 | ), 96 | $deprecated['tag'], 97 | 'MissingEmptyLineAfterDeprecated' 98 | ); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/DescriptionStopSymbolPropertySniff.php: -------------------------------------------------------------------------------- 1 | numTokens + 1) to skip 31 | * the rest of the file. 32 | */ 33 | protected function processMemberVar( File $phpcsFile, $stackPtr ) { 34 | 35 | $tokens = $phpcsFile->getTokens(); 36 | $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $stackPtr ); 37 | $firstDescriptionLine = $this->findFirstDescriptionLine( $phpcsFile, $commentStart ); 38 | 39 | if ( $tokens[ $commentStart ]['line'] - $tokens[ $firstDescriptionLine ]['line'] === 0 ) { 40 | $phpcsFile->addError( 41 | sprintf( 42 | 'Move comment description for %s to the next line.', 43 | $tokens[ $stackPtr ]['content'] 44 | ), 45 | $commentStart, 46 | 'MissDescription' 47 | ); 48 | 49 | return; 50 | } 51 | 52 | $last = $this->findLastDescriptionLIne( $phpcsFile, $firstDescriptionLine, $tokens ); 53 | 54 | if ( ! $this->hasStopSymbol( $last, $tokens ) ) { 55 | $phpcsFile->addError( 56 | sprintf( 57 | 'Add a stop symbol for %s.', 58 | $tokens[ $stackPtr ]['content'] 59 | ), 60 | $last, 61 | 'AddStopSymbol' 62 | ); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/DescriptionStopSymbolSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 52 | $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $stackPtr ); 53 | 54 | if ( ! $commentStart ) { 55 | return; 56 | } 57 | 58 | $firstDescriptionLine = $this->findFirstDescriptionLine( $phpcsFile, $commentStart ); 59 | $entity = $this->getEntityFullName( $phpcsFile, $stackPtr, $tokens ); 60 | 61 | if ( $tokens[ $commentStart ]['line'] - $tokens[ $firstDescriptionLine ]['line'] === 0 ) { 62 | $phpcsFile->addError( 63 | sprintf( 64 | 'Move comment description for %s to the next line.', 65 | $entity 66 | ), 67 | $commentStart, 68 | 'MissDescription' 69 | ); 70 | 71 | return; 72 | } 73 | 74 | $last = $this->findLastDescriptionLIne( $phpcsFile, $firstDescriptionLine, $tokens ); 75 | 76 | if ( ! $this->hasStopSymbol( $last, $tokens ) ) { 77 | $phpcsFile->addError( 78 | sprintf( 79 | 'Add a stop symbol for %s.', 80 | $entity 81 | ), 82 | $last, 83 | 'AddStopSymbol' 84 | ); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/LanguageInjectionSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 44 | 45 | // Allow `// language=` language injection comment. 46 | $currentToken = $tokens[ $stackPtr ]; 47 | 48 | if ( $currentToken['code'] === T_COMMENT && strpos( $currentToken['content'], '// language=' ) === 0 ) { 49 | // Block 'Inline comments must end in full-stops, exclamation marks, or question marks' error. 50 | $phpcsFile->tokenizer->ignoredLines[ $currentToken['line'] ] = [ 51 | 'Squiz.Commenting.InlineComment.InvalidEndChar' => true, 52 | 'Squiz.Commenting.InlineComment.SpacingBefore' => true, 53 | ]; 54 | 55 | return; 56 | } 57 | 58 | if ( 59 | ! isset( $currentToken['comment_closer'] ) 60 | || ( 61 | $tokens[ $currentToken['comment_closer'] ]['content'] === '' 62 | && $currentToken['comment_closer'] === ( $phpcsFile->numTokens - 1 ) 63 | ) 64 | ) { 65 | return; // Don't process an unfinished comment during live coding. 66 | } 67 | 68 | $commentEnd = $currentToken['comment_closer']; 69 | 70 | $empty = [ 71 | T_DOC_COMMENT_WHITESPACE, 72 | T_DOC_COMMENT_STAR, 73 | ]; 74 | 75 | $short = $phpcsFile->findNext( $empty, ( $stackPtr + 1 ), $commentEnd, true ); 76 | 77 | // Allow `@lang` language injection comment. 78 | if ( $short && $tokens[ $short ]['code'] === T_DOC_COMMENT_TAG && $tokens[ $short ]['content'] === '@lang' ) { 79 | // Block 'Missing short description in doc comment' error. 80 | $phpcsFile->tokenizer->ignoredLines[ $tokens[ $short ]['line'] ] = [ 'Generic.Commenting.DocComment.MissingShort' => true ]; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/NoSpacesAfterParamTagSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 55 | $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $stackPtr ); 56 | $tag = $this->findTag( $this->tag, $commentStart, $tokens ); 57 | 58 | if ( empty( $tag ) ) { 59 | return; 60 | } 61 | 62 | // More than one space. 63 | if ( $tokens[ $tag['tag'] + 1 ]['length'] > 1 ) { 64 | $phpcsFile->addError( 65 | sprintf( 66 | 'Allows only 1 space after %s tag for %s() function.', 67 | $this->tag, 68 | $phpcsFile->getDeclarationName( $stackPtr ) 69 | ), 70 | $tag['tag'], 71 | 'OnlyOneSpaceCanBeUsed' 72 | ); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/NoSpacesAfterReturnTagSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 46 | 47 | if ( $tokens[ $stackPtr ]['content'] !== 'define' ) { 48 | return; 49 | } 50 | 51 | $commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr ); 52 | 53 | if ( ! $commentEnd || $tokens[ $commentEnd ]['line'] !== $tokens[ $stackPtr ]['line'] - 1 ) { 54 | $phpcsFile->addError( 55 | 'Add the PHPDoc for the define function.', 56 | $stackPtr, 57 | 'MissPHPDoc' 58 | ); 59 | 60 | return; 61 | } 62 | 63 | $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $commentEnd ); 64 | $shortDescription = $phpcsFile->findNext( [ T_DOC_COMMENT_TAG, T_DOC_COMMENT_STRING ], $commentStart, $commentEnd ); 65 | 66 | if ( empty( $shortDescription ) || $tokens[ $shortDescription ]['code'] === T_DOC_COMMENT_TAG ) { 67 | $phpcsFile->addError( 68 | 'Add the short description', 69 | $commentStart, 70 | 'MissShortDescription' 71 | ); 72 | 73 | return; 74 | } 75 | 76 | $last = $this->findLastDescriptionLIne( $phpcsFile, $shortDescription, $tokens ); 77 | 78 | if ( ! $this->hasStopSymbol( $last, $tokens ) ) { 79 | $phpcsFile->addError( 80 | 'Add a stop symbol for the short description.', 81 | $last, 82 | 'AddStopSymbol' 83 | ); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/PHPDocHooksSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 57 | 58 | if ( $tokens[ $stackPtr + 1 ]['code'] !== T_OPEN_PARENTHESIS || ! in_array( $tokens[ $stackPtr ]['content'], self::HOOK_FUNCTIONS, true ) ) { 59 | return; 60 | } 61 | 62 | $hookName = $this->getFirstArgument( $phpcsFile, $stackPtr ); 63 | $commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr - 1 ); 64 | 65 | if ( ! $commentEnd || $tokens[ $commentEnd ]['line'] !== $tokens[ $stackPtr ]['line'] - 1 ) { 66 | $phpcsFile->addError( 67 | sprintf( 68 | 'Missing PHPDoc for the %s hook', 69 | $hookName 70 | ), 71 | $stackPtr, 72 | 'RequiredHookDocumentation' 73 | ); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/ParamTagHooksSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 63 | 64 | if ( ! in_array( $tokens[ $stackPtr ]['content'], self::HOOK_FUNCTIONS, true ) ) { 65 | return; 66 | } 67 | 68 | $commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr ); 69 | 70 | if ( ! $commentEnd || $tokens[ $commentEnd ]['line'] !== $tokens[ $stackPtr ]['line'] - 1 ) { 71 | return; 72 | } 73 | 74 | $commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr ); 75 | $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $commentEnd ); 76 | 77 | if ( $this->isDuplicateHook( $commentStart, $tokens ) ) { 78 | return; 79 | } 80 | 81 | $params = $this->findTags( '@param', $commentStart, $tokens ); 82 | $argumentsQuantity = $this->countArguments( $phpcsFile, $stackPtr ); 83 | 84 | if ( count( $params ) !== $argumentsQuantity ) { 85 | $phpcsFile->addError( 86 | sprintf( 87 | 'You should have %d @param tags', 88 | $argumentsQuantity 89 | ), 90 | $stackPtr, 91 | 'InvalidParamTagsQuantity' 92 | ); 93 | 94 | return; 95 | } 96 | 97 | $this->processParams( $phpcsFile, $params ); 98 | } 99 | 100 | /** 101 | * Get arguments quantity. 102 | * 103 | * @since 1.0.0 104 | * 105 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 106 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 107 | * 108 | * @return int 109 | */ 110 | private function countArguments( $phpcsFile, $stackPtr ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh 111 | 112 | $tokens = $phpcsFile->getTokens(); 113 | $openParenthesis = $phpcsFile->findNext( [ T_OPEN_PARENTHESIS ], $stackPtr + 1 ); 114 | $lastPosition = $tokens[ $openParenthesis ]['parenthesis_closer'] - 1; 115 | $commaPtr = $phpcsFile->findNext( T_COMMA, $stackPtr + 1 ); 116 | 117 | if ( $commaPtr === false ) { 118 | return 0; 119 | } 120 | 121 | $currentPosition = $commaPtr + 1; 122 | $quantity = 0; 123 | $lookingForComma = false; 124 | 125 | while ( $currentPosition < $lastPosition ) { 126 | if ( $tokens[ $currentPosition ]['code'] === T_WHITESPACE ) { 127 | ++$currentPosition; 128 | continue; 129 | } 130 | 131 | if ( $tokens[ $currentPosition ]['code'] === T_COMMA ) { 132 | $lookingForComma = false; 133 | 134 | ++$currentPosition; 135 | continue; 136 | } 137 | 138 | if ( in_array( $tokens[ $currentPosition ]['code'], [ T_ARRAY, T_OPEN_SHORT_ARRAY, T_CLOSURE ], true ) ) { 139 | ++$quantity; 140 | } 141 | 142 | if ( $this->skip( $phpcsFile, $currentPosition ) ) { 143 | continue; 144 | } 145 | 146 | ++$currentPosition; 147 | 148 | if ( $lookingForComma ) { 149 | continue; 150 | } 151 | 152 | ++$quantity; 153 | 154 | $lookingForComma = true; 155 | } 156 | 157 | return $quantity; 158 | } 159 | 160 | /** 161 | * Skip some tokens. 162 | * 163 | * @since 1.0.3 164 | * 165 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 166 | * @param int $currentPosition Current position. 167 | * 168 | * @return bool 169 | */ 170 | private function skip( $phpcsFile, &$currentPosition ) { 171 | 172 | $skipTokens = [ 173 | 'parenthesis', 174 | 'bracket', 175 | 'scope', 176 | ]; 177 | 178 | $skip = false; 179 | 180 | $tokens = $phpcsFile->getTokens(); 181 | 182 | foreach ( $skipTokens as $skipToken ) { 183 | $opener = $skipToken . '_opener'; 184 | $closer = $skipToken . '_closer'; 185 | 186 | if ( isset( $tokens[ $currentPosition ][ $opener ] ) ) { 187 | $currentPosition = $tokens[ $currentPosition ][ $closer ] + 1; 188 | $skip = true; 189 | 190 | break; 191 | } 192 | } 193 | 194 | return $skip; 195 | } 196 | 197 | /** 198 | * Process params tag. 199 | * 200 | * @since 1.0.0 201 | * 202 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 203 | * @param array $params List of params tags. 204 | * 205 | * @return array 206 | */ 207 | private function processParams( $phpcsFile, $params ) { 208 | 209 | $typeLength = 0; 210 | $varLength = 0; 211 | 212 | foreach ( $params as $key => $param ) { 213 | $param = $this->processParamTag( $phpcsFile, $param ); 214 | $params[ $key ] = $param; 215 | $typeLength = max( $typeLength, strlen( $param['elements'][0] ) ); 216 | $varLength = max( $varLength, strlen( $param['elements'][0] ) + strlen( $param['elements'][1] ) ); 217 | } 218 | 219 | foreach ( $params as $param ) { 220 | if ( 221 | $typeLength !== strlen( $param['elements'][0] ) || 222 | $varLength !== strlen( $param['elements'][0] ) + strlen( $param['elements'][1] ) 223 | ) { 224 | $phpcsFile->addError( 225 | 'You should align the params types, variables, and short description', 226 | $param['tag'], 227 | 'InvalidAlign' 228 | ); 229 | } 230 | } 231 | 232 | return $params; 233 | } 234 | 235 | /** 236 | * Process the param tag. 237 | * 238 | * @since 1.0.0 239 | * 240 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 241 | * @param array $param List of params tags. 242 | * 243 | * @return array 244 | */ 245 | private function processParamTag( $phpcsFile, $param ) { 246 | 247 | $tokens = $phpcsFile->getTokens(); 248 | $commentString = $phpcsFile->findNext( T_DOC_COMMENT_STRING, $param['tag'] + 1 ); 249 | $param['elements'] = [ '', '', '' ]; 250 | 251 | if ( $tokens[ $commentString ]['line'] !== $param['line'] ) { 252 | $phpcsFile->addError( 253 | 'Missing type, variable, and short description', 254 | $param['tag'], 255 | 'MissParamInfo' 256 | ); 257 | 258 | return $param; 259 | } 260 | 261 | preg_match( '/([\w\s\[\]|]+)(\$[\w_]+\s+)(.*)/', $tokens[ $commentString ]['content'], $paramElements ); 262 | 263 | if ( empty( $paramElements[1] ) || empty( $paramElements[2] ) || empty( $paramElements[3] ) ) { 264 | $phpcsFile->addError( 265 | 'Missing type, variable, or short description', 266 | $param['tag'], 267 | 'MissParamInfo' 268 | ); 269 | 270 | return $param; 271 | } 272 | 273 | $param['elements'] = [ $paramElements[1], $paramElements[2], $paramElements[3] ]; 274 | 275 | if ( $tokens[ $param['tag'] + 1 ]['code'] === T_DOC_COMMENT_WHITESPACE && strlen( $tokens[ $param['tag'] + 1 ]['content'] ) > 1 ) { 276 | $phpcsFile->addError( 277 | 'Allow only 1 space after the @param tag.', 278 | $param['tag'], 279 | 'ExtraSpacesAfterParamTag' 280 | ); 281 | } 282 | 283 | $last = $this->findLastDescriptionLIne( $phpcsFile, $commentString, $tokens ); 284 | 285 | if ( ! $this->hasStopSymbol( $last, $tokens ) ) { 286 | $phpcsFile->addError( 287 | 'You should add a stop symbol for the short description.', 288 | $last, 289 | 'AddStopSymbol' 290 | ); 291 | } 292 | 293 | return $param; 294 | } 295 | } 296 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/ShortDescriptionHooksSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 62 | 63 | if ( $tokens[ $stackPtr + 1 ]['code'] !== T_OPEN_PARENTHESIS || ! in_array( $tokens[ $stackPtr ]['content'], self::HOOK_FUNCTIONS, true ) ) { 64 | return; 65 | } 66 | 67 | $commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr - 1 ); 68 | 69 | if ( ! $commentEnd || $tokens[ $commentEnd ]['line'] !== $tokens[ $stackPtr ]['line'] - 1 ) { 70 | return; 71 | } 72 | 73 | $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $commentEnd ); 74 | 75 | if ( $this->isDuplicateHook( $commentStart, $tokens ) ) { 76 | return; 77 | } 78 | 79 | $shortDescription = $phpcsFile->findNext( [ T_DOC_COMMENT_TAG, T_DOC_COMMENT_STRING ], $commentStart, $commentEnd ); 80 | 81 | if ( empty( $shortDescription ) || $tokens[ $shortDescription ]['code'] === T_DOC_COMMENT_TAG ) { 82 | $phpcsFile->addError( 83 | 'Add the short description', 84 | $commentStart, 85 | 'MissShortDescription' 86 | ); 87 | 88 | return; 89 | } 90 | 91 | $last = $this->findLastDescriptionLIne( $phpcsFile, $shortDescription, $tokens ); 92 | 93 | if ( ! $this->hasStopSymbol( $last, $tokens ) ) { 94 | $phpcsFile->addError( 95 | 'Add a stop symbol for the short description.', 96 | $last, 97 | 'AddStopSymbol' 98 | ); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/SinceTagDefineSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 50 | 51 | if ( $tokens[ $stackPtr ]['content'] !== 'define' ) { 52 | return; 53 | } 54 | 55 | $commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr ); 56 | 57 | if ( ! $commentEnd || $tokens[ $commentEnd ]['line'] !== $tokens[ $stackPtr ]['line'] - 1 ) { 58 | return; 59 | } 60 | 61 | $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $commentEnd ); 62 | $since = $this->findTag( '@since', $commentStart, $tokens ); 63 | 64 | if ( empty( $since ) ) { 65 | $phpcsFile->addError( 66 | 'Missing @since tag for the define function', 67 | $stackPtr, 68 | 'MissingSinceTag' 69 | ); 70 | 71 | return; 72 | } 73 | 74 | $this->processVersion( $phpcsFile, $since ); 75 | 76 | if ( $this->hasEmptyLineAfterInComment( $phpcsFile, $since ) ) { 77 | $phpcsFile->addError( 78 | 'Remove empty line after @since tag', 79 | $since['tag'], 80 | 'EmptyLineAfterSince' 81 | ); 82 | } 83 | } 84 | 85 | /** 86 | * Process version. 87 | * 88 | * @since 1.0.0 89 | * 90 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 91 | * @param array $since Since tag token. 92 | */ 93 | private function processVersion( $phpcsFile, $since ) { 94 | 95 | $tokens = $phpcsFile->getTokens(); 96 | 97 | if ( ! $this->hasVersion( $since, $tokens ) ) { 98 | $phpcsFile->addError( 99 | 'Version missing for @since tag in a comment for the define function', 100 | $since['tag'], 101 | 'MissingSinceVersion' 102 | ); 103 | 104 | return; 105 | } 106 | 107 | if ( ! $this->isValidVersion( $since, $tokens ) ) { 108 | $phpcsFile->addError( 109 | 'Invalid version for @since tag in a comment for the define hook.', 110 | $since['tag'], 111 | 'InvalidSinceVersion' 112 | ); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/SinceTagHooksSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 62 | 63 | if ( $tokens[ $stackPtr + 1 ]['code'] !== T_OPEN_PARENTHESIS || ! in_array( $tokens[ $stackPtr ]['content'], self::HOOK_FUNCTIONS, true ) ) { 64 | return; 65 | } 66 | 67 | $commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr - 1 ); 68 | $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, (int) $commentEnd ); 69 | 70 | if ( $this->isDuplicateHook( $commentStart, $tokens ) ) { 71 | return; 72 | } 73 | 74 | $hookNamePtr = $phpcsFile->findNext( T_CONSTANT_ENCAPSED_STRING, $stackPtr + 1 ); 75 | $hookName = trim( $tokens[ $hookNamePtr ]['content'], '"\'' ); 76 | $since = $this->findTag( '@since', $commentStart, $tokens ); 77 | 78 | if ( empty( $since ) ) { 79 | $phpcsFile->addError( 80 | sprintf( 81 | 'Missing @since tag for the %s hook', 82 | $hookName 83 | ), 84 | $stackPtr, 85 | 'MissingSinceTag' 86 | ); 87 | 88 | return; 89 | } 90 | 91 | $this->processVersion( $phpcsFile, $since, $hookName ); 92 | $this->lineBetweenTags( $phpcsFile, $stackPtr, $since ); 93 | } 94 | 95 | /** 96 | * Process version. 97 | * 98 | * @since 1.0.0 99 | * 100 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 101 | * @param array $since Since tag token. 102 | * @param string $hookName Hook name. 103 | */ 104 | private function processVersion( $phpcsFile, $since, $hookName ) { 105 | 106 | $tokens = $phpcsFile->getTokens(); 107 | 108 | if ( ! $this->hasVersion( $since, $tokens ) ) { 109 | $phpcsFile->addError( 110 | sprintf( 111 | 'Version missing for @since tag in a comment for the %s hook.', 112 | $hookName 113 | ), 114 | $since['tag'], 115 | 'MissingSinceVersion' 116 | ); 117 | 118 | return; 119 | } 120 | 121 | if ( ! $this->isValidVersion( $since, $tokens ) ) { 122 | $phpcsFile->addError( 123 | sprintf( 124 | 'Invalid version for @since tag in a comment for the %s hook.', 125 | $hookName 126 | ), 127 | $since['tag'], 128 | 'InvalidSinceVersion' 129 | ); 130 | } 131 | } 132 | 133 | /** 134 | * Processes and detect empty line between tags. 135 | * 136 | * @since 1.0.0 137 | * 138 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 139 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 140 | * @param array $since Since tag token. 141 | * 142 | * @return void 143 | */ 144 | private function lineBetweenTags( $phpcsFile, $stackPtr, $since ) { 145 | 146 | $tokens = $phpcsFile->getTokens(); 147 | $hookNamePtr = $phpcsFile->findNext( T_CONSTANT_ENCAPSED_STRING, $stackPtr + 1 ); 148 | $hookName = trim( $tokens[ $hookNamePtr ]['content'], '"\'' ); 149 | $nextAnnotation = $phpcsFile->findNext( T_DOC_COMMENT_TAG, $since['tag'] + 1 ); 150 | $commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr ); 151 | $nextAnnotation = $nextAnnotation && $tokens[ $commentEnd ]['line'] > $tokens[ $nextAnnotation ]['line'] ? $nextAnnotation : false; 152 | 153 | if ( ( $nextAnnotation && $tokens[ $nextAnnotation ]['content'] === '@deprecated' ) || $tokens[ $nextAnnotation ]['content'] === '@since' ) { 154 | if ( $this->hasEmptyLineAfterInComment( $phpcsFile, $since ) ) { 155 | $phpcsFile->addError( 156 | sprintf( 157 | 'Remove empty line between @since and @deprecated for the %s hook.', 158 | $hookName 159 | ), 160 | $since['tag'], 161 | 'EmptyLineBetweenSinceAndDeprecated' 162 | ); 163 | } 164 | 165 | return; 166 | } 167 | 168 | if ( 169 | ! $this->isLastTag( $phpcsFile, $since ) && 170 | ! $this->hasEmptyLineAfterInComment( $phpcsFile, $since ) 171 | ) { 172 | $phpcsFile->addError( 173 | sprintf( 174 | 'Add empty line after @since tag for the %s hook.', 175 | $hookName 176 | ), 177 | $since['tag'], 178 | 'MissingEmptyLineAfterSince' 179 | ); 180 | } 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/SinceTagPropertySniff.php: -------------------------------------------------------------------------------- 1 | numTokens + 1) to skip 31 | * the rest of the file. 32 | */ 33 | protected function processMemberVar( File $phpcsFile, $stackPtr ) { 34 | 35 | $tokens = $phpcsFile->getTokens(); 36 | $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $stackPtr ); 37 | 38 | if ( ! $commentStart ) { 39 | return; 40 | } 41 | 42 | $since = $this->findTag( '@since', $commentStart, $tokens ); 43 | 44 | if ( empty( $since ) ) { 45 | $phpcsFile->addError( 46 | sprintf( 47 | '@since tag missing for %s property.', 48 | $tokens[ $stackPtr ]['content'] 49 | ), 50 | $stackPtr, 51 | 'MissingPhpDoc' 52 | ); 53 | 54 | return; 55 | } 56 | 57 | if ( ! $this->hasVersion( $since, $tokens ) ) { 58 | $phpcsFile->addError( 59 | sprintf( 60 | 'Version missing for @since tag in a comment for %s property.', 61 | $tokens[ $stackPtr ]['content'] 62 | ), 63 | $since['tag'], 64 | 'MissingSinceVersion' 65 | ); 66 | 67 | return; 68 | } 69 | 70 | if ( ! $this->isValidVersion( $since, $tokens ) ) { 71 | $phpcsFile->addError( 72 | sprintf( 73 | 'Invalid version for @since tag in a comment for %s property.', 74 | $tokens[ $stackPtr ]['content'] 75 | ), 76 | $since['tag'], 77 | 'InvalidSinceVersion' 78 | ); 79 | 80 | return; 81 | } 82 | 83 | $this->lineBetweenTags( $phpcsFile, $stackPtr, $since ); 84 | } 85 | 86 | /** 87 | * Processes and detect empty line between tags. 88 | * 89 | * @since 1.0.0 90 | * 91 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 92 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 93 | * @param array $since Since tag token. 94 | * 95 | * @return void 96 | */ 97 | private function lineBetweenTags( $phpcsFile, $stackPtr, $since ) { 98 | 99 | $tokens = $phpcsFile->getTokens(); 100 | $nextAnnotation = $phpcsFile->findNext( T_DOC_COMMENT_TAG, $since['tag'] + 1 ); 101 | $commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr ); 102 | $nextAnnotation = $nextAnnotation && $tokens[ $commentEnd ]['line'] > $tokens[ $nextAnnotation ]['line'] ? $nextAnnotation : false; 103 | 104 | if ( ( $nextAnnotation && $tokens[ $nextAnnotation ]['content'] === '@deprecated' ) || $tokens[ $nextAnnotation ]['content'] === '@since' ) { 105 | if ( $this->hasEmptyLineAfterInComment( $phpcsFile, $since ) ) { 106 | $phpcsFile->addError( 107 | sprintf( 108 | 'Remove empty line between @since and @deprecated for %s property.', 109 | $tokens[ $stackPtr ]['content'] 110 | ), 111 | $since['tag'], 112 | 'EmptyLineBetweenSinceAndDeprecated' 113 | ); 114 | } 115 | 116 | return; 117 | } 118 | 119 | if ( 120 | ! $this->isLastTag( $phpcsFile, $since ) && 121 | ! $this->hasEmptyLineAfterInComment( $phpcsFile, $since ) 122 | ) { 123 | $phpcsFile->addError( 124 | sprintf( 125 | 'Add empty line after @since tag for %s property.', 126 | $tokens[ $stackPtr ]['content'] 127 | ), 128 | $since['tag'], 129 | 'MissingEmptyLineAfterSince' 130 | ); 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/SinceTagSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 54 | $commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $stackPtr ); 55 | 56 | if ( empty( $commentStart ) ) { 57 | return; 58 | } 59 | 60 | $since = $this->findTag( '@since', $commentStart, $tokens ); 61 | $entity = $this->getEntityFullName( $phpcsFile, $stackPtr, $tokens ); 62 | 63 | /* 64 | * @since is required. 65 | */ 66 | if ( empty( $since ) ) { 67 | $phpcsFile->addError( 68 | sprintf( 69 | '@since tag missing for %s.', 70 | $entity 71 | ), 72 | $stackPtr, 73 | 'MissingSince' 74 | ); 75 | 76 | return; 77 | } 78 | 79 | /* 80 | * @since should have a version number, basically an ordinary comment. 81 | */ 82 | if ( ! $this->hasVersion( $since, $tokens ) ) { 83 | $phpcsFile->addError( 84 | sprintf( 85 | 'Version missing for @since tag in a comment for %s.', 86 | $entity 87 | ), 88 | $since['tag'], 89 | 'MissingSinceVersion' 90 | ); 91 | 92 | return; 93 | } 94 | 95 | if ( ! $this->isValidVersion( $since, $tokens ) ) { 96 | $phpcsFile->addError( 97 | sprintf( 98 | 'Invalid version for @since tag in a comment for %s.', 99 | $entity 100 | ), 101 | $since['tag'], 102 | 'InvalidSinceVersion' 103 | ); 104 | 105 | return; 106 | } 107 | 108 | $this->lineBetweenTags( $phpcsFile, $stackPtr, $since ); 109 | } 110 | 111 | /** 112 | * Processes and detect empty line between tags. 113 | * 114 | * @since 1.0.0 115 | * 116 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 117 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 118 | * @param array $since Since tag token. 119 | * 120 | * @return void 121 | */ 122 | private function lineBetweenTags( $phpcsFile, $stackPtr, $since ) { 123 | 124 | $tokens = $phpcsFile->getTokens(); 125 | $entity = $this->getEntityFullName( $phpcsFile, $stackPtr, $tokens ); 126 | $nextAnnotation = $phpcsFile->findNext( T_DOC_COMMENT_TAG, $since['tag'] + 1 ); 127 | $commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr ); 128 | $nextAnnotation = $nextAnnotation && $tokens[ $commentEnd ]['line'] > $tokens[ $nextAnnotation ]['line'] ? $nextAnnotation : false; 129 | 130 | if ( 131 | ( $nextAnnotation && $tokens[ $nextAnnotation ]['content'] === '@deprecated' ) || 132 | $tokens[ $nextAnnotation ]['content'] === '@since' 133 | ) { 134 | if ( $this->hasEmptyLineAfterInComment( $phpcsFile, $since ) ) { 135 | $phpcsFile->addError( 136 | sprintf( 137 | 'Remove empty line between @since and @deprecated for %s.', 138 | $entity 139 | ), 140 | $since['tag'], 141 | 'EmptyLineBetweenSinceAndDeprecated' 142 | ); 143 | } 144 | 145 | return; 146 | } 147 | 148 | if ( 149 | ! $this->isLastTag( $phpcsFile, $since ) && 150 | ! $this->hasEmptyLineAfterInComment( $phpcsFile, $since ) 151 | ) { 152 | $phpcsFile->addError( 153 | sprintf( 154 | 'Add empty line after @since tag for %s.', 155 | $entity 156 | ), 157 | $since['tag'], 158 | 'MissingEmptyLineAfterSince' 159 | ); 160 | } 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Comments/TranslatorsSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 46 | $content = $tokens[ $stackPtr ]['content']; 47 | 48 | if ( 3 !== strpos( $content, 'translators' ) ) { 49 | return; 50 | } 51 | 52 | if ( 3 !== strpos( $content, 'translators:' ) ) { 53 | $phpcsFile->addError( 54 | 'You should add the colon after translators', 55 | $stackPtr, 56 | 'MissColon' 57 | ); 58 | 59 | return; 60 | } 61 | 62 | if ( $this->processShortDescription( $phpcsFile, $stackPtr ) ) { 63 | return; 64 | } 65 | 66 | if ( $content[1] !== '*' ) { 67 | $phpcsFile->addError( 68 | 'Use /* ... */ comments instead', 69 | $stackPtr, 70 | 'InvalidCommentTag' 71 | ); 72 | } 73 | } 74 | 75 | /** 76 | * Process a short description. 77 | * 78 | * @since 1.0.0 79 | * 80 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 81 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 82 | * 83 | * @return bool 84 | */ 85 | private function processShortDescription( $phpcsFile, $stackPtr ) { 86 | 87 | $tokens = $phpcsFile->getTokens(); 88 | $content = $tokens[ $stackPtr ]['content']; 89 | 90 | preg_match( '/translators:(.*)/', $content, $matches ); 91 | 92 | if ( empty( $matches[1] ) ) { 93 | $phpcsFile->addError( 94 | 'Add a short description', 95 | $stackPtr, 96 | 'MissShortDescription' 97 | ); 98 | 99 | return true; 100 | } 101 | 102 | $shortDescription = trim( preg_replace( '/\*\/$/', '', $matches[1] ) ); 103 | 104 | if ( empty( $shortDescription ) ) { 105 | $phpcsFile->addError( 106 | 'Add a short description', 107 | $stackPtr, 108 | 'MissShortDescription' 109 | ); 110 | 111 | return true; 112 | } 113 | 114 | if ( ! in_array( $shortDescription[ strlen( $shortDescription ) - 1 ], [ '.', '!', '?' ], true ) ) { 115 | $phpcsFile->addError( 116 | 'Add a stop symbol', 117 | $stackPtr, 118 | 'MissStopSymbol' 119 | ); 120 | 121 | return true; 122 | } 123 | 124 | return false; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Formatting/EmptyLineAfterAssigmentVariablesSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 42 | $firstOpenCurlyBracket = $phpcsFile->findNext( [ T_OPEN_CURLY_BRACKET ], $stackPtr + 1 ); 43 | 44 | // Skip default values for function/methods arguments. 45 | if ( $firstOpenCurlyBracket && $tokens[ $firstOpenCurlyBracket ]['line'] === $tokens[ $stackPtr ]['line'] ) { 46 | return; 47 | } 48 | 49 | // Detect the last ";" for detect the end of this operation for multiline expressions. 50 | $semicolon = $phpcsFile->findNext( [ T_SEMICOLON ], $stackPtr + 1 ); 51 | $nextAfterSemicolon = $phpcsFile->findNext( Tokens::$emptyTokens, $semicolon + 1, null, true ); 52 | 53 | // Skip conditions and loops. 54 | if ( $nextAfterSemicolon && $tokens[ $semicolon ]['line'] === $tokens[ $nextAfterSemicolon ]['line'] ) { 55 | return; 56 | } 57 | 58 | $nextLineTokens = $this->getTokenNextLine( $phpcsFile, $semicolon ); 59 | 60 | // If the next line is an empty line. 61 | if ( empty( $nextLineTokens ) ) { 62 | return; 63 | } 64 | 65 | if ( 66 | $this->isBreakInSwitch( $phpcsFile, $nextLineTokens[0] ) || 67 | in_array( $nextLineTokens[0]['code'], $this->getAllowedTokensAfterAssigment(), true ) 68 | ) { 69 | return; 70 | } 71 | 72 | $phpcsFile->addError( 73 | 'Add empty line after assigment statement.', 74 | $stackPtr, 75 | 'AddEmptyLine' 76 | ); 77 | } 78 | 79 | /** 80 | * Get the list of tokens that allowed in the next line after assigment. 81 | * 82 | * @since 1.0.0 83 | * 84 | * @return array 85 | */ 86 | private function getAllowedTokensAfterAssigment() { 87 | 88 | return array_merge( 89 | [ 90 | T_CLOSE_CURLY_BRACKET, 91 | T_CLOSE_TAG, 92 | ], 93 | Tokens::$phpcsCommentTokens 94 | ); 95 | } 96 | 97 | /** 98 | * Get tokens in the last line. 99 | * 100 | * @since 1.0.0 101 | * 102 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 103 | * @param int $semicolon Semicolon position. 104 | * 105 | * @return array 106 | */ 107 | private function getTokenNextLine( $phpcsFile, $semicolon ) { 108 | 109 | $tokens = $phpcsFile->getTokens(); 110 | $nextLine = $tokens[ $semicolon ]['line'] + 1; 111 | $nextLineTokens = []; 112 | $count = count( $tokens ); 113 | 114 | for ( $i = $semicolon; $i < $count; $i++ ) { 115 | if ( $tokens[ $i ]['line'] > $nextLine ) { 116 | break; 117 | } 118 | 119 | // Skip current line. 120 | if ( $tokens[ $i ]['line'] !== $nextLine || in_array( $tokens[ $i ]['code'], Tokens::$emptyTokens, true ) ) { 121 | continue; 122 | } 123 | 124 | if ( in_array( $tokens[ $i ]['code'], Tokens::$parenthesisOpeners, true ) ) { 125 | $nextLineTokens[] = $tokens[ $i ]; 126 | 127 | break; 128 | } 129 | 130 | // Skip if the next line is also an assignment statement. 131 | if ( in_array( $tokens[ $i ]['code'], Tokens::$assignmentTokens, true ) ) { 132 | return []; 133 | } 134 | 135 | $nextLineTokens[] = $tokens[ $i ]; 136 | } 137 | 138 | return $nextLineTokens; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Formatting/EmptyLineAfterFunctionDeclarationSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 44 | $openBracket = $phpcsFile->findNext( T_OPEN_CURLY_BRACKET, $stackPtr + 1 ); 45 | $firstLine = $phpcsFile->findNext( Tokens::$emptyTokens, $openBracket + 1, null, true ); 46 | 47 | if ( $tokens[ $firstLine ]['code'] === T_CLOSE_CURLY_BRACKET ) { 48 | return; 49 | } 50 | 51 | if ( $tokens [ $firstLine ]['code'] === T_CLOSE_TAG ) { 52 | $firstLine = $phpcsFile->findNext( Tokens::$emptyTokens, $firstLine + 1, null, true ); 53 | } 54 | 55 | if ( $tokens[ $firstLine ]['line'] - $tokens[ $openBracket ]['line'] > 1 ) { 56 | return; 57 | } 58 | 59 | $phpcsFile->addError( 60 | sprintf( 61 | 'Add empty line after %s() function declaration.', 62 | $phpcsFile->getDeclarationName( $stackPtr ) 63 | ), 64 | $stackPtr, 65 | 'AddEmptyLineAfterFunctionDeclaration' 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Formatting/EmptyLineBeforeReturnSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 44 | $previous = $phpcsFile->findPrevious( Tokens::$emptyTokens, $stackPtr - 1, null, true ); 45 | $statement = $phpcsFile->findStartOfStatement( $previous - 1, T_COLON ); 46 | $importantLineAfter = array_merge( [ T_FUNCTION, T_STATIC ], Tokens::$scopeModifiers ); 47 | 48 | // Don't allow empty line for statements with only return in a body. 49 | if ( 50 | $tokens[ $previous ]['code'] === T_OPEN_CURLY_BRACKET && 51 | ! in_array( $tokens[ $statement ]['code'], $importantLineAfter, true ) 52 | ) { 53 | $linesBeforeReturn = $phpcsFile->getTokensAsString( $previous + 1, $stackPtr - $previous - 1 ); 54 | $count = count( array_filter( array_map( 'trim', explode( "\n", $linesBeforeReturn ) ) ) ); 55 | 56 | if ( $tokens[ $stackPtr ]['line'] - $tokens[ $previous ]['line'] - $count > 1 ) { 57 | $phpcsFile->addError( 58 | sprintf( 59 | 'Remove empty line before return statement in %d line.', 60 | $tokens[ $stackPtr ]['line'] - 1 61 | ), 62 | $stackPtr, 63 | 'RemoveEmptyLineBeforeReturnStatement' 64 | ); 65 | } 66 | 67 | return; 68 | } 69 | 70 | if ( $tokens[ $stackPtr ]['line'] - $tokens[ $previous ]['line'] < 2 ) { 71 | $phpcsFile->addError( 72 | sprintf( 73 | 'Add empty line before return statement in %d line.', 74 | $tokens[ $stackPtr ]['line'] - 1 75 | ), 76 | $stackPtr, 77 | 'AddEmptyLineBeforeReturnStatement' 78 | ); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /WPForms/Sniffs/Formatting/SwitchSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 46 | 47 | if ( $tokens[ $stackPtr ]['code'] === T_SWITCH ) { 48 | $this->processSwitch( $phpcsFile, $stackPtr ); 49 | } 50 | 51 | if ( in_array( $tokens[ $stackPtr ]['code'], [ T_CASE, T_DEFAULT ], true ) ) { 52 | $this->processCase( $phpcsFile, $stackPtr ); 53 | } 54 | 55 | if ( $this->isBreakInSwitch( $phpcsFile, $tokens[ $stackPtr ] ) ) { 56 | $this->processBreak( $phpcsFile, $stackPtr ); 57 | } 58 | } 59 | 60 | /** 61 | * Process the switch element. 62 | * 63 | * @since 1.0.0 64 | * 65 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 66 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 67 | */ 68 | private function processSwitch( File $phpcsFile, $stackPtr ) { 69 | 70 | $tokens = $phpcsFile->getTokens(); 71 | $previous = $phpcsFile->findPrevious( [ T_WHITESPACE, T_COMMENT ], $stackPtr - 1, null, true ); 72 | 73 | if ( $previous === false || $tokens[ $previous ]['code'] === T_COMMENT ) { 74 | return; 75 | } 76 | 77 | if ( $this->lineDistance( $phpcsFile, $stackPtr, $previous ) === 1 ) { 78 | $this->addEmptyLineError( $phpcsFile, $stackPtr ); 79 | } 80 | 81 | $beforeClose = $phpcsFile->findPrevious( T_WHITESPACE, $tokens[ $stackPtr ]['scope_closer'] - 1, null, true ); 82 | 83 | if ( $this->lineDistance( $phpcsFile, $tokens[ $stackPtr ]['scope_closer'], $beforeClose ) !== 1 ) { 84 | $this->removeEmptyLineError( $phpcsFile, $tokens[ $stackPtr ]['scope_closer'] ); 85 | } 86 | 87 | $next = $phpcsFile->findNext( T_WHITESPACE, $tokens[ $stackPtr ]['scope_closer'] + 1, null, true ); 88 | 89 | if ( $next === false || ( $tokens[ $next ]['code'] === T_CLOSE_CURLY_BRACKET ) ) { 90 | return; 91 | } 92 | 93 | if ( $this->lineDistance( $phpcsFile, $next, $tokens[ $stackPtr ]['scope_closer'] ) > 1 ) { 94 | return; 95 | } 96 | 97 | $this->addEmptyLineError( $phpcsFile, $next ); 98 | } 99 | 100 | /** 101 | * Process the case element. 102 | * 103 | * @since 1.0.0 104 | * 105 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 106 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 107 | */ 108 | private function processCase( File $phpcsFile, $stackPtr ) { 109 | 110 | $tokens = $phpcsFile->getTokens(); 111 | $previous = $phpcsFile->findPrevious( 112 | [ 113 | T_WHITESPACE, 114 | T_COMMENT, 115 | T_DOC_COMMENT_OPEN_TAG, 116 | T_DOC_COMMENT_WHITESPACE, 117 | T_DOC_COMMENT_STAR, 118 | T_DOC_COMMENT_STRING, 119 | T_DOC_COMMENT_CLOSE_TAG, 120 | ], 121 | $stackPtr - 1, 122 | null, 123 | true 124 | ); 125 | $previousStatement = $phpcsFile->findFirstOnLine( [ T_SWITCH, T_CASE, T_DEFAULT, T_BREAK ], $previous ); 126 | 127 | if ( 128 | $previousStatement === false && 129 | $this->lineDistance( $phpcsFile, $stackPtr, $previous ) === 1 130 | ) { 131 | $this->addEmptyLineError( $phpcsFile, $stackPtr ); 132 | 133 | return; 134 | } 135 | 136 | if ( 137 | $tokens[ $previousStatement ]['code'] === T_BREAK && 138 | $this->lineDistance( $phpcsFile, $stackPtr, $previousStatement ) === 1 139 | ) { 140 | $this->addEmptyLineError( $phpcsFile, $stackPtr ); 141 | 142 | return; 143 | } 144 | 145 | if ( 146 | in_array( $tokens[ $previousStatement ]['code'], [ T_SWITCH, T_CASE, T_DEFAULT ], true ) && 147 | $this->lineDistance( $phpcsFile, $stackPtr, $previousStatement ) !== 1 148 | ) { 149 | $this->removeEmptyLineError( $phpcsFile, $stackPtr ); 150 | } 151 | } 152 | 153 | /** 154 | * Get distance in lines between tokens, ignoring comment lines. 155 | * 156 | * @since 1.0.4 157 | * 158 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 159 | * @param int $endPtr End token. 160 | * @param int $startPtr Start token. 161 | * 162 | * @return mixed 163 | */ 164 | private function lineDistance( File $phpcsFile, $endPtr, $startPtr ) { 165 | 166 | $tokens = $phpcsFile->getTokens(); 167 | 168 | $ptr = $startPtr + 1; 169 | 170 | $commentLines = []; 171 | 172 | while ( $ptr < $endPtr ) { 173 | if ( 174 | in_array( 175 | $tokens[ $ptr ]['code'], 176 | [ 177 | T_DOC_COMMENT_OPEN_TAG, 178 | T_DOC_COMMENT_WHITESPACE, 179 | T_DOC_COMMENT_STAR, 180 | T_DOC_COMMENT_STRING, 181 | T_DOC_COMMENT_CLOSE_TAG, 182 | ], 183 | true 184 | ) || 185 | ( 186 | $tokens[ $ptr ]['code'] === T_COMMENT && 187 | $phpcsFile->findFirstOnLine( [ T_WHITESPACE, T_COMMENT ], $ptr, true ) === false 188 | ) 189 | ) { 190 | $commentLines[] = $tokens[ $ptr ]['line']; 191 | } 192 | 193 | ++$ptr; 194 | } 195 | 196 | return max( 197 | 0, 198 | $tokens[ $endPtr ]['line'] - $tokens[ $startPtr ]['line'] - count( array_unique( $commentLines ) ) 199 | ); 200 | } 201 | 202 | /** 203 | * Process the break element. 204 | * 205 | * @since 1.0.0 206 | * 207 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 208 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 209 | */ 210 | private function processBreak( File $phpcsFile, $stackPtr ) { 211 | 212 | $tokens = $phpcsFile->getTokens(); 213 | $previous = $phpcsFile->findPrevious( T_WHITESPACE, $stackPtr - 1, null, true ); 214 | 215 | if ( $tokens[ $previous ]['code'] === T_OPEN_CURLY_BRACKET ) { 216 | return; 217 | } 218 | 219 | $previousStatement = $phpcsFile->findFirstOnLine( [ T_CASE, T_DEFAULT ], $previous ); 220 | 221 | if ( empty( $previousStatement ) && $tokens[ $stackPtr ]['line'] - $tokens[ $previous ]['line'] !== 1 ) { 222 | $this->removeEmptyLineError( $phpcsFile, $stackPtr ); 223 | } 224 | } 225 | 226 | /** 227 | * Add error to add an empty line. 228 | * 229 | * @since 1.0.0 230 | * 231 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 232 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 233 | */ 234 | private function addEmptyLineError( $phpcsFile, $stackPtr ) { 235 | 236 | $phpcsFile->addError( 237 | 'You should add an empty line before', 238 | $stackPtr, 239 | 'AddEmptyLineBefore' 240 | ); 241 | } 242 | 243 | /** 244 | * Add error to remove an empty line. 245 | * 246 | * @since 1.0.0 247 | * 248 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 249 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 250 | */ 251 | private function removeEmptyLineError( $phpcsFile, $stackPtr ) { 252 | 253 | $phpcsFile->addError( 254 | 'You should remove an empty line before', 255 | $stackPtr, 256 | 'RemoveEmptyLineBefore' 257 | ); 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /WPForms/Sniffs/PHP/BackSlashSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 44 | 45 | if ( $tokens[ $stackPtr ]['code'] === T_DOC_COMMENT_STRING ) { 46 | $this->processComments( $phpcsFile, $stackPtr ); 47 | 48 | return; 49 | } 50 | 51 | $this->processCode( $phpcsFile, $stackPtr ); 52 | } 53 | 54 | /** 55 | * Process code. 56 | * 57 | * @since 1.0.0 58 | * 59 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 60 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 61 | */ 62 | private function processCode( $phpcsFile, $stackPtr ) { 63 | 64 | $tokens = $phpcsFile->getTokens(); 65 | 66 | if ( ! in_array( $tokens[ $stackPtr + 1 ]['code'], [ T_OPEN_PARENTHESIS, T_DOUBLE_COLON ], true ) ) { 67 | return; 68 | } 69 | 70 | if ( $tokens[ $stackPtr - 1 ]['code'] !== T_NS_SEPARATOR ) { 71 | return; 72 | } 73 | 74 | $startPtr = $phpcsFile->findPrevious( [ T_STRING, T_NS_SEPARATOR ], $stackPtr - 1, null, true ); 75 | 76 | if ( $startPtr === false ) { 77 | return; 78 | } 79 | 80 | ++$startPtr; 81 | 82 | if ( $tokens[ $startPtr ]['code'] !== T_NS_SEPARATOR ) { 83 | return; 84 | } 85 | 86 | $name = $phpcsFile->getTokensAsString( $startPtr, $stackPtr - $startPtr + 1 ); 87 | $count = substr_count( $name, '\\' ); 88 | 89 | if ( $count === 1 ) { 90 | $this->removeBackslashMessage( $phpcsFile, $stackPtr ); 91 | 92 | return; 93 | } 94 | 95 | $this->useShortSyntaxMessage( $phpcsFile, $stackPtr ); 96 | } 97 | 98 | /** 99 | * Process comments. 100 | * 101 | * @since 1.0.0 102 | * 103 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 104 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 105 | */ 106 | private function processComments( $phpcsFile, $stackPtr ) { 107 | 108 | $tokens = $phpcsFile->getTokens(); 109 | 110 | if ( $tokens[ $stackPtr - 2 ]['code'] !== T_DOC_COMMENT_TAG ) { 111 | return; 112 | } 113 | 114 | if ( preg_match( '~^[\\\]\w+[\\\]~', $tokens[ $stackPtr ]['content'] ) ) { 115 | $this->useShortSyntaxMessage( $phpcsFile, $stackPtr ); 116 | 117 | return; 118 | } 119 | 120 | if ( preg_match( '~^[\\\]\w+~', $tokens[ $stackPtr ]['content'] ) ) { 121 | $this->removeBackslashMessage( $phpcsFile, $stackPtr ); 122 | } 123 | } 124 | 125 | /** 126 | * Remove the backslash message. 127 | * 128 | * @since 1.0.0 129 | * 130 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 131 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 132 | */ 133 | private function removeBackslashMessage( $phpcsFile, $stackPtr ) { 134 | 135 | $phpcsFile->addError( 136 | 'Remove unnecessary backslash', 137 | $stackPtr, 138 | 'RemoveBackslash' 139 | ); 140 | } 141 | 142 | /** 143 | * Use short syntax instead of full function/object/class name. 144 | * 145 | * @since 1.0.0 146 | * 147 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 148 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 149 | */ 150 | private function useShortSyntaxMessage( $phpcsFile, $stackPtr ) { 151 | 152 | $phpcsFile->addError( 153 | 'We prefer imports with `use` statement instead of fully qualified names.', 154 | $stackPtr, 155 | 'UseShortSyntax' 156 | ); 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /WPForms/Sniffs/PHP/ConditionsYodaDisableSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 47 | $beforeCompare = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); 48 | $afterCompare = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); 49 | 50 | if ( in_array( $tokens[ $beforeCompare ]['code'], [ T_VARIABLE, T_CLOSE_SQUARE_BRACKET ], true ) ) { 51 | return; 52 | } 53 | 54 | // Skip if after not variable. 55 | if ( $tokens[ $afterCompare ]['code'] !== T_VARIABLE ) { 56 | return; 57 | } 58 | 59 | // Skip if before method. 60 | if ( $tokens[ $beforeCompare ]['code'] === T_CLOSE_PARENTHESIS ) { 61 | $openParenthesis = $phpcsFile->findPrevious( T_OPEN_PARENTHESIS, $beforeCompare - 1 ); 62 | $name = $phpcsFile->findPrevious( Tokens::$emptyTokens, $openParenthesis - 1, null, true ); 63 | 64 | if ( $tokens[ $name ]['code'] === T_STRING ) { 65 | return; 66 | } 67 | } 68 | 69 | // Allow properties. 70 | if ( $tokens[ $beforeCompare ]['code'] === T_STRING && $tokens[ $beforeCompare - 1 ]['code'] === T_OBJECT_OPERATOR ) { 71 | return; 72 | } 73 | 74 | $phpcsFile->addError( 'Remove Yoda Condition, it is annoying us.', $stackPtr, 'YodaRemove' ); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /WPForms/Sniffs/PHP/HooksMethodSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 62 | 63 | if ( ! in_array( $tokens[ $stackPtr ]['content'], self::ADD_HOOKS_FUNCTIONS, true ) ) { 64 | return; 65 | } 66 | 67 | if ( ! $this->getFullyQualifiedClassName( $phpcsFile ) ) { 68 | return; 69 | } 70 | 71 | $previous = $phpcsFile->findPrevious( T_FUNCTION, $stackPtr ); 72 | 73 | if ( $previous === false ) { 74 | return; 75 | } 76 | 77 | $function = $phpcsFile->findNext( T_STRING, $previous ); 78 | 79 | if ( $function === false ) { 80 | return; 81 | } 82 | 83 | if ( $tokens[ $function ]['content'] === self::METHOD_NAME ) { 84 | return; 85 | } 86 | 87 | $phpcsFile->addError( 88 | 'Hooks can only be added in the `hooks` method', 89 | $function, 90 | 'InvalidPlaceForAddingHooks' 91 | ); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /WPForms/Sniffs/PHP/UseStatementSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 43 | 44 | if ( $tokens[ $stackPtr ]['level'] !== 0 ) { 45 | return; 46 | } 47 | 48 | $entity = $phpcsFile->findPrevious( T_STRING, $phpcsFile->findNext( T_SEMICOLON, $stackPtr ) ); 49 | 50 | if ( $this->hasEntity( $phpcsFile, $entity ) ) { 51 | return; 52 | } 53 | 54 | if ( $this->hasEntityInDoc( $phpcsFile, $entity ) ) { 55 | return; 56 | } 57 | 58 | $phpcsFile->addError( 59 | 'Remove unneeded `use` statement', 60 | $stackPtr, 61 | 'UnusedUseStatement' 62 | ); 63 | } 64 | 65 | /** 66 | * Find function/objects/class with namespace in the code. 67 | * 68 | * @since 1.0.0 69 | * 70 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 71 | * @param int $entity Function/objects/class position that have namespace. 72 | * 73 | * @return bool 74 | */ 75 | private function hasEntity( $phpcsFile, $entity ) { 76 | 77 | $tokens = $phpcsFile->getTokens(); 78 | $element = $phpcsFile->findNext( T_STRING, $entity + 1, null, false, $tokens[ $entity ]['content'] ); 79 | 80 | if ( ! $element ) { 81 | return false; 82 | } 83 | 84 | if ( $tokens[ $element ]['level'] === 0 && $tokens[ $element + 1 ]['code'] === T_SEMICOLON ) { 85 | return $this->hasEntity( $phpcsFile, $element ); 86 | } 87 | 88 | return true; 89 | } 90 | 91 | /** 92 | * Find function/objects/class with namespace in the PHPDoc. 93 | * 94 | * @since 1.0.0 95 | * 96 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 97 | * @param int $entity Function/objects/class position that have namespace. 98 | * 99 | * @return bool 100 | */ 101 | private function hasEntityInDoc( $phpcsFile, $entity ) { 102 | 103 | $tokens = $phpcsFile->getTokens(); 104 | $entityName = $tokens[ $entity ]['content']; 105 | $element = $phpcsFile->findNext( T_DOC_COMMENT_STRING, $entity + 1, null, false, $entityName ); 106 | 107 | if ( ! empty( $element ) ) { 108 | return true; 109 | } 110 | 111 | return $this->findInParamsDescription( $phpcsFile, $entityName, $entity ); 112 | } 113 | 114 | /** 115 | * Find function/objects/class with namespace in the PHPDoc. 116 | * 117 | * @since 1.0.0 118 | * 119 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 120 | * @param string $entityName Function/objects/class name. 121 | * @param int $element Last search position. 122 | * 123 | * @return bool 124 | */ 125 | private function findInParamsDescription( $phpcsFile, $entityName, $element ) { 126 | 127 | $tokens = $phpcsFile->getTokens(); 128 | $nextElement = $phpcsFile->findNext( T_DOC_COMMENT_TAG, $element + 1 ); 129 | 130 | if ( empty( $nextElement ) ) { 131 | return false; 132 | } 133 | 134 | if ( $this->findInThrows( $phpcsFile, $entityName, $nextElement ) ) { 135 | return true; 136 | } 137 | 138 | if ( $tokens[ $nextElement ]['content'] !== '@param' ) { 139 | return $this->findInParamsDescription( $phpcsFile, $entityName, $nextElement ); 140 | } 141 | 142 | $paramDescription = $nextElement + 2; 143 | 144 | if ( $tokens[ $paramDescription ]['code'] !== T_DOC_COMMENT_STRING ) { 145 | return $this->findInParamsDescription( $phpcsFile, $entityName, $nextElement ); 146 | } 147 | 148 | if ( strpos( $tokens[ $paramDescription ]['content'], $entityName ) === 0 ) { 149 | return true; 150 | } 151 | 152 | return $this->findInParamsDescription( $phpcsFile, $entityName, $nextElement ); 153 | } 154 | 155 | /** 156 | * Find function/objects/class in the PHPDoc @throws. 157 | * 158 | * @since 1.0.0 159 | * 160 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 161 | * @param string $entityName Function/objects/class name. 162 | * @param int $stackPtr Current search position. 163 | * 164 | * @return bool 165 | */ 166 | private function findInThrows( $phpcsFile, $entityName, $stackPtr ) { 167 | 168 | $tokens = $phpcsFile->getTokens(); 169 | 170 | if ( $tokens[ $stackPtr ]['content'] === '@throws' ) { 171 | $closePtr = $phpcsFile->findNext( T_DOC_COMMENT_CLOSE_TAG, $stackPtr + 1 ); 172 | $commentPtr = $phpcsFile->findNext( T_DOC_COMMENT_STRING, $stackPtr + 1, $closePtr ); 173 | 174 | if ( $commentPtr && $entityName === explode( ' ', $tokens[ $commentPtr ]['content'], 2 )[0] ) { 175 | return true; 176 | } 177 | } 178 | 179 | return false; 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /WPForms/Sniffs/PHP/ValidateDomainSniff.php: -------------------------------------------------------------------------------- 1 | 51 | * 52 | * 53 | * 54 | * 55 | * . 56 | * 57 | * @since 1.0.0 58 | * 59 | * @param string $name Property name. 60 | * @param mixed $value Value. 61 | * 62 | * @noinspection MagicMethodsValidityInspection 63 | */ 64 | public function __set( $name, $value ) { 65 | 66 | $value = explode( ',', $this->normalizeFilename( $value ) ); 67 | 68 | $this->domains[ strtolower( $name ) ] = $value; 69 | } 70 | 71 | /** 72 | * Returns an array of tokens this test wants to listen for. 73 | * 74 | * @since 1.0.0 75 | * 76 | * @return array 77 | */ 78 | public function register() { 79 | 80 | return [ 81 | T_STRING, 82 | ]; 83 | } 84 | 85 | /** 86 | * Process this test when one of its tokens is encountered. 87 | * 88 | * @since 1.0.0 89 | * 90 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 91 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 92 | * 93 | * @return void 94 | */ 95 | public function process( File $phpcsFile, $stackPtr ) { 96 | 97 | $tokens = $phpcsFile->getTokens(); 98 | 99 | if ( $tokens[ $stackPtr + 1 ]['code'] !== T_OPEN_PARENTHESIS || ! in_array( $tokens[ $stackPtr ]['content'], self::TRANSLATE_FUNCTIONS, true ) ) { 100 | return; 101 | } 102 | 103 | $currentDomain = $this->getCurrentDomain( $phpcsFile, $stackPtr ); 104 | $expectedDomain = $this->getExpectedDomain( $phpcsFile ); 105 | 106 | if ( $currentDomain === false ) { 107 | $phpcsFile->addError( 108 | 'Domain name must be string.', 109 | $stackPtr, 110 | 'NotStringDomain' 111 | ); 112 | 113 | return; 114 | } 115 | 116 | if ( ! $currentDomain || ! $expectedDomain ) { 117 | return; 118 | } 119 | 120 | if ( $currentDomain === $expectedDomain ) { 121 | return; 122 | } 123 | 124 | $phpcsFile->addError( 125 | sprintf( 126 | "You are using invalid domain name. Use '%s' instead of '%s'.", 127 | $expectedDomain, 128 | $currentDomain 129 | ), 130 | $stackPtr, 131 | 'InvalidDomain' 132 | ); 133 | } 134 | 135 | /** 136 | * Get current domain. 137 | * 138 | * @since 1.0.0 139 | * 140 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 141 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. 142 | * 143 | * @return string|false 144 | */ 145 | private function getCurrentDomain( $phpcsFile, $stackPtr ) { 146 | 147 | $tokens = $phpcsFile->getTokens(); 148 | $openPtr = $phpcsFile->findNext( T_OPEN_PARENTHESIS, $stackPtr ); 149 | $closePtr = $tokens[ $openPtr ]['parenthesis_closer']; 150 | $commaPtr = $phpcsFile->findPrevious( T_COMMA, $closePtr, $stackPtr ); 151 | 152 | if ( ! $commaPtr ) { 153 | return ''; 154 | } 155 | 156 | // Find anything except string and whitespace. 157 | $lastArgument = $phpcsFile->findNext( [ T_CONSTANT_ENCAPSED_STRING, T_WHITESPACE ], $commaPtr + 1, $closePtr, true ); 158 | 159 | // The last argument is not a string, but something else. 160 | if ( $lastArgument ) { 161 | return false; 162 | } 163 | 164 | $lastArgument = $phpcsFile->findNext( T_CONSTANT_ENCAPSED_STRING, $commaPtr + 1, $closePtr ); 165 | 166 | if ( ! $lastArgument ) { 167 | return ''; 168 | } 169 | 170 | return strtolower( 171 | preg_replace( '/[\'\"]/', '', $tokens [ $lastArgument ]['content'] ) 172 | ); 173 | } 174 | 175 | /** 176 | * Get domain that should be used for the file. 177 | * 178 | * @since 1.0.0 179 | * 180 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 181 | * 182 | * @return string 183 | */ 184 | private function getExpectedDomain( $phpcsFile ) { 185 | 186 | $filePath = $this->getRelativePath( $phpcsFile ); 187 | $root = $this->getRootDirectory( $phpcsFile ); 188 | 189 | if ( ! empty( $this->domains ) ) { 190 | $currentDomain = $this->findDomainByProperty( $filePath ); 191 | } 192 | 193 | if ( ! empty( $currentDomain ) ) { 194 | return strtolower( $currentDomain ); 195 | } 196 | 197 | $basename = basename( $root ); 198 | 199 | if ( ! Config::getConfigData( 'multi_domains' ) ) { 200 | return $basename; 201 | } 202 | 203 | preg_match( '/[\w.-]+/', dirname( $filePath ), $domain ); 204 | 205 | return ! empty( $domain[0] ) ? strtolower( $domain[0] ) : $basename; 206 | } 207 | 208 | /** 209 | * Get domain by properties from ruleset.xml. 210 | * 211 | * @since 1.0.0 212 | * 213 | * @param string $filePath File path. 214 | * 215 | * @return string 216 | */ 217 | private function findDomainByProperty( $filePath ) { 218 | 219 | $fileDir = DIRECTORY_SEPARATOR . trim( dirname( $filePath ), DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR; 220 | $currentDomain = ''; 221 | $currentPath = ''; 222 | 223 | foreach ( $this->domains as $domain => $paths ) { 224 | foreach ( $paths as $path ) { 225 | $pathDir = DIRECTORY_SEPARATOR . trim( $this->normalizePath( $path ), DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR; 226 | 227 | if ( 228 | 0 === strpos( $fileDir, $pathDir ) && 229 | strlen( $path ) > strlen( $currentPath ) 230 | ) { 231 | $currentDomain = $domain; 232 | $currentPath = $path; 233 | } 234 | } 235 | } 236 | 237 | return $currentDomain; 238 | } 239 | 240 | /** 241 | * Get the normalized path, like realpath() for a non-existing path or file. 242 | * 243 | * @since 1.0.5 244 | * 245 | * @param string $path Path to be normalized. 246 | * 247 | * @return string 248 | */ 249 | private function normalizePath( $path ) { 250 | 251 | return (string) array_reduce( 252 | explode( DIRECTORY_SEPARATOR, $path ), 253 | static function ( $a, $b ) { 254 | if ( $a === null ) { 255 | $a = DIRECTORY_SEPARATOR; 256 | } 257 | if ( $b === '' || $b === '.' ) { 258 | return $a; 259 | } 260 | if ( $b === '..' ) { 261 | return dirname( $a ); 262 | } 263 | 264 | $sep = DIRECTORY_SEPARATOR; 265 | $escSep = '\\' . $sep; 266 | $pattern = "/$escSep+/"; 267 | 268 | return (string) preg_replace( $pattern, DIRECTORY_SEPARATOR, "$a$sep$b" ); 269 | } 270 | ); 271 | } 272 | } 273 | -------------------------------------------------------------------------------- /WPForms/Sniffs/PHP/ValidateHooksSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 55 | 56 | if ( $tokens[ $stackPtr + 1 ]['code'] !== T_OPEN_PARENTHESIS || ! in_array( $tokens[ $stackPtr ]['content'], self::HOOK_FUNCTIONS, true ) ) { 57 | return; 58 | } 59 | 60 | $hookName = $this->getFirstArgument( $phpcsFile, $stackPtr ); 61 | $expectedName = $this->getFullyQualifiedClassName( $phpcsFile ); 62 | 63 | if ( ! $expectedName || 0 === strpos( $hookName, $expectedName ) ) { 64 | return; 65 | } 66 | 67 | $phpcsFile->addError( 68 | sprintf( 69 | 'The `%s` is invalid hook name. The hook name should start with `%s`.', 70 | $hookName, 71 | $expectedName 72 | ), 73 | $stackPtr, 74 | 'InvalidHookName' 75 | ); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /WPForms/Sniffs/PropertyBaseSniff.php: -------------------------------------------------------------------------------- 1 | numTokens + 1) to skip 26 | * the rest of the file. 27 | */ 28 | protected function processVariable( File $phpcsFile, $stackPtr ) { 29 | } 30 | 31 | /** 32 | * Called to process variables found in double-quoted strings or heredocs. 33 | * 34 | * Note that there may be more than one variable in the string, which will 35 | * result only in one call for the string or one call per line for heredocs. 36 | * 37 | * @since 1.0.0 38 | * 39 | * @param File $phpcsFile The PHP_CodeSniffer file where this token was found. 40 | * @param int $stackPtr The position where the double-quoted string was found. 41 | * 42 | * @return void Optionally returns a stack pointer. The sniff will not be 43 | * called again on the current file until the returned stack 44 | * pointer is reached. Return ($phpcsFile->numTokens + 1) to skip 45 | * the rest of the file. 46 | */ 47 | protected function processVariableInString( File $phpcsFile, $stackPtr ) { 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /WPForms/Traits/CommentTag.php: -------------------------------------------------------------------------------- 1 | getTokens(); 82 | 83 | $star = $phpcsFile->findNext( T_DOC_COMMENT_STAR, $tag['tag'] ); 84 | 85 | if ( ! $star ) { 86 | return false; 87 | } 88 | 89 | if ( $tokens[ $star ]['line'] !== $tag['line'] + 1 ) { 90 | return false; 91 | } 92 | 93 | return $tokens[ $star ]['code'] === T_DOC_COMMENT_STAR && $tokens[ $star + 1 ]['code'] === T_DOC_COMMENT_WHITESPACE && $tokens[ $star + 2 ]['code'] === T_DOC_COMMENT_WHITESPACE; 94 | } 95 | 96 | /** 97 | * Is last tag. 98 | * 99 | * @since 1.0.0 100 | * 101 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 102 | * @param array $tag Tag information. 103 | * 104 | * @return bool 105 | */ 106 | protected function isLastTag( $phpcsFile, $tag ) { 107 | 108 | $tokens = $phpcsFile->getTokens(); 109 | $closeComment = $phpcsFile->findNext( T_DOC_COMMENT_CLOSE_TAG, $tag['tag'] ); 110 | 111 | return $tag['line'] === $tokens[ $closeComment ]['line'] - 1; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /WPForms/Traits/Description.php: -------------------------------------------------------------------------------- 1 | findNext( [ T_DOC_COMMENT_WHITESPACE, T_DOC_COMMENT_STAR ], $commentStart + 1, null, true ); 27 | } 28 | 29 | /** 30 | * Find last line in description. 31 | * 32 | * @since 1.0.0 33 | * 34 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. 35 | * @param int $firstDescriptionLine Position of first description line. 36 | * @param array $tokens Token stack for this file. 37 | * 38 | * @return int 39 | */ 40 | protected function findLastDescriptionLIne( $phpcsFile, $firstDescriptionLine, $tokens ) { 41 | 42 | $lastDescriptionLine = $firstDescriptionLine; 43 | 44 | do { 45 | $last = $phpcsFile->findNext( [ T_DOC_COMMENT_WHITESPACE, T_DOC_COMMENT_STAR ], $lastDescriptionLine + 1, null, true ); 46 | 47 | if ( 48 | $tokens[ $last ]['line'] - $tokens[ $lastDescriptionLine ]['line'] !== 1 || 49 | $tokens[ $last ]['code'] === T_DOC_COMMENT_TAG || 50 | $tokens[ $last ]['code'] === T_DOC_COMMENT_CLOSE_TAG 51 | ) { 52 | return $lastDescriptionLine; 53 | } 54 | $lastDescriptionLine = $last; 55 | } while ( $last ); 56 | 57 | return $lastDescriptionLine; 58 | } 59 | 60 | /** 61 | * The line has a stop symbol. 62 | * 63 | * @since 1.0.0 64 | * 65 | * @param int $last Position of last line. 66 | * @param array $tokens Token stack for this file. 67 | * 68 | * @return bool 69 | */ 70 | protected function hasStopSymbol( $last, $tokens ) { 71 | 72 | $lastSymbol = $tokens[ $last ]['content'][ strlen( $tokens[ $last ]['content'] ) - 1 ]; 73 | 74 | return in_array( $lastSymbol, [ '.', '!', '?' ], true ); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /WPForms/Traits/DuplicateHook.php: -------------------------------------------------------------------------------- 1 | findTag( '@see', $commentStart, $tokens ); 29 | 30 | if ( $see && $commentEnd && ( $see['tag'] < $commentEnd ) ) { 31 | $commentStringPtr = $see['tag'] + 2; 32 | } else { 33 | $commentStringPtr = $commentStart + 2; 34 | 35 | if ( $tokens[ $commentStart ]['line'] !== $tokens[ $commentEnd ]['line'] ) { 36 | return false; 37 | } 38 | } 39 | 40 | $content = $tokens[ $commentStringPtr ]['content']; 41 | 42 | if ( $tokens[ $commentStringPtr ]['code'] !== T_DOC_COMMENT_STRING ) { 43 | return false; 44 | } 45 | 46 | return ( 47 | 0 === strpos( $content, 'This action is documented in ' ) || 48 | 0 === strpos( $content, 'This filter is documented in ' ) 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /WPForms/Traits/GetEntityName.php: -------------------------------------------------------------------------------- 1 | getSuffix( $tokens[ $stackPtr ]['code'] ); 28 | 29 | if ( $tokens[ $stackPtr ]['code'] === T_CONST ) { 30 | return $tokens[ $stackPtr + 2 ]['content'] . $suffix; 31 | } 32 | 33 | return $phpcsFile->getDeclarationName( $stackPtr ) . $suffix; 34 | } 35 | 36 | /** 37 | * Get element suffix. 38 | * 39 | * @since 1.0.0 40 | * 41 | * @param int $code Code for current element. 42 | * 43 | * @return string 44 | */ 45 | private function getSuffix( $code ) { 46 | 47 | if ( $code === T_FUNCTION ) { 48 | return '() function'; 49 | } 50 | 51 | if ( $code === T_CLASS ) { 52 | return ' class'; 53 | } 54 | 55 | if ( $code === T_INTERFACE ) { 56 | return ' interface'; 57 | } 58 | 59 | if ( $code === T_TRAIT ) { 60 | return ' trait'; 61 | } 62 | 63 | if ( $code === T_CONST ) { 64 | return ' constant'; 65 | } 66 | 67 | return ''; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /WPForms/Traits/Version.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | The code standard for WPForms. 4 | 5 | 6 | \.codeception/* 7 | \.packages/* 8 | \.vendor/* 9 | vendor/* 10 | vendor_prefixed/* 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 5 71 | 72 | 73 | 5 74 | 75 | 76 | 5 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "awesomemotive/wpforms-phpcs", 3 | "description": "WPForms Coding Standards", 4 | "type": "phpcodesniffer-standard", 5 | "license": "GPL-2.0-or-later", 6 | "config": { 7 | "allow-plugins": { 8 | "dealerdirect/phpcodesniffer-composer-installer": true 9 | }, 10 | "platform": { 11 | "php": "7.4" 12 | } 13 | }, 14 | "require": { 15 | "automattic/vipwpcs": "^3.0.1", 16 | "phpcompatibility/php-compatibility": "^9.3.5", 17 | "squizlabs/php_codesniffer": "^3.11.3", 18 | "wp-coding-standards/wpcs": "^3.1.0" 19 | }, 20 | "require-dev": { 21 | "roave/security-advisories": "dev-latest", 22 | "phpunit/phpunit": "6.5 - 9.6" 23 | }, 24 | "autoload-dev": { 25 | "psr-4": { 26 | "WPForms\\": "WPForms", 27 | "WPForms\\Tests\\Tests\\": "WPForms/Tests" 28 | } 29 | }, 30 | "scripts": { 31 | "cs": "vendor/bin/phpcs --standard=.phpcs.xml ./WPForms -s", 32 | "unit": "vendor/bin/phpunit --configuration ./WPForms/Tests/phpunit.xml" 33 | } 34 | } 35 | --------------------------------------------------------------------------------