PHP Compatibility Checker - Version 1.2.1

Version Description

  • Updated the PHPCompatibility library to latest version
Download this release

Release Info

Developer wpengine
Plugin Icon 128x128 PHP Compatibility Checker
Version 1.2.1
Comparing to
See all releases

Code changes from version 1.2.0 to 1.2.1

Files changed (83) hide show
  1. readme.txt +27 -25
  2. src/wpephpcompat.php +1 -1
  3. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/.coveralls.yml +1 -1
  4. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/.scrutinizer.yml +1 -1
  5. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/README.md +35 -6
  6. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniff.php +243 -29
  7. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ConstantArraysUsingDefineSniff.php +14 -20
  8. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/DeprecatedFunctionsSniff.php +16 -45
  9. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/DeprecatedIniDirectivesSniff.php +10 -6
  10. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/DeprecatedPHP4StyleConstructorsSniff.php +11 -7
  11. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/EmptyNonVariableSniff.php +153 -0
  12. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenBreakContinueVariableArgumentsSniff.php +36 -25
  13. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenCallTimePassByReferenceSniff.php +135 -95
  14. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenFunctionParametersWithSameNameSniff.php +24 -15
  15. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenGlobalVariableVariableSniff.php +1 -3
  16. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenNamesAsInvokedFunctionsSniff.php +45 -45
  17. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenNamesSniff.php +61 -35
  18. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenNegativeBitshiftSniff.php +17 -9
  19. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/MbstringReplaceEModifierSniff.php +107 -0
  20. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewAnonymousClassesSniff.php +6 -5
  21. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewClassesSniff.php +13 -11
  22. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewExecutionDirectivesSniff.php +4 -4
  23. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewFunctionArrayDereferencingSniff.php +33 -15
  24. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewFunctionParametersSniff.php +0 -14
  25. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewFunctionsSniff.php +7 -44
  26. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewGroupUseDeclarationsSniff.php +1 -1
  27. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewHashAlgorithmsSniff.php +168 -0
  28. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewIniDirectivesSniff.php +37 -42
  29. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewInterfacesSniff.php +10 -12
  30. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewKeywordsSniff.php +90 -58
  31. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewScalarReturnTypeDeclarationsSniff.php +2 -7
  32. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewScalarTypeDeclarationsSniff.php +6 -7
  33. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ParameterShadowSuperGlobalsSniff.php +1 -6
  34. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/PregReplaceEModifierSniff.php +56 -52
  35. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/RemovedAlternativePHPTagsSniff.php +163 -0
  36. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/RemovedFunctionParametersSniff.php +1 -15
  37. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/RemovedGlobalVariablesSniff.php +4 -4
  38. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/RemovedHashAlgorithmsSniff.php +93 -31
  39. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/RequiredOptionalFunctionParametersSniff.php +2 -2
  40. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ShortArraySniff.php +19 -27
  41. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/TernaryOperatorsSniff.php +12 -12
  42. vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ValidIntegersSniff.php +6 -6
  43. vendor/wimg/php-compatibility/.coveralls.yml +1 -1
  44. vendor/wimg/php-compatibility/.scrutinizer.yml +1 -1
  45. vendor/wimg/php-compatibility/README.md +35 -6
  46. vendor/wimg/php-compatibility/Sniff.php +243 -29
  47. vendor/wimg/php-compatibility/Sniffs/PHP/ConstantArraysUsingDefineSniff.php +14 -20
  48. vendor/wimg/php-compatibility/Sniffs/PHP/DeprecatedFunctionsSniff.php +16 -45
  49. vendor/wimg/php-compatibility/Sniffs/PHP/DeprecatedIniDirectivesSniff.php +10 -6
  50. vendor/wimg/php-compatibility/Sniffs/PHP/DeprecatedPHP4StyleConstructorsSniff.php +11 -7
  51. vendor/wimg/php-compatibility/Sniffs/PHP/EmptyNonVariableSniff.php +153 -0
  52. vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenBreakContinueVariableArgumentsSniff.php +36 -25
  53. vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenCallTimePassByReferenceSniff.php +135 -95
  54. vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenFunctionParametersWithSameNameSniff.php +24 -15
  55. vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenGlobalVariableVariableSniff.php +1 -3
  56. vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenNamesAsInvokedFunctionsSniff.php +45 -45
  57. vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenNamesSniff.php +61 -35
  58. vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenNegativeBitshiftSniff.php +17 -9
  59. vendor/wimg/php-compatibility/Sniffs/PHP/MbstringReplaceEModifierSniff.php +107 -0
  60. vendor/wimg/php-compatibility/Sniffs/PHP/NewAnonymousClassesSniff.php +6 -5
  61. vendor/wimg/php-compatibility/Sniffs/PHP/NewClassesSniff.php +13 -11
  62. vendor/wimg/php-compatibility/Sniffs/PHP/NewExecutionDirectivesSniff.php +4 -4
  63. vendor/wimg/php-compatibility/Sniffs/PHP/NewFunctionArrayDereferencingSniff.php +33 -15
  64. vendor/wimg/php-compatibility/Sniffs/PHP/NewFunctionParametersSniff.php +0 -14
  65. vendor/wimg/php-compatibility/Sniffs/PHP/NewFunctionsSniff.php +7 -44
  66. vendor/wimg/php-compatibility/Sniffs/PHP/NewGroupUseDeclarationsSniff.php +1 -1
  67. vendor/wimg/php-compatibility/Sniffs/PHP/NewHashAlgorithmsSniff.php +168 -0
  68. vendor/wimg/php-compatibility/Sniffs/PHP/NewIniDirectivesSniff.php +37 -42
  69. vendor/wimg/php-compatibility/Sniffs/PHP/NewInterfacesSniff.php +10 -12
  70. vendor/wimg/php-compatibility/Sniffs/PHP/NewKeywordsSniff.php +90 -58
  71. vendor/wimg/php-compatibility/Sniffs/PHP/NewScalarReturnTypeDeclarationsSniff.php +2 -7
  72. vendor/wimg/php-compatibility/Sniffs/PHP/NewScalarTypeDeclarationsSniff.php +6 -7
  73. vendor/wimg/php-compatibility/Sniffs/PHP/ParameterShadowSuperGlobalsSniff.php +1 -6
  74. vendor/wimg/php-compatibility/Sniffs/PHP/PregReplaceEModifierSniff.php +56 -52
  75. vendor/wimg/php-compatibility/Sniffs/PHP/RemovedAlternativePHPTagsSniff.php +163 -0
  76. vendor/wimg/php-compatibility/Sniffs/PHP/RemovedFunctionParametersSniff.php +1 -15
  77. vendor/wimg/php-compatibility/Sniffs/PHP/RemovedGlobalVariablesSniff.php +4 -4
  78. vendor/wimg/php-compatibility/Sniffs/PHP/RemovedHashAlgorithmsSniff.php +93 -31
  79. vendor/wimg/php-compatibility/Sniffs/PHP/RequiredOptionalFunctionParametersSniff.php +2 -2
  80. vendor/wimg/php-compatibility/Sniffs/PHP/ShortArraySniff.php +19 -27
  81. vendor/wimg/php-compatibility/Sniffs/PHP/TernaryOperatorsSniff.php +12 -12
  82. vendor/wimg/php-compatibility/Sniffs/PHP/ValidIntegersSniff.php +6 -6
  83. wpengine-phpcompat.php +2 -2
readme.txt CHANGED
@@ -3,15 +3,15 @@ Contributors: wpengine, octalmage, stevenkword, Taylor4484, pross
3
  Tags: php 7, php 5.5, php, version, compatibility, checker, wp engine, wpe, wpengine
4
  Requires at least: 3.5
5
  Tested up to: 4.6
6
- Stable tag: 1.2.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
- Make sure your plugins and themes are compatible with newer PHP versions.
11
 
12
  == Description ==
13
 
14
- The WP Engine PHP Compatibility Checker can be used by any WordPress website on any web host to check PHP version compatibility.
15
 
16
  This plugin will lint theme and plugin code inside your WordPress file system and give you back a report of compatibility issues for you to fix. Compatibility issues are categorized into errors and warnings and will list the file and line number of the offending code, as well as the info about why that line of code is incompatible with the chosen version of PHP. The plugin will also suggest updates to themes and plugins, as a new version may offer compatible code.
17
 
@@ -19,11 +19,13 @@ This plugin will lint theme and plugin code inside your WordPress file system an
19
 
20
  **Please note that linting code is not perfect. This plugin cannot detect unused codepaths that might be used for backwards compatibility, and thus might show false postiives. We maintain a [whitelist of plugins](https://github.com/wpengine/phpcompat/wiki/Results) that can cause false positives. We are continuously working to ensure the checker provides the most accurate results possible.**
21
 
 
 
22
  = Update to PHP 7 =
23
- * Use this plugin to check your site for compatibility for PHP 7!
24
  * As of [August 2016](https://wordpress.org/about/stats/), 57.1% of WordPress websites run a PHP version less PHP 5.5.
25
  * These versions of PHP have been deprecated and unsupported for over 9 months.
26
- * Only 2.2% of WordPress websites run PHP 7, the current main version of PHP.
27
 
28
 
29
  = Disclaimer =
@@ -31,13 +33,13 @@ This plugin will lint theme and plugin code inside your WordPress file system an
31
 
32
  The plugin was created by WP Engine to help the WordPress community increase adoption of modern PHP versions. We [welcome contributors](https://github.com/wpengine/phpcompat) to this plugin, and are excited to see how developers and other WordPress hosts use this plugin.
33
 
34
- To disclose security issues for this plugin please email WordPress@wpengine.com
35
 
36
  == Installation ==
37
 
38
  *Note: If you have WordPress 2.7 or above you can simply go to 'Plugins' > 'Add New' in the WordPress admin and search for "PHP Compatibility Checker" and install it from there.*
39
 
40
- To manually install:
41
  1. Upload `phpcompat` to the `/wpengine-wp-content/plugins/` directory
42
  2. Activate the plugin through the 'Plugins' menu in WordPress
43
 
@@ -51,7 +53,7 @@ PHP Compatibility Checker includes WP-CLI command support:
51
 
52
  `wp phpcompat <version> [--scan=<scan>]`
53
 
54
- `
55
  <version>
56
  PHP version to test.
57
 
@@ -69,7 +71,7 @@ Example: `wp phpcompat 7.0 --scan=active`
69
 
70
  1. Will this work outside of the WP Engine hosting account?
71
 
72
- Yes, this plugin can be used any ANY WordPress website on ANY host.
73
 
74
  2. Are there WP-CLI commands available?
75
 
@@ -77,33 +79,33 @@ Example: `wp phpcompat 7.0 --scan=active`
77
 
78
  3. A plugin I created is listed as not compatible, what should I do?
79
 
80
- We maintain a [whitelist of plugins](https://github.com/wpengine/phpcompat/wiki/Results) that cause false positives. If your plugin shows up as incompatible but you think that is wrong, please open a [GitHub issue](https://github.com/wpengine/phpcompat/issues/new) on the project, or email wordpress@wpengine.com with info about your plugin and why you know it is compatible (you have automated tests, the failure is on backwards compatibility codepaths, etc).
 
 
81
 
82
- 4. Can I use this to test non-WordPress PHP Projects?
83
-
84
  Yes! While you cannot use this WordPress plugin to test your non-WordPress projects, you can use the [Open Source PHPCompatibility Library](https://github.com/wimg/PHPCompatibility) that this plugin is built on.
85
 
86
  5. Why was my plugin/theme skipped?
87
 
88
- Some servers have timeouts to prevent long running queries, this is commonly 60 seconds. This can prevent the checker from being able to process large themes or plugins. You should check with your host to see if this timeout can be temporarily removed. The best way around this timeout issue is to run this plugin on a [local copy](https://make.wordpress.org/core/handbook/tutorials/installing-a-local-server/) of your site, or you can use the WP-CLI command.
89
-
90
  You can use the filter `wpephpcompat_scan_timeout` to customize the scan timeout. See [this](https://gist.github.com/octalmage/07f26e0d1f25cea9a8ca92ebc67a3a14) for an example.
91
-
92
  Setting the timeout to 0 disables the cron/timeout.
93
-
94
  6. The scan is stuck, what can I do?
95
 
96
- The PHP Compatibility Checker relies on WP-Cron to process plugins/themes in batches, this is necessary to avoid server timeouts. The scan will get stuck if your site's WP-Cron isn't functioning. You can look into this using [WP Crontrol](https://wordpress.org/plugins/wp-crontrol/). The cron is called `wpephpcompat_start_test_cron`.
97
 
98
  You can also use the [WP-CLI command](https://wordpress.org/plugins/php-compatibility-checker/other_notes/) or disable the timeout to avoid using WP-Cron.
99
 
100
  7. I found a bug, or have a suggestion, can I contribute back?
101
 
102
- Yes! WP Engine has a public GitHub repo where you can contribute back to this plugin. Please open an issue on the [Plugin GitHub](https://github.com/wpengine/phpcompat). We actively develop this plugin, and are always happy to receive pull requests.
103
 
104
  The plugin was created by WP Engine to help the WordPress community increase adoption of modern PHP versions. We welcome contributors to this plugin, and are excited to see how developers and other WordPress hosts use this plugin.
105
 
106
- To disclose security issues for this plugin please email WordPress@wpengine.com
107
 
108
  == Screenshots ==
109
 
@@ -112,6 +114,9 @@ To disclose security issues for this plugin please email WordPress@wpengine.com
112
 
113
  == Changelog ==
114
 
 
 
 
115
  = 1.2.0 =
116
  - Updated the PHPCompatibility library to latest version
117
  - Added support for PHP 5.6
@@ -138,7 +143,7 @@ To disclose security issues for this plugin please email WordPress@wpengine.com
138
  = 1.0.2 =
139
  - Added additional role protections
140
  - Changed the UI colors to better understand output at a glance
141
- - Exclude checking node_modules and tmp directories
142
  - Added support for child theme's parent theme
143
 
144
  = 1.0.1 =
@@ -157,8 +162,5 @@ To disclose security issues for this plugin please email WordPress@wpengine.com
157
 
158
  == Upgrade Notice ==
159
 
160
- = 1.1.2 =
161
- - Fixed issue with WordPress notices breaking the plugin header.
162
- - Changed the way we send and parse JSON.
163
- - You can now restart an in progress scan.
164
- - Updated download.js to v4.2 for better Safari compatibility.
3
  Tags: php 7, php 5.5, php, version, compatibility, checker, wp engine, wpe, wpengine
4
  Requires at least: 3.5
5
  Tested up to: 4.6
6
+ Stable tag: 1.2.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
+ Make sure your plugins and themes are compatible with newer PHP versions.
11
 
12
  == Description ==
13
 
14
+ The WP Engine PHP Compatibility Checker can be used by any WordPress website on any web host to check PHP version compatibility.
15
 
16
  This plugin will lint theme and plugin code inside your WordPress file system and give you back a report of compatibility issues for you to fix. Compatibility issues are categorized into errors and warnings and will list the file and line number of the offending code, as well as the info about why that line of code is incompatible with the chosen version of PHP. The plugin will also suggest updates to themes and plugins, as a new version may offer compatible code.
17
 
19
 
20
  **Please note that linting code is not perfect. This plugin cannot detect unused codepaths that might be used for backwards compatibility, and thus might show false postiives. We maintain a [whitelist of plugins](https://github.com/wpengine/phpcompat/wiki/Results) that can cause false positives. We are continuously working to ensure the checker provides the most accurate results possible.**
21
 
22
+ **This plugin relies on WP-Cron to scan files in the background. The scan will get stuck if the site's WP-Cron isn't running correctly. Please see the [FAQ](https://wordpress.org/plugins/php-compatibility-checker/faq/) for more information.**
23
+
24
  = Update to PHP 7 =
25
+ * Use this plugin to check your site for compatibility for PHP 7!
26
  * As of [August 2016](https://wordpress.org/about/stats/), 57.1% of WordPress websites run a PHP version less PHP 5.5.
27
  * These versions of PHP have been deprecated and unsupported for over 9 months.
28
+ * Only 2.2% of WordPress websites run PHP 7, the current main version of PHP.
29
 
30
 
31
  = Disclaimer =
33
 
34
  The plugin was created by WP Engine to help the WordPress community increase adoption of modern PHP versions. We [welcome contributors](https://github.com/wpengine/phpcompat) to this plugin, and are excited to see how developers and other WordPress hosts use this plugin.
35
 
36
+ To disclose security issues for this plugin please email WordPress@wpengine.com
37
 
38
  == Installation ==
39
 
40
  *Note: If you have WordPress 2.7 or above you can simply go to 'Plugins' > 'Add New' in the WordPress admin and search for "PHP Compatibility Checker" and install it from there.*
41
 
42
+ To manually install:
43
  1. Upload `phpcompat` to the `/wpengine-wp-content/plugins/` directory
44
  2. Activate the plugin through the 'Plugins' menu in WordPress
45
 
53
 
54
  `wp phpcompat <version> [--scan=<scan>]`
55
 
56
+ `
57
  <version>
58
  PHP version to test.
59
 
71
 
72
  1. Will this work outside of the WP Engine hosting account?
73
 
74
+ Yes, this plugin can be used any ANY WordPress website on ANY host.
75
 
76
  2. Are there WP-CLI commands available?
77
 
79
 
80
  3. A plugin I created is listed as not compatible, what should I do?
81
 
82
+ We maintain a [whitelist of plugins](https://github.com/wpengine/phpcompat/wiki/Results) that cause false positives. If your plugin shows up as incompatible but you think that is wrong, please open a [GitHub issue](https://github.com/wpengine/phpcompat/issues/new) on the project, or email wordpress@wpengine.com with info about your plugin and why you know it is compatible (you have automated tests, the failure is on backwards compatibility codepaths, etc).
83
+
84
+ 4. Can I use this to test non-WordPress PHP Projects?
85
 
 
 
86
  Yes! While you cannot use this WordPress plugin to test your non-WordPress projects, you can use the [Open Source PHPCompatibility Library](https://github.com/wimg/PHPCompatibility) that this plugin is built on.
87
 
88
  5. Why was my plugin/theme skipped?
89
 
90
+ Some servers have timeouts to prevent long running queries, this is commonly 60 seconds. This can prevent the checker from being able to process large themes or plugins. You should check with your host to see if this timeout can be temporarily removed. The best way around this timeout issue is to run this plugin on a [local copy](https://make.wordpress.org/core/handbook/tutorials/installing-a-local-server/) of your site, or you can use the WP-CLI command.
91
+
92
  You can use the filter `wpephpcompat_scan_timeout` to customize the scan timeout. See [this](https://gist.github.com/octalmage/07f26e0d1f25cea9a8ca92ebc67a3a14) for an example.
93
+
94
  Setting the timeout to 0 disables the cron/timeout.
95
+
96
  6. The scan is stuck, what can I do?
97
 
98
+ The PHP Compatibility Checker relies on WP-Cron to process plugins/themes in batches, this is necessary to avoid server timeouts. The scan will get stuck if your site's WP-Cron isn't functioning. You can look into this using [WP Crontrol](https://wordpress.org/plugins/wp-crontrol/). The cron is called `wpephpcompat_start_test_cron`. This could also be an issue if your site is using basic authentication.
99
 
100
  You can also use the [WP-CLI command](https://wordpress.org/plugins/php-compatibility-checker/other_notes/) or disable the timeout to avoid using WP-Cron.
101
 
102
  7. I found a bug, or have a suggestion, can I contribute back?
103
 
104
+ Yes! WP Engine has a public GitHub repo where you can contribute back to this plugin. Please open an issue on the [Plugin GitHub](https://github.com/wpengine/phpcompat). We actively develop this plugin, and are always happy to receive pull requests.
105
 
106
  The plugin was created by WP Engine to help the WordPress community increase adoption of modern PHP versions. We welcome contributors to this plugin, and are excited to see how developers and other WordPress hosts use this plugin.
107
 
108
+ To disclose security issues for this plugin please email WordPress@wpengine.com
109
 
110
  == Screenshots ==
111
 
114
 
115
  == Changelog ==
116
 
117
+ = 1.2.1 =
118
+ - Updated the PHPCompatibility library to latest version
119
+
120
  = 1.2.0 =
121
  - Updated the PHPCompatibility library to latest version
122
  - Added support for PHP 5.6
143
  = 1.0.2 =
144
  - Added additional role protections
145
  - Changed the UI colors to better understand output at a glance
146
+ - Exclude checking node_modules and tmp directories
147
  - Added support for child theme's parent theme
148
 
149
  = 1.0.1 =
162
 
163
  == Upgrade Notice ==
164
 
165
+ = 1.2.1 =
166
+ - Updated the PHPCompatibility library to latest version
 
 
 
src/wpephpcompat.php CHANGED
@@ -201,7 +201,7 @@ class WPEPHPCompat {
201
  update_option( 'wpephpcompat.scan_results', $scan_results , false );
202
  wp_delete_post( $directory->ID );
203
  $count = 0;
204
- $this->debug_log( 'Skipped: ' .$directory->post_title );
205
  continue;
206
  }
207
 
201
  update_option( 'wpephpcompat.scan_results', $scan_results , false );
202
  wp_delete_post( $directory->ID );
203
  $count = 0;
204
+ $this->debug_log( 'Skipped: ' . $directory->post_title );
205
  continue;
206
  }
207
 
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/.coveralls.yml CHANGED
@@ -1,3 +1,3 @@
1
- src_dir: Sniffs
2
  coverage_clover: build/logs/clover.xml
3
  json_path: build/logs/coveralls-upload.json
 
 
1
  coverage_clover: build/logs/clover.xml
2
  json_path: build/logs/coveralls-upload.json
3
+ service_name: travis-ci
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/.scrutinizer.yml CHANGED
@@ -1,6 +1,6 @@
1
  filter:
2
  excluded_paths:
3
- - 'Tests/sniff-examples/*'
4
 
5
  tools:
6
  php_sim: true
1
  filter:
2
  excluded_paths:
3
+ - 'Tests/*'
4
 
5
  tools:
6
  php_sim: true
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/README.md CHANGED
@@ -2,6 +2,7 @@ PHP Compatibility Coding Standard for PHP_CodeSniffer
2
  =====================================================
3
  [![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=wimg&url=https://github.com/wimg/PHPCompatibility&title=PHPCompatibility&language=&tags=github&category=software)
4
  [![Build Status](https://travis-ci.org/wimg/PHPCompatibility.png?branch=master)](https://travis-ci.org/wimg/PHPCompatibility)
 
5
  [![Latest Stable Version](https://poser.pugx.org/wimg/php-compatibility/v/stable.png)](https://packagist.org/packages/wimg/php-compatibility)
6
  [![Latest Unstable Version](https://poser.pugx.org/wimg/php-compatibility/v/unstable.png)](https://packagist.org/packages/wimg/php-compatibility)
7
  [![License](https://poser.pugx.org/wimg/php-compatibility/license.png)](https://packagist.org/packages/wimg/php-compatibility)
@@ -10,11 +11,22 @@ This is a set of sniffs for [PHP_CodeSniffer](http://pear.php.net/PHP_CodeSniffe
10
  It will allow you to analyse your code for compatibility with higher and lower versions of PHP.
11
 
12
 
 
 
 
 
 
 
 
 
 
13
  Thank you
14
  ---------
15
  Thanks to all contributors for their valuable contributions.
16
-
17
- Thanks to [![WPEngine](https://cu.be/img/wpengine.png)](http://wpengine.com) for their support on the PHP 7.0 sniffs.
 
 
18
 
19
 
20
  Installation (method 1)
@@ -71,18 +83,18 @@ Alternatively, you can add PHPCompatibility to a custom PHPCS ruleset.
71
 
72
  You can also set the `testVersion` from within the ruleset:
73
  ```xml
74
- <arg name="testVersion" value="5.3-5.5"/>
75
  ```
76
 
77
- Other advanced options, such as changing the message type or severity, as described in the [PHPCS Annotated ruleset](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml) wiki page are, of course, also supported.
78
 
79
 
80
- ##### PHPCompatibility specific options
81
 
82
  At this moment, there is one sniff which has a property which can be set via the ruleset. More custom properties may become available in the future.
83
 
84
  The `PHPCompatibility.PHP.RemovedExtensions` sniff checks for removed extensions based on the function prefix used for these extensions.
85
- This might clash with userland function using the same function prefix.
86
 
87
  To whitelist userland functions, you can pass a comma-delimited list of function names to the sniff.
88
  ```xml
@@ -134,6 +146,23 @@ on the sniffs, the following installation steps are required.
134
  PHPCompatibility. It will read the `phpunit.xml` file and execute the tests
135
 
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  License
138
  -------
139
  This code is released under the GNU Lesser General Public License (LGPL). For more information, visit http://www.gnu.org/copyleft/lesser.html
2
  =====================================================
3
  [![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=wimg&url=https://github.com/wimg/PHPCompatibility&title=PHPCompatibility&language=&tags=github&category=software)
4
  [![Build Status](https://travis-ci.org/wimg/PHPCompatibility.png?branch=master)](https://travis-ci.org/wimg/PHPCompatibility)
5
+ [![Coverage Status](https://coveralls.io/repos/github/wimg/PHPCompatibility/badge.svg?branch=master)](https://coveralls.io/github/wimg/PHPCompatibility?branch=master)
6
  [![Latest Stable Version](https://poser.pugx.org/wimg/php-compatibility/v/stable.png)](https://packagist.org/packages/wimg/php-compatibility)
7
  [![Latest Unstable Version](https://poser.pugx.org/wimg/php-compatibility/v/unstable.png)](https://packagist.org/packages/wimg/php-compatibility)
8
  [![License](https://poser.pugx.org/wimg/php-compatibility/license.png)](https://packagist.org/packages/wimg/php-compatibility)
11
  It will allow you to analyse your code for compatibility with higher and lower versions of PHP.
12
 
13
 
14
+ PHP Version Support
15
+ -------
16
+
17
+ The project aims to cover all PHP compatibility changes introduced since PHP 5.0 up to the latest PHP release. This is an ongoing process and coverage is not yet 100% (if, indeed, it ever could be). Progress is tracked on [our Github issue tracker](https://github.com/wimg/PHPCompatibility/issues).
18
+
19
+ Pull requests that check for compatibility issues in PHP4 code - in particular between PHP 4 and PHP 5.0 - are very welcome as there are still situations where people need help upgrading legacy systems. However, coverage for changes introduced before PHP 5.1 will remain patchy as sniffs for this are not actively being developed at this time.
20
+
21
+ The sniffs are designed to give the same results regardless of which PHP version you are using to run CodeSniffer. Therefore you should get consistent results independently of the PHP version used in your test environment.
22
+
23
  Thank you
24
  ---------
25
  Thanks to all contributors for their valuable contributions.
26
+
27
+ [![WPEngine](https://cu.be/img/wpengine.png)](https://wpengine.com)
28
+
29
+ Thanks to [WP Engine](https://wpengine.com) for their support on the PHP 7.0 sniffs.
30
 
31
 
32
  Installation (method 1)
83
 
84
  You can also set the `testVersion` from within the ruleset:
85
  ```xml
86
+ <config name="testVersion" value="5.3-5.5"/>
87
  ```
88
 
89
+ Other advanced options, such as changing the message type or severity of select sniffs, as described in the [PHPCS Annotated ruleset](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml) wiki page are, of course, also supported.
90
 
91
 
92
+ #### PHPCompatibility specific options
93
 
94
  At this moment, there is one sniff which has a property which can be set via the ruleset. More custom properties may become available in the future.
95
 
96
  The `PHPCompatibility.PHP.RemovedExtensions` sniff checks for removed extensions based on the function prefix used for these extensions.
97
+ This might clash with userland functions using the same function prefix.
98
 
99
  To whitelist userland functions, you can pass a comma-delimited list of function names to the sniff.
100
  ```xml
146
  PHPCompatibility. It will read the `phpunit.xml` file and execute the tests
147
 
148
 
149
+ #### Issues when running the PHPCS Unit tests for another standard
150
+
151
+ This sniff library uses its own PHPUnit setup rather than the PHPCS native unit testing framework to allow for testing the sniffs with various config settings for the `testVersion` variable.
152
+
153
+ If you are running the PHPCS native unit tests or the unit tests for another sniff library which uses the PHPCS native unit testing framework, PHPUnit might throw errors related to this sniff library depending on your setup.
154
+
155
+ This will generally only happen if you have both PHPCompatibility as well as another custom sniff library in your PHPCS `installed_paths` setting.
156
+
157
+ To fix these errors, make sure you are running PHPCS 2.7.1 or higher and add the following to the `phpunit.xml` file for the sniff library you are testing:
158
+ ```xml
159
+ <php>
160
+ <env name="PHPCS_IGNORE_TESTS" value="PHPCompatibility"/>
161
+ </php>
162
+ ```
163
+
164
+ This will prevent PHPCS trying to include the PHPCompatibility unit tests when creating the test suite.
165
+
166
  License
167
  -------
168
  This code is released under the GNU Lesser General Public License (LGPL). For more information, visit http://www.gnu.org/copyleft/lesser.html
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniff.php CHANGED
@@ -22,6 +22,24 @@
22
  abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
23
  {
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  /* The testVersion configuration variable may be in any of the following formats:
26
  * 1) Omitted/empty, in which case no version is specified. This effectively
27
  * disables all the checks provided by this standard.
@@ -76,7 +94,7 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
76
  return $arrTestVersions[$testVersion];
77
  }
78
  else {
79
- return array(null, null);
80
  }
81
  }
82
 
@@ -108,6 +126,21 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
108
  }
109
  }//end supportsBelow()
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  /**
112
  * Returns the name(s) of the interface(s) that the specified class implements.
113
  *
@@ -123,8 +156,12 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
123
  *
124
  * @return array|false
125
  */
126
- public function findImplementedInterfaceNames($phpcsFile, $stackPtr)
127
  {
 
 
 
 
128
  $tokens = $phpcsFile->getTokens();
129
 
130
  // Check for the existence of the token.
@@ -238,10 +275,35 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
238
  return 0;
239
  }
240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  // Ok, we know we have a T_STRING with parameters and valid open & close parenthesis.
242
  $tokens = $phpcsFile->getTokens();
243
 
244
- $openParenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
245
  $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
246
 
247
  // Which nesting level is the one we are interested in ?
@@ -250,44 +312,108 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
250
  $nestedParenthesisCount = count($tokens[$openParenthesis]['nested_parenthesis']) + 1;
251
  }
252
 
253
- $nextComma = $openParenthesis;
254
- $cnt = 0;
255
- while ($nextComma = $phpcsFile->findNext(array(T_COMMA, T_CLOSE_PARENTHESIS), $nextComma + 1, $closeParenthesis + 1)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  // Ignore comma's at a lower nesting level.
257
  if (
258
- $tokens[$nextComma]['type'] == 'T_COMMA'
259
  &&
260
  isset($tokens[$nextComma]['nested_parenthesis'])
261
  &&
262
- count($tokens[$nextComma]['nested_parenthesis']) != $nestedParenthesisCount
263
  ) {
264
  continue;
265
  }
266
 
267
  // Ignore closing parenthesis if not 'ours'.
268
- if ($tokens[$nextComma]['type'] == 'T_CLOSE_PARENTHESIS' && $nextComma != $closeParenthesis) {
269
  continue;
270
  }
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  $cnt++;
273
  }
274
 
275
- return $cnt;
276
  }
277
 
278
 
279
  /**
280
- * Verify whether a token is within a class scope.
281
  *
282
- * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
283
- * @param int $stackPtr The position of the token.
284
- * @param bool $strict Whether to strictly check for the T_CLASS
285
- * scope or also accept interfaces and traits
286
- * as scope.
287
  *
288
- * @return bool True if within class scope, false otherwise.
 
 
 
 
 
 
 
 
289
  */
290
- public function inClassScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $strict = true)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  {
292
  $tokens = $phpcsFile->getTokens();
293
 
@@ -301,15 +427,24 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
301
  return false;
302
  }
303
 
304
- $validScope = array(T_CLASS);
305
- if ($strict === false) {
306
- $validScope[] = T_INTERFACE;
307
- $validScope[] = T_TRAIT;
308
  }
309
 
310
- // Check for class scope.
 
 
 
 
 
 
 
 
 
 
311
  foreach ($tokens[$stackPtr]['conditions'] as $pointer => $type) {
312
- if (in_array($type, $validScope, true)) {
313
  return true;
314
  }
315
  }
@@ -318,6 +453,29 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
318
  }
319
 
320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  /**
322
  * Returns the fully qualified class name for a new class instantiation.
323
  *
@@ -348,7 +506,12 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
348
  T_WHITESPACE,
349
  );
350
 
351
- $start = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
 
 
 
 
 
352
  $end = $phpcsFile->findNext($find, ($start + 1), null, true, null, true);
353
  $className = $phpcsFile->getTokensAsString($start, ($end - $start));
354
  $className = trim($className);
@@ -414,6 +577,11 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
414
  return '';
415
  }
416
 
 
 
 
 
 
417
  // Nothing to do if 'parent' or 'static' as we don't know how far the class tree extends.
418
  if (in_array($tokens[$stackPtr - 1]['code'], array(T_PARENT, T_STATIC), true)) {
419
  return '';
@@ -423,8 +591,8 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
423
  if ($tokens[$stackPtr - 1]['code'] === T_SELF) {
424
  $classDeclarationPtr = $phpcsFile->findPrevious(T_CLASS, $stackPtr - 1);
425
  if ($classDeclarationPtr === false) {
426
- return '';
427
- }
428
  $className = $phpcsFile->getDeclarationName($classDeclarationPtr);
429
  return $this->getFQName($phpcsFile, $classDeclarationPtr, $className);
430
  }
@@ -521,8 +689,8 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
521
  if ($namespace !== false) {
522
  return $namespace;
523
  }
 
524
  }
525
- break; // We only need to check the highest level condition.
526
  }
527
  }
528
 
@@ -635,7 +803,7 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
635
  * @param int $stackPtr The position in the stack of the T_FUNCTION token
636
  * to acquire the parameters for.
637
  *
638
- * @return array
639
  * @throws PHP_CodeSniffer_Exception If the specified $stackPtr is not of
640
  * type T_FUNCTION.
641
  */
@@ -785,4 +953,50 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
785
 
786
  }//end getMethodParameters()
787
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
788
  }//end class
22
  abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
23
  {
24
 
25
+ /**
26
+ * List of functions using hash algorithm as parameter (always the first parameter).
27
+ *
28
+ * Used by the new/removed hash algorithm sniffs.
29
+ * Key is the function name, value is the 1-based parameter position in the function call.
30
+ *
31
+ * @var array
32
+ */
33
+ protected $hashAlgoFunctions = array(
34
+ 'hash_file' => 1,
35
+ 'hash_hmac_file' => 1,
36
+ 'hash_hmac' => 1,
37
+ 'hash_init' => 1,
38
+ 'hash_pbkdf2' => 1,
39
+ 'hash' => 1,
40
+ );
41
+
42
+
43
  /* The testVersion configuration variable may be in any of the following formats:
44
  * 1) Omitted/empty, in which case no version is specified. This effectively
45
  * disables all the checks provided by this standard.
94
  return $arrTestVersions[$testVersion];
95
  }
96
  else {
97
+ return array(null, null);
98
  }
99
  }
100
 
126
  }
127
  }//end supportsBelow()
128
 
129
+
130
+ /**
131
+ * Strip quotes surrounding an arbitrary string.
132
+ *
133
+ * Intended for use with the content of a T_CONSTANT_ENCAPSED_STRING.
134
+ *
135
+ * @param string $string The raw string.
136
+ *
137
+ * @return string String without quotes around it.
138
+ */
139
+ public function stripQuotes($string) {
140
+ return preg_replace('`^([\'"])(.*)\1$`Ds', '$2', $string);
141
+ }
142
+
143
+
144
  /**
145
  * Returns the name(s) of the interface(s) that the specified class implements.
146
  *
156
  *
157
  * @return array|false
158
  */
159
+ public function findImplementedInterfaceNames(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
160
  {
161
+ if (method_exists($phpcsFile, 'findImplementedInterfaceNames')) {
162
+ return $phpcsFile->findImplementedInterfaceNames($stackPtr);
163
+ }
164
+
165
  $tokens = $phpcsFile->getTokens();
166
 
167
  // Check for the existence of the token.
275
  return 0;
276
  }
277
 
278
+ return count($this->getFunctionCallParameters($phpcsFile, $stackPtr));
279
+ }
280
+
281
+
282
+ /**
283
+ * Get information on all parameters passed to a function call.
284
+ *
285
+ * Expects to be passed the T_STRING stack pointer for the function call.
286
+ * If passed a T_STRING which is *not* a function call, the behaviour is unreliable.
287
+ *
288
+ * Will return an multi-dimentional array with the start token pointer, end token
289
+ * pointer and raw parameter value for all parameters. Index will be 1-based.
290
+ * If no parameters are found, will return an empty array.
291
+ *
292
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
293
+ * @param int $stackPtr The position of the function call token.
294
+ *
295
+ * @return array
296
+ */
297
+ public function getFunctionCallParameters(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
298
+ {
299
+ if ($this->doesFunctionCallHaveParameters($phpcsFile, $stackPtr) === false) {
300
+ return array();
301
+ }
302
+
303
  // Ok, we know we have a T_STRING with parameters and valid open & close parenthesis.
304
  $tokens = $phpcsFile->getTokens();
305
 
306
+ $openParenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
307
  $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
308
 
309
  // Which nesting level is the one we are interested in ?
312
  $nestedParenthesisCount = count($tokens[$openParenthesis]['nested_parenthesis']) + 1;
313
  }
314
 
315
+ $parameters = array();
316
+ $nextComma = $openParenthesis;
317
+ $paramStart = $openParenthesis + 1;
318
+ $cnt = 1;
319
+ while ($nextComma = $phpcsFile->findNext(array(T_COMMA, T_CLOSE_PARENTHESIS, T_OPEN_SHORT_ARRAY), $nextComma + 1, $closeParenthesis + 1)) {
320
+ // Ignore anything within short array definition brackets.
321
+ if (
322
+ $tokens[$nextComma]['type'] === 'T_OPEN_SHORT_ARRAY'
323
+ &&
324
+ ( isset($tokens[$nextComma]['bracket_opener']) && $tokens[$nextComma]['bracket_opener'] === $nextComma )
325
+ &&
326
+ isset($tokens[$nextComma]['bracket_closer'])
327
+ ) {
328
+ // Skip forward to the end of the short array definition.
329
+ $nextComma = $tokens[$nextComma]['bracket_closer'];
330
+ continue;
331
+ }
332
+
333
  // Ignore comma's at a lower nesting level.
334
  if (
335
+ $tokens[$nextComma]['type'] === 'T_COMMA'
336
  &&
337
  isset($tokens[$nextComma]['nested_parenthesis'])
338
  &&
339
+ count($tokens[$nextComma]['nested_parenthesis']) !== $nestedParenthesisCount
340
  ) {
341
  continue;
342
  }
343
 
344
  // Ignore closing parenthesis if not 'ours'.
345
+ if ($tokens[$nextComma]['type'] === 'T_CLOSE_PARENTHESIS' && $nextComma !== $closeParenthesis) {
346
  continue;
347
  }
348
 
349
+ // Ok, we've reached the end of the parameter.
350
+ $parameters[$cnt]['start'] = $paramStart;
351
+ $parameters[$cnt]['end'] = $nextComma - 1;
352
+ $parameters[$cnt]['raw'] = trim($phpcsFile->getTokensAsString($paramStart, ($nextComma - $paramStart)));
353
+
354
+ // Check if there are more tokens before the closing parenthesis.
355
+ // Prevents code like the following from setting a third parameter:
356
+ // functionCall( $param1, $param2, );
357
+ $hasNextParam = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $nextComma + 1, $closeParenthesis, true, null, true);
358
+ if ($hasNextParam === false) {
359
+ break;
360
+ }
361
+
362
+ // Prepare for the next parameter.
363
+ $paramStart = $nextComma + 1;
364
  $cnt++;
365
  }
366
 
367
+ return $parameters;
368
  }
369
 
370
 
371
  /**
372
+ * Get information on a specific parameter passed to a function call.
373
  *
374
+ * Expects to be passed the T_STRING stack pointer for the function call.
375
+ * If passed a T_STRING which is *not* a function call, the behaviour is unreliable.
 
 
 
376
  *
377
+ * Will return a array with the start token pointer, end token pointer and the raw value
378
+ * of the parameter at a specific offset.
379
+ * If the specified parameter is not found, will return false.
380
+ *
381
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
382
+ * @param int $stackPtr The position of the function call token.
383
+ * @param int $paramOffset The 1-based index position of the parameter to retrieve.
384
+ *
385
+ * @return array|false
386
  */
387
+ public function getFunctionCallParameter(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $paramOffset)
388
+ {
389
+ $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
390
+
391
+ if (isset($parameters[$paramOffset]) === false) {
392
+ return false;
393
+ }
394
+ else {
395
+ return $parameters[$paramOffset];
396
+ }
397
+ }
398
+
399
+
400
+ /**
401
+ * Verify whether a token is within a scoped condition.
402
+ *
403
+ * If the optional $validScopes parameter has been passed, the function
404
+ * will check that the token has at least one condition which is of a
405
+ * type defined in $validScopes.
406
+ *
407
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
408
+ * @param int $stackPtr The position of the token.
409
+ * @param array|int $validScopes Optional. Array of valid scopes
410
+ * or int value of a valid scope.
411
+ *
412
+ * @return bool Without the optional $scopeTypes: True if within a scope, false otherwise.
413
+ * If the $scopeTypes are set: True if *one* of the conditions is a
414
+ * valid scope, false otherwise.
415
+ */
416
+ public function tokenHasScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $validScopes = null)
417
  {
418
  $tokens = $phpcsFile->getTokens();
419
 
427
  return false;
428
  }
429
 
430
+ // Ok, there are conditions, do we have to check for specific ones ?
431
+ if (isset($validScopes) === false) {
432
+ return true;
 
433
  }
434
 
435
+ if (is_int($validScopes)) {
436
+ // Received an integer, so cast to array.
437
+ $validScopes = (array) $validScopes;
438
+ }
439
+
440
+ if (empty($validScopes) || is_array($validScopes) === false) {
441
+ // No valid scope types received, so will not comply.
442
+ return false;
443
+ }
444
+
445
+ // Check for required scope types.
446
  foreach ($tokens[$stackPtr]['conditions'] as $pointer => $type) {
447
+ if (in_array($type, $validScopes, true)) {
448
  return true;
449
  }
450
  }
453
  }
454
 
455
 
456
+ /**
457
+ * Verify whether a token is within a class scope.
458
+ *
459
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
460
+ * @param int $stackPtr The position of the token.
461
+ * @param bool $strict Whether to strictly check for the T_CLASS
462
+ * scope or also accept interfaces and traits
463
+ * as scope.
464
+ *
465
+ * @return bool True if within class scope, false otherwise.
466
+ */
467
+ public function inClassScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $strict = true)
468
+ {
469
+ $validScopes = array(T_CLASS);
470
+ if ($strict === false) {
471
+ $validScopes[] = T_INTERFACE;
472
+ $validScopes[] = T_TRAIT;
473
+ }
474
+
475
+ return $this->tokenHasScope($phpcsFile, $stackPtr, $validScopes);
476
+ }
477
+
478
+
479
  /**
480
  * Returns the fully qualified class name for a new class instantiation.
481
  *
506
  T_WHITESPACE,
507
  );
508
 
509
+ $start = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
510
+ // Bow out if the next token is a variable as we don't know where it was defined.
511
+ if ($tokens[$start]['code'] === T_VARIABLE) {
512
+ return '';
513
+ }
514
+
515
  $end = $phpcsFile->findNext($find, ($start + 1), null, true, null, true);
516
  $className = $phpcsFile->getTokensAsString($start, ($end - $start));
517
  $className = trim($className);
577
  return '';
578
  }
579
 
580
+ // Nothing to do if previous token is a variable as we don't know where it was defined.
581
+ if ($tokens[$stackPtr - 1]['code'] === T_VARIABLE) {
582
+ return '';
583
+ }
584
+
585
  // Nothing to do if 'parent' or 'static' as we don't know how far the class tree extends.
586
  if (in_array($tokens[$stackPtr - 1]['code'], array(T_PARENT, T_STATIC), true)) {
587
  return '';
591
  if ($tokens[$stackPtr - 1]['code'] === T_SELF) {
592
  $classDeclarationPtr = $phpcsFile->findPrevious(T_CLASS, $stackPtr - 1);
593
  if ($classDeclarationPtr === false) {
594
+ return '';
595
+ }
596
  $className = $phpcsFile->getDeclarationName($classDeclarationPtr);
597
  return $this->getFQName($phpcsFile, $classDeclarationPtr, $className);
598
  }
689
  if ($namespace !== false) {
690
  return $namespace;
691
  }
692
+ break; // Nested namespaces is not possible.
693
  }
 
694
  }
695
  }
696
 
803
  * @param int $stackPtr The position in the stack of the T_FUNCTION token
804
  * to acquire the parameters for.
805
  *
806
+ * @return array|false
807
  * @throws PHP_CodeSniffer_Exception If the specified $stackPtr is not of
808
  * type T_FUNCTION.
809
  */
953
 
954
  }//end getMethodParameters()
955
 
956
+
957
+ /**
958
+ * Get the hash algorithm name from the parameter in a hash function call.
959
+ *
960
+ * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile.
961
+ * @param int $stackPtr The position of the T_STRING function token.
962
+ *
963
+ * @return string|false The algorithm name without quotes if this was a relevant hash
964
+ * function call or false if it was not.
965
+ */
966
+ public function getHashAlgorithmParameter(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
967
+ {
968
+ $tokens = $phpcsFile->getTokens();
969
+
970
+ // Check for the existence of the token.
971
+ if (isset($tokens[$stackPtr]) === false) {
972
+ return false;
973
+ }
974
+
975
+ if ($tokens[$stackPtr]['code'] !== T_STRING) {
976
+ return false;
977
+ }
978
+
979
+ $functionName = $tokens[$stackPtr]['content'];
980
+ $functionNameLc = strtolower($functionName);
981
+
982
+ // Bow out if not one of the functions we're targetting.
983
+ if (isset($this->hashAlgoFunctions[$functionNameLc]) === false) {
984
+ return false;
985
+ }
986
+
987
+ // Get the parameter from the function call which should contain the algorithm name.
988
+ $algoParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->hashAlgoFunctions[$functionNameLc]);
989
+ if ($algoParam === false) {
990
+ return false;
991
+ }
992
+
993
+ /**
994
+ * Algorithm is a T_CONSTANT_ENCAPSED_STRING, so we need to remove the quotes.
995
+ */
996
+ $algo = strtolower(trim($algoParam['raw']));
997
+ $algo = $this->stripQuotes($algo);
998
+
999
+ return $algo;
1000
+ }
1001
+
1002
  }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ConstantArraysUsingDefineSniff.php CHANGED
@@ -44,6 +44,10 @@ class PHPCompatibility_Sniffs_PHP_ConstantArraysUsingDefineSniff extends PHPComp
44
  */
45
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
  {
 
 
 
 
47
  $tokens = $phpcsFile->getTokens();
48
 
49
  $ignore = array(
@@ -60,28 +64,18 @@ class PHPCompatibility_Sniffs_PHP_ConstantArraysUsingDefineSniff extends PHPComp
60
  }
61
 
62
  $function = strtolower($tokens[$stackPtr]['content']);
 
 
 
63
 
64
- if ($function === 'define') {
65
- $openParenthesis = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, null, null, null, true);
66
- if ($openParenthesis === false) {
67
- return;
68
- }
69
-
70
- $comma = $phpcsFile->findNext(T_COMMA, $openParenthesis, $tokens[$openParenthesis]['parenthesis_closer']);
71
-
72
- if ($comma === false) {
73
- return;
74
- }
75
-
76
- $array = $phpcsFile->findNext(array(T_ARRAY, T_OPEN_SHORT_ARRAY), $comma, $tokens[$openParenthesis]['parenthesis_closer']);
77
 
78
- if ($array !== false) {
79
- if ($this->supportsAbove('7.0')) {
80
- return;
81
- } else {
82
- $phpcsFile->addError('Constant arrays using define are not allowed in PHP 5.6 or earlier', $array);
83
- }
84
- }
85
  }
86
  }
87
  }
44
  */
45
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
  {
47
+ if ($this->supportsBelow('5.6') !== true) {
48
+ return;
49
+ }
50
+
51
  $tokens = $phpcsFile->getTokens();
52
 
53
  $ignore = array(
64
  }
65
 
66
  $function = strtolower($tokens[$stackPtr]['content']);
67
+ if ($function !== 'define') {
68
+ return;
69
+ }
70
 
71
+ $secondParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 2);
72
+ if (isset($secondParam['start'], $secondParam['end']) === false) {
73
+ return;
74
+ }
 
 
 
 
 
 
 
 
 
75
 
76
+ $array = $phpcsFile->findNext(array(T_ARRAY, T_OPEN_SHORT_ARRAY), $secondParam['start'], ($secondParam['end'] + 1));
77
+ if ($array !== false) {
78
+ $phpcsFile->addError('Constant arrays using define are not allowed in PHP 5.6 or earlier', $array);
 
 
 
 
79
  }
80
  }
81
  }
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/DeprecatedFunctionsSniff.php CHANGED
@@ -18,14 +18,6 @@
18
  */
19
  class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibility_Sniff
20
  {
21
-
22
- /**
23
- * If true, forbidden functions will be considered regular expressions.
24
- *
25
- * @var bool
26
- */
27
- protected $patternMatch = false;
28
-
29
  /**
30
  * A list of forbidden functions with their alternatives.
31
  *
@@ -636,6 +628,15 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibil
636
  ),
637
  );
638
 
 
 
 
 
 
 
 
 
 
639
  /**
640
  * Returns an array of tokens this test wants to listen for.
641
  *
@@ -647,12 +648,6 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibil
647
  // they want to check for, so now we can cache out the list.
648
  $this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions);
649
 
650
- if ($this->patternMatch === true) {
651
- foreach ($this->forbiddenFunctionNames as $i => $name) {
652
- $this->forbiddenFunctionNames[$i] = '/'.$name.'/i';
653
- }
654
- }
655
-
656
  return array(T_STRING);
657
 
658
  }//end register()
@@ -687,31 +682,12 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibil
687
  }
688
 
689
  $function = strtolower($tokens[$stackPtr]['content']);
690
- $pattern = null;
691
-
692
- if ($this->patternMatch === true) {
693
- $count = 0;
694
- $pattern = preg_replace(
695
- $this->forbiddenFunctionNames,
696
- $this->forbiddenFunctionNames,
697
- $function,
698
- 1,
699
- $count
700
- );
701
-
702
- if ($count === 0) {
703
- return;
704
- }
705
 
706
- // Remove the pattern delimiters and modifier.
707
- $pattern = substr($pattern, 1, -2);
708
- } else {
709
- if (in_array($function, $this->forbiddenFunctionNames) === false) {
710
- return;
711
- }
712
  }
713
 
714
- $this->addError($phpcsFile, $stackPtr, $function, $pattern);
715
 
716
  }//end process()
717
 
@@ -722,21 +698,16 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibil
722
  * @param int $stackPtr The position of the forbidden function
723
  * in the token array.
724
  * @param string $function The name of the forbidden function.
725
- * @param string $pattern The pattern used for the match.
726
  *
727
  * @return void
728
  */
729
- protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
730
  {
731
- if ($pattern === null) {
732
- $pattern = $function;
733
- }
734
-
735
  $error = '';
736
 
737
  $isError = false;
738
  $previousVersionStatus = null;
739
- foreach ($this->forbiddenFunctions[$pattern] as $version => $forbidden) {
740
  if ($this->supportsAbove($version)) {
741
  if ($version != 'alternative') {
742
  if ($previousVersionStatus !== $forbidden) {
@@ -756,8 +727,8 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibil
756
  $error = 'The use of function ' . $function . ' is ' . $error;
757
  $error = substr($error, 0, strlen($error) - 5);
758
 
759
- if ($this->forbiddenFunctions[$pattern]['alternative'] !== null) {
760
- $error .= '; use ' . $this->forbiddenFunctions[$pattern]['alternative'] . ' instead';
761
  }
762
 
763
  if ($isError === true) {
18
  */
19
  class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibility_Sniff
20
  {
 
 
 
 
 
 
 
 
21
  /**
22
  * A list of forbidden functions with their alternatives.
23
  *
628
  ),
629
  );
630
 
631
+ /**
632
+ * List of just the function names.
633
+ *
634
+ * Will be set automatically in the register() method.
635
+ *
636
+ * @var array
637
+ */
638
+ protected $forbiddenFunctionNames = array();
639
+
640
  /**
641
  * Returns an array of tokens this test wants to listen for.
642
  *
648
  // they want to check for, so now we can cache out the list.
649
  $this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions);
650
 
 
 
 
 
 
 
651
  return array(T_STRING);
652
 
653
  }//end register()
682
  }
683
 
684
  $function = strtolower($tokens[$stackPtr]['content']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
685
 
686
+ if (in_array($function, $this->forbiddenFunctionNames) === false) {
687
+ return;
 
 
 
 
688
  }
689
 
690
+ $this->addError($phpcsFile, $stackPtr, $function);
691
 
692
  }//end process()
693
 
698
  * @param int $stackPtr The position of the forbidden function
699
  * in the token array.
700
  * @param string $function The name of the forbidden function.
 
701
  *
702
  * @return void
703
  */
704
+ protected function addError($phpcsFile, $stackPtr, $function)
705
  {
 
 
 
 
706
  $error = '';
707
 
708
  $isError = false;
709
  $previousVersionStatus = null;
710
+ foreach ($this->forbiddenFunctions[$function] as $version => $forbidden) {
711
  if ($this->supportsAbove($version)) {
712
  if ($version != 'alternative') {
713
  if ($previousVersionStatus !== $forbidden) {
727
  $error = 'The use of function ' . $function . ' is ' . $error;
728
  $error = substr($error, 0, strlen($error) - 5);
729
 
730
+ if ($this->forbiddenFunctions[$function]['alternative'] !== null) {
731
+ $error .= '; use ' . $this->forbiddenFunctions[$function]['alternative'] . ' instead';
732
  }
733
 
734
  if ($isError === true) {
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/DeprecatedIniDirectivesSniff.php CHANGED
@@ -222,12 +222,16 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedIniDirectivesSniff extends PHPCompat
222
  }
223
 
224
  $function = strtolower($tokens[$stackPtr]['content']);
225
- if ($function != 'ini_get' && $function != 'ini_set') {
226
  return;
227
  }
228
 
229
- $iniToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr, null);
230
- $filteredToken = trim($tokens[$iniToken]['content'], '\'"');
 
 
 
 
231
  if (isset($this->deprecatedIniDirectives[$filteredToken]) === false) {
232
  return;
233
  }
@@ -239,7 +243,7 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedIniDirectivesSniff extends PHPCompat
239
  if ($version !== 'alternative') {
240
  if ($this->supportsAbove($version)) {
241
  if ($forbidden === true) {
242
- $isError = ($function != 'ini_get') ?: false;
243
  $error .= " forbidden";
244
  } else {
245
  $isError = false;
@@ -258,9 +262,9 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedIniDirectivesSniff extends PHPCompat
258
  }
259
 
260
  if ($isError === true) {
261
- $phpcsFile->addError($error, $stackPtr);
262
  } else {
263
- $phpcsFile->addWarning($error, $stackPtr);
264
  }
265
  }
266
 
222
  }
223
 
224
  $function = strtolower($tokens[$stackPtr]['content']);
225
+ if ($function !== 'ini_get' && $function !== 'ini_set') {
226
  return;
227
  }
228
 
229
+ $iniToken = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 1);
230
+ if ($iniToken === false) {
231
+ return;
232
+ }
233
+
234
+ $filteredToken = $this->stripQuotes($iniToken['raw']);
235
  if (isset($this->deprecatedIniDirectives[$filteredToken]) === false) {
236
  return;
237
  }
243
  if ($version !== 'alternative') {
244
  if ($this->supportsAbove($version)) {
245
  if ($forbidden === true) {
246
+ $isError = ($function !== 'ini_get') ? true : false;
247
  $error .= " forbidden";
248
  } else {
249
  $isError = false;
262
  }
263
 
264
  if ($isError === true) {
265
+ $phpcsFile->addError($error, $iniToken['end']);
266
  } else {
267
+ $phpcsFile->addWarning($error, $iniToken['end']);
268
  }
269
  }
270
 
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/DeprecatedPHP4StyleConstructorsSniff.php CHANGED
@@ -16,7 +16,8 @@
16
  * @package PHPCompatibility
17
  * @author Koen Eelen <koen.eelen@cu.be>
18
  */
19
- class PHPCompatibility_Sniffs_PHP_DeprecatedPHP4StyleConstructorsSniff extends PHPCompatibility_Sniff {
 
20
 
21
  public function register()
22
  {
@@ -45,7 +46,7 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedPHP4StyleConstructorsSniff extends P
45
 
46
  $class = $tokens[$stackPtr];
47
 
48
- if(!IsSet($class['scope_closer'])) {
49
  return;
50
  }
51
 
@@ -56,28 +57,31 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedPHP4StyleConstructorsSniff extends P
56
  return;
57
  }
58
 
59
- $nextFunc = $stackPtr;
 
60
  $newConstructorFound = false;
61
  $oldConstructorFound = false;
62
- $oldConstructorPos = false;
63
  while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) {
64
  $funcName = $phpcsFile->getDeclarationName($nextFunc);
65
  if (empty($funcName) || is_string($funcName) === false) {
66
  continue;
67
  }
68
 
69
- if ($funcName === '__construct') {
 
 
70
  $newConstructorFound = true;
71
  }
72
 
73
- if ($funcName === $className) {
74
  $oldConstructorFound = true;
75
  $oldConstructorPos = $phpcsFile->findNext(T_STRING, $nextFunc);
76
  }
77
  }
78
 
79
  if ($newConstructorFound === false && $oldConstructorFound === true) {
80
- $phpcsFile->addError('Deprecated PHP4 style constructor are not supported since PHP7', $oldConstructorPos);
81
  }
82
  }
83
  }
16
  * @package PHPCompatibility
17
  * @author Koen Eelen <koen.eelen@cu.be>
18
  */
19
+ class PHPCompatibility_Sniffs_PHP_DeprecatedPHP4StyleConstructorsSniff extends PHPCompatibility_Sniff
20
+ {
21
 
22
  public function register()
23
  {
46
 
47
  $class = $tokens[$stackPtr];
48
 
49
+ if (isset($class['scope_closer']) === false) {
50
  return;
51
  }
52
 
57
  return;
58
  }
59
 
60
+ $nextFunc = $stackPtr;
61
+ $classNameLc = strtolower($className);
62
  $newConstructorFound = false;
63
  $oldConstructorFound = false;
64
+ $oldConstructorPos = -1;
65
  while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) {
66
  $funcName = $phpcsFile->getDeclarationName($nextFunc);
67
  if (empty($funcName) || is_string($funcName) === false) {
68
  continue;
69
  }
70
 
71
+ $funcNameLc = strtolower($funcName);
72
+
73
+ if ($funcNameLc === '__construct') {
74
  $newConstructorFound = true;
75
  }
76
 
77
+ if ($funcNameLc === $classNameLc) {
78
  $oldConstructorFound = true;
79
  $oldConstructorPos = $phpcsFile->findNext(T_STRING, $nextFunc);
80
  }
81
  }
82
 
83
  if ($newConstructorFound === false && $oldConstructorFound === true) {
84
+ $phpcsFile->addError('Use of deprecated PHP4 style class constructor is not supported since PHP 7', $oldConstructorPos);
85
  }
86
  }
87
  }
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/EmptyNonVariableSniff.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * PHPCompatibility_Sniffs_PHP_EmptyNonVariableSniff.
4
+ *
5
+ * PHP version 5.5
6
+ *
7
+ * @category PHP
8
+ * @package PHPCompatibility
9
+ */
10
+
11
+ /**
12
+ * PHPCompatibility_Sniffs_PHP_EmptyNonVariableSniff.
13
+ *
14
+ * Verify that nothing but variables are passed to empty().
15
+ *
16
+ * PHP version 5.5
17
+ *
18
+ * @category PHP
19
+ * @package PHPCompatibility
20
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
21
+ */
22
+ class PHPCompatibility_Sniffs_PHP_EmptyNonVariableSniff extends PHPCompatibility_Sniff
23
+ {
24
+ /**
25
+ * List of tokens to check against.
26
+ *
27
+ * @var array
28
+ */
29
+ protected $tokenBlackList = array();
30
+
31
+ /**
32
+ * List of brackets which can be part of a variable variable.
33
+ *
34
+ * Key is the open bracket token, value the close bracket token.
35
+ *
36
+ * @var array
37
+ */
38
+ protected $bracketTokens = array(
39
+ T_OPEN_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
40
+ T_OPEN_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET,
41
+ );
42
+
43
+
44
+ /**
45
+ * Returns an array of tokens this test wants to listen for.
46
+ *
47
+ * @return array
48
+ */
49
+ public function register()
50
+ {
51
+ // Set the token blacklist only once.
52
+ $tokenBlackList = array_unique(array_merge(
53
+ PHP_CodeSniffer_Tokens::$assignmentTokens,
54
+ PHP_CodeSniffer_Tokens::$equalityTokens,
55
+ PHP_CodeSniffer_Tokens::$comparisonTokens,
56
+ PHP_CodeSniffer_Tokens::$operators,
57
+ PHP_CodeSniffer_Tokens::$booleanOperators,
58
+ PHP_CodeSniffer_Tokens::$castTokens,
59
+ array(T_OPEN_PARENTHESIS, T_STRING_CONCAT)
60
+ ));
61
+ $this->tokenBlackList = array_combine($tokenBlackList, $tokenBlackList);
62
+
63
+ return array(T_EMPTY);
64
+ }
65
+
66
+ /**
67
+ * Processes this test, when one of its tokens is encountered.
68
+ *
69
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
70
+ * @param int $stackPtr The position of the current token in the
71
+ * stack passed in $tokens.
72
+ *
73
+ * @return void
74
+ */
75
+ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
76
+ {
77
+ if ($this->supportsBelow('5.4') === false) {
78
+ return;
79
+ }
80
+
81
+ $tokens = $phpcsFile->getTokens();
82
+
83
+ $open = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true);
84
+ if ($open === false || isset($tokens[$open]['parenthesis_closer']) === false) {
85
+ return;
86
+ }
87
+
88
+ $close = $tokens[$open]['parenthesis_closer'];
89
+
90
+ // If no variable at all was found, then it's definitely a no-no.
91
+ $hasVariable = $phpcsFile->findNext(T_VARIABLE, $open + 1, $close);
92
+ if ($hasVariable === false) {
93
+ $this->addError($phpcsFile, $stackPtr);
94
+ return;
95
+ }
96
+
97
+ // Check if the variable found is at the right level. Deeper levels are always an error.
98
+ if (isset($tokens[$open + 1]['nested_parenthesis'], $tokens[$hasVariable]['nested_parenthesis'])) {
99
+ $nestingLevel = count($tokens[$open + 1]['nested_parenthesis']);
100
+ if (count($tokens[$hasVariable]['nested_parenthesis']) !== $nestingLevel) {
101
+ $this->addError($phpcsFile, $stackPtr);
102
+ return;
103
+ }
104
+ }
105
+
106
+ // Ok, so the first variable is at the right level, now are there any
107
+ // blacklisted tokens within the empty() ?
108
+ $hasBadToken = $phpcsFile->findNext($this->tokenBlackList, $open + 1, $close);
109
+ if ($hasBadToken === false) {
110
+ return;
111
+ }
112
+
113
+ // If there are also bracket tokens, the blacklisted token might be part of a variable
114
+ // variable, but if there are no bracket tokens, we know we have an error.
115
+ $hasBrackets = $phpcsFile->findNext($this->bracketTokens, $open + 1, $close);
116
+ if ($hasBrackets === false) {
117
+ $this->addError($phpcsFile, $stackPtr);
118
+ return;
119
+ }
120
+
121
+ // Ok, we have both a blacklisted token as well as brackets, so we need to walk
122
+ // the tokens of the variable variable.
123
+ for ($i = ($open + 1); $i < $close; $i++) {
124
+ // If this is a bracket token, skip to the end of the bracketed expression.
125
+ if (isset($this->bracketTokens[$tokens[$i]['code']], $tokens[$i]['bracket_closer'])) {
126
+ $i = $tokens[$i]['bracket_closer'];
127
+ continue;
128
+ }
129
+
130
+ // If it's a blacklisted token, not within brackets, we have an error.
131
+ if (isset($this->tokenBlackList[$tokens[$i]['code']])) {
132
+ $this->addError($phpcsFile, $stackPtr);
133
+ return;
134
+ }
135
+ }
136
+ }
137
+
138
+
139
+ /**
140
+ * Add the error message.
141
+ *
142
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
143
+ * @param int $stackPtr The position of the current token in the
144
+ * stack passed in $tokens.
145
+ *
146
+ * @return void
147
+ */
148
+ protected function addError($phpcsFile, $stackPtr)
149
+ {
150
+ $error = 'Only variables can be passed to empty() prior to PHP 5.5.';
151
+ $phpcsFile->addError($error, $stackPtr, 'Found');
152
+ }
153
+ }
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenBreakContinueVariableArgumentsSniff.php CHANGED
@@ -13,7 +13,7 @@
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_ForbiddenBreakContinueVariableArguments.
15
  *
16
- * Discourages the use of assigning the return value of new by reference
17
  *
18
  * PHP version 5.4
19
  *
@@ -24,6 +24,8 @@
24
  */
25
  class PHPCompatibility_Sniffs_PHP_ForbiddenBreakContinueVariableArgumentsSniff extends PHPCompatibility_Sniff
26
  {
 
 
27
 
28
  /**
29
  * Returns an array of tokens this test wants to listen for.
@@ -47,33 +49,42 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenBreakContinueVariableArgumentsSniff e
47
  */
48
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
49
  {
50
- if ($this->supportsAbove('5.4')) {
51
- $tokens = $phpcsFile->getTokens();
52
- $nextSemicolonToken = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr), null, false);
53
- for ($curToken = $stackPtr + 1; $curToken < $nextSemicolonToken; $curToken++) {
54
- $gotError = false;
55
- if ($tokens[$curToken]['type'] == 'T_STRING') {
56
- // If the next non-whitespace token after the string
57
- // is an opening parenthesis then it's a function call.
58
- $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $curToken + 1, null, true);
59
- if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
60
- continue;
61
- } else {
62
- $gotError = true;
63
- }
64
- }
65
- switch ($tokens[$curToken]['type']) {
66
- case 'T_VARIABLE':
67
- case 'T_FUNCTION':
68
- $gotError = true;
69
- break;
70
- }
71
- if ($gotError === true) {
72
- $error = 'Using a variable argument on break or continue is forbidden since PHP 5.4';
73
- $phpcsFile->addError($error, $stackPtr);
74
  }
75
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
 
77
  }//end process()
78
 
79
  }//end class
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_ForbiddenBreakContinueVariableArguments.
15
  *
16
+ * Forbids variable arguments on break or continue statements.
17
  *
18
  * PHP version 5.4
19
  *
24
  */
25
  class PHPCompatibility_Sniffs_PHP_ForbiddenBreakContinueVariableArgumentsSniff extends PHPCompatibility_Sniff
26
  {
27
+ const ERROR_TYPE_VARIABLE = 'a variable argument';
28
+ const ERROR_TYPE_ZERO = '0 as an argument';
29
 
30
  /**
31
  * Returns an array of tokens this test wants to listen for.
49
  */
50
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
51
  {
52
+ if ($this->supportsAbove('5.4') === false) {
53
+ return;
54
+ }
55
+
56
+ $tokens = $phpcsFile->getTokens();
57
+ $nextSemicolonToken = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr), null, false);
58
+ $isError = false;
59
+ $errorType = '';
60
+ for ($curToken = $stackPtr + 1; $curToken < $nextSemicolonToken; $curToken++) {
61
+ if ($tokens[$curToken]['type'] === 'T_STRING') {
62
+ // If the next non-whitespace token after the string
63
+ // is an opening parenthesis then it's a function call.
64
+ $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $curToken + 1, null, true);
65
+ if ($tokens[$openBracket]['code'] === T_OPEN_PARENTHESIS) {
66
+ $isError = true;
67
+ $errorType = self::ERROR_TYPE_VARIABLE;
68
+ break;
 
 
 
 
 
 
 
69
  }
70
  }
71
+ else if (in_array($tokens[$curToken]['type'], array('T_VARIABLE', 'T_FUNCTION', 'T_CLOSURE'), true)) {
72
+ $isError = true;
73
+ $errorType = self::ERROR_TYPE_VARIABLE;
74
+ break;
75
+ }
76
+ else if ($tokens[$curToken]['type'] === 'T_LNUMBER' && $tokens[$curToken]['content'] === '0') {
77
+ $isError = true;
78
+ $errorType = self::ERROR_TYPE_ZERO;
79
+ break;
80
+ }
81
+ }
82
+
83
+ if ($isError === true && !empty($errorType)) {
84
+ $error = 'Using ' . $errorType . ' on break or continue is forbidden since PHP 5.4';
85
+ $phpcsFile->addError($error, $stackPtr);
86
  }
87
+
88
  }//end process()
89
 
90
  }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenCallTimePassByReferenceSniff.php CHANGED
@@ -51,117 +51,157 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenCallTimePassByReferenceSniff extends
51
  */
52
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
53
  {
54
- if ($this->supportsAbove('5.4')) {
55
- $tokens = $phpcsFile->getTokens();
56
-
57
- // Skip tokens that are the names of functions or classes
58
- // within their definitions. For example: function myFunction...
59
- // "myFunction" is T_STRING but we should skip because it is not a
60
- // function or method *call*.
61
- $functionName = $stackPtr;
62
- $findTokens = array_merge(
63
- PHP_CodeSniffer_Tokens::$emptyTokens,
64
- array(T_BITWISE_AND)
65
- );
66
 
67
- $functionKeyword = $phpcsFile->findPrevious(
68
- $findTokens,
69
- ($stackPtr - 1),
70
- null,
71
- true
72
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
- if ($tokens[$functionKeyword]['code'] === T_FUNCTION
75
- || $tokens[$functionKeyword]['code'] === T_CLASS
 
 
76
  ) {
77
- return;
78
  }
79
 
80
- // If the next non-whitespace token after the function or method call
81
- // is not an opening parenthesis then it cant really be a *call*.
82
- $openBracket = $phpcsFile->findNext(
83
  PHP_CodeSniffer_Tokens::$emptyTokens,
84
- ($functionName + 1),
85
- null,
86
  true
87
  );
88
 
89
- if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
90
- return;
 
91
  }
92
 
93
- $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
94
-
95
- $nextSeparator = $openBracket;
96
- while (($nextSeparator = $phpcsFile->findNext(T_VARIABLE, ($nextSeparator + 1), $closeBracket)) !== false) {
97
- // Make sure the variable belongs directly to this function call
98
- // and is not inside a nested function call or array.
99
- if (isset($tokens[$nextSeparator]['nested_parenthesis'])) {
100
- $brackets = $tokens[$nextSeparator]['nested_parenthesis'];
101
- $lastBracket = array_pop($brackets);
102
- if ($lastBracket !== $closeBracket) {
103
- continue;
104
- }
105
- }
 
 
 
 
 
 
 
106
 
107
- // Checking this: $value = my_function(...[*]$arg...).
108
- $tokenBefore = $phpcsFile->findPrevious(
109
- PHP_CodeSniffer_Tokens::$emptyTokens,
110
- ($nextSeparator - 1),
111
- null,
112
- true
113
- );
114
-
115
- if ($tokens[$tokenBefore]['code'] === T_BITWISE_AND) {
116
- // Checking this: $value = my_function(...[*]&$arg...).
117
- $tokenBefore = $phpcsFile->findPrevious(
118
  PHP_CodeSniffer_Tokens::$emptyTokens,
119
  ($tokenBefore - 1),
120
- null,
121
  true
122
  );
123
-
124
- // We have to exclude all uses of T_BITWISE_AND that are not
125
- // references. We use a blacklist approach as we prefer false
126
- // positives to not identifying a pass-by-reference call at all.
127
- // The blacklist may not yet be complete.
128
- switch ($tokens[$tokenBefore]['code']) {
129
- // In these cases T_BITWISE_AND represents
130
- // the bitwise and operator.
131
- case T_LNUMBER:
132
- case T_VARIABLE:
133
- case T_CLOSE_SQUARE_BRACKET:
134
- case T_CLOSE_PARENTHESIS:
135
- continue;
136
-
137
- // Unfortunately the tokenizer fails to recognize global constants,
138
- // class-constants and -attributes. Any of these are returned is
139
- // treated as T_STRING.
140
- // So we step back another token and check if it is a class
141
- // operator (-> or ::), which means we have a false positive.
142
- // Global constants still remain uncovered.
143
- case T_STRING:
144
- $tokenBeforePlus = $phpcsFile->findPrevious(
145
- PHP_CodeSniffer_Tokens::$emptyTokens,
146
- ($tokenBefore - 1),
147
- null,
148
- true
149
- );
150
- if( T_DOUBLE_COLON === $tokens[$tokenBeforePlus]['code'] ||
151
- T_OBJECT_OPERATOR === $tokens[$tokenBeforePlus]['code']
152
- ) {
153
- continue;
154
- }
155
-
156
- default:
157
- // T_BITWISE_AND represents a pass-by-reference.
158
- $error = 'Using a call-time pass-by-reference is prohibited since php 5.4';
159
- $phpcsFile->addError($error, $tokenBefore, 'NotAllowed');
160
- break;
161
  }
162
- }//end if
163
- }//end while
164
- }
165
- }//end process()
 
 
 
 
 
 
 
 
166
 
167
  }//end class
51
  */
52
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
53
  {
54
+ if ($this->supportsAbove('5.3') === false) {
55
+ return;
56
+ }
 
 
 
 
 
 
 
 
 
57
 
58
+ $tokens = $phpcsFile->getTokens();
59
+
60
+ // Skip tokens that are the names of functions or classes
61
+ // within their definitions. For example: function myFunction...
62
+ // "myFunction" is T_STRING but we should skip because it is not a
63
+ // function or method *call*.
64
+ $findTokens = array_merge(
65
+ PHP_CodeSniffer_Tokens::$emptyTokens,
66
+ array(T_BITWISE_AND)
67
+ );
68
+
69
+ $prevNonEmpty = $phpcsFile->findPrevious(
70
+ $findTokens,
71
+ ($stackPtr - 1),
72
+ null,
73
+ true
74
+ );
75
+
76
+ if ($prevNonEmpty !== false && in_array($tokens[$prevNonEmpty]['code'], array(T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT), true)) {
77
+ return;
78
+ }
79
+
80
+ // If the next non-whitespace token after the function or method call
81
+ // is not an opening parenthesis then it can't really be a *call*.
82
+ $openBracket = $phpcsFile->findNext(
83
+ PHP_CodeSniffer_Tokens::$emptyTokens,
84
+ ($stackPtr + 1),
85
+ null,
86
+ true
87
+ );
88
+
89
+ if ($openBracket === false || $tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS
90
+ || isset($tokens[$openBracket]['parenthesis_closer']) === false
91
+ ) {
92
+ return;
93
+ }
94
+
95
+ // Get the function call parameters.
96
+ $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
97
+ if (count($parameters) === 0) {
98
+ return;
99
+ }
100
+
101
+ // Which nesting level is the one we are interested in ?
102
+ $nestedParenthesisCount = 1;
103
+ if (isset($tokens[$openBracket]['nested_parenthesis'])) {
104
+ $nestedParenthesisCount = count($tokens[$openBracket]['nested_parenthesis']) + 1;
105
+ }
106
+
107
+ foreach ($parameters as $parameter) {
108
+ if ($this->isCallTimePassByReferenceParam($phpcsFile, $parameter, $nestedParenthesisCount) === true) {
109
+ // T_BITWISE_AND represents a pass-by-reference.
110
+ $error = 'Using a call-time pass-by-reference is deprecated since PHP 5.3';
111
+ if($this->supportsAbove('5.4')) {
112
+ $error .= ' and prohibited since PHP 5.4';
113
+ }
114
+ $phpcsFile->addError($error, $parameter['start'], 'NotAllowed');
115
+ }
116
+ }
117
+ }//end process()
118
+
119
+
120
+ protected function isCallTimePassByReferenceParam(PHP_CodeSniffer_File $phpcsFile, $parameter, $nestingLevel)
121
+ {
122
+ $tokens = $phpcsFile->getTokens();
123
+
124
+ $searchStartToken = $parameter['start'] - 1;
125
+ $searchEndToken = $parameter['end'] + 1;
126
+ $nextVariable = $searchStartToken;
127
+ do {
128
+ $nextVariable = $phpcsFile->findNext(T_VARIABLE, ($nextVariable + 1), $searchEndToken);
129
+ if ($nextVariable === false) {
130
+ return false;
131
+ }
132
 
133
+ // Make sure the variable belongs directly to this function call
134
+ // and is not inside a nested function call or array.
135
+ if (isset($tokens[$nextVariable]['nested_parenthesis']) === false ||
136
+ (count($tokens[$nextVariable]['nested_parenthesis']) !== $nestingLevel)
137
  ) {
138
+ continue;
139
  }
140
 
141
+
142
+ // Checking this: $value = my_function(...[*]$arg...).
143
+ $tokenBefore = $phpcsFile->findPrevious(
144
  PHP_CodeSniffer_Tokens::$emptyTokens,
145
+ ($nextVariable - 1),
146
+ $searchStartToken,
147
  true
148
  );
149
 
150
+ if ($tokenBefore === false || $tokens[$tokenBefore]['code'] !== T_BITWISE_AND) {
151
+ // Nothing before the token or no &.
152
+ continue;
153
  }
154
 
155
+ // Checking this: $value = my_function(...[*]&$arg...).
156
+ $tokenBefore = $phpcsFile->findPrevious(
157
+ PHP_CodeSniffer_Tokens::$emptyTokens,
158
+ ($tokenBefore - 1),
159
+ $searchStartToken,
160
+ true
161
+ );
162
+
163
+ // We have to exclude all uses of T_BITWISE_AND that are not
164
+ // references. We use a blacklist approach as we prefer false
165
+ // positives to not identifying a pass-by-reference call at all.
166
+ // The blacklist may not yet be complete.
167
+ switch ($tokens[$tokenBefore]['code']) {
168
+ // In these cases T_BITWISE_AND represents
169
+ // the bitwise and operator.
170
+ case T_LNUMBER:
171
+ case T_VARIABLE:
172
+ case T_CLOSE_SQUARE_BRACKET:
173
+ case T_CLOSE_PARENTHESIS:
174
+ break;
175
 
176
+ // Unfortunately the tokenizer fails to recognize global constants,
177
+ // class-constants and -attributes. Any of these are returned is
178
+ // treated as T_STRING.
179
+ // So we step back another token and check if it is a class
180
+ // operator (-> or ::), which means we have a false positive.
181
+ // Global constants still remain uncovered.
182
+ case T_STRING:
183
+ $tokenBeforePlus = $phpcsFile->findPrevious(
 
 
 
184
  PHP_CodeSniffer_Tokens::$emptyTokens,
185
  ($tokenBefore - 1),
186
+ $searchStartToken,
187
  true
188
  );
189
+ if ($tokens[$tokenBeforePlus]['code'] === T_DOUBLE_COLON ||
190
+ $tokens[$tokenBeforePlus]['code'] === T_OBJECT_OPERATOR
191
+ ) {
192
+ break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  }
194
+ // If not a class constant: fall through.
195
+
196
+ default:
197
+ // The found T_BITWISE_AND represents a pass-by-reference.
198
+ return true;
199
+ }
200
+
201
+ } while($nextVariable < $searchEndToken);
202
+
203
+ // This code should never be reached, but here in case of weird bugs ;-)
204
+ return false;
205
+ }
206
 
207
  }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenFunctionParametersWithSameNameSniff.php CHANGED
@@ -45,24 +45,33 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenFunctionParametersWithSameNameSniff e
45
  */
46
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
47
  {
48
- if ($this->supportsAbove('7.0')) {
49
- $tokens = $phpcsFile->getTokens();
50
- $token = $tokens[$stackPtr];
51
- // Skip function without body.
52
- if (isset($token['scope_opener']) === false) {
53
- return;
54
- }
 
 
 
 
 
 
 
 
 
 
55
 
56
- // Get all parameters from method signature.
57
- $paramNames = array();
58
- foreach ($phpcsFile->getMethodParameters($stackPtr) as $param) {
59
- $paramNames[] = strtolower($param['name']);
60
- }
61
 
62
- if (count($paramNames) != count(array_unique($paramNames))) {
63
- $phpcsFile->addError('Functions can not have multiple parameters with the same name since PHP 7.0', $stackPtr);
64
- }
65
  }
 
66
  }//end process()
67
 
68
  }//end class
45
  */
46
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
47
  {
48
+ if ($this->supportsAbove('7.0') === false) {
49
+ return;
50
+ }
51
+
52
+ $tokens = $phpcsFile->getTokens();
53
+ $token = $tokens[$stackPtr];
54
+ // Skip function without body.
55
+ if (isset($token['scope_opener']) === false) {
56
+ return;
57
+ }
58
+
59
+ // Get all parameters from method signature.
60
+ $parameters = $phpcsFile->getMethodParameters($stackPtr);
61
+ if (empty($parameters) || is_array($parameters) === false) {
62
+ return;
63
+ }
64
+
65
 
66
+ $paramNames = array();
67
+ foreach ($parameters as $param) {
68
+ $paramNames[] = strtolower($param['name']);
69
+ }
 
70
 
71
+ if (count($paramNames) != count(array_unique($paramNames))) {
72
+ $phpcsFile->addError('Functions can not have multiple parameters with the same name since PHP 7.0', $stackPtr);
 
73
  }
74
+
75
  }//end process()
76
 
77
  }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenGlobalVariableVariableSniff.php CHANGED
@@ -50,9 +50,7 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenGlobalVariableVariableSniff extends P
50
  $variable = $phpcsFile->findNext(T_VARIABLE, $stackPtr, $stackPtr + 4, false);
51
 
52
  if (isset($tokens[$variable - 1]) && $tokens[$variable - 1]['type'] == 'T_DOLLAR') {
53
- $error = sprintf(
54
- "Global with variable variables are not allowed since PHP 7.0"
55
- );
56
  $phpcsFile->addError($error, $stackPtr);
57
  }
58
  }
50
  $variable = $phpcsFile->findNext(T_VARIABLE, $stackPtr, $stackPtr + 4, false);
51
 
52
  if (isset($tokens[$variable - 1]) && $tokens[$variable - 1]['type'] == 'T_DOLLAR') {
53
+ $error = 'Global with variable variables is not allowed since PHP 7.0';
 
 
54
  $phpcsFile->addError($error, $stackPtr);
55
  }
56
  }
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenNamesAsInvokedFunctionsSniff.php CHANGED
@@ -13,7 +13,7 @@
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_ForbiddenNamesAsInvokedFunctionsSniff.
15
  *
16
- * Prohibits the use of reserved keywords invoked as functions
17
  *
18
  * PHP version 5.4
19
  *
@@ -26,7 +26,7 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesAsInvokedFunctionsSniff extends
26
  {
27
 
28
  /**
29
- * List of tokens to register
30
  *
31
  * @var array
32
  */
@@ -54,11 +54,16 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesAsInvokedFunctionsSniff extends
54
  );
55
 
56
  /**
57
- * targetedStringTokens
 
 
 
58
  *
59
  * @var array
60
  */
61
  protected $targetedStringTokens = array(
 
 
62
  'callable' => '5.4',
63
  'insteadof' => '5.4',
64
  'trait' => '5.4',
@@ -80,10 +85,10 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesAsInvokedFunctionsSniff extends
80
  */
81
  public function register()
82
  {
83
- return array_merge(
84
- array(T_STRING),
85
- array_keys($this->targetedTokens)
86
- );
87
  }//end register()
88
 
89
  /**
@@ -97,65 +102,60 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesAsInvokedFunctionsSniff extends
97
  */
98
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
99
  {
100
- $tokens = $phpcsFile->getTokens();
101
- $isString = false;
 
 
102
 
103
  // For string tokens we only care if the string is a reserved word used
104
  // as a function. This only happens in older versions of PHP where the
105
  // token doesn't exist yet for that keyword.
106
- if ($tokens[$stackPtr]['code'] == T_STRING
107
- && (!in_array($tokens[$stackPtr]['content'], array_keys($this->targetedStringTokens)))
108
  ) {
109
  return;
110
  }
111
 
112
- if ($tokens[$stackPtr]['code'] == T_STRING) {
113
  $isString = true;
114
  }
115
 
116
  // Make sure this is a function call.
117
- $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
118
- if ($next === false) {
119
  // Not a function call.
120
  return;
121
  }
122
 
123
- if ($tokens[$next]['code'] == T_OPEN_PARENTHESIS) {
124
- $prev = $phpcsFile->findPrevious(array(T_WHITESPACE, T_COMMENT), ($stackPtr - 1), null, true);
 
 
 
125
 
126
- // This sniff isn't concerned about function declaration
127
- if ($tokens[$prev]['code'] == T_FUNCTION) {
 
 
 
128
  return;
129
  }
 
130
 
131
- // For the word catch, it is valid to have an open parenthesis
132
- // after it, but only if it is preceded by a right curly brace
133
- if ($tokens[$stackPtr]['code'] == T_CATCH) {
134
- if ($prev !== false) {
135
- if ($tokens[$prev]['code'] == T_CLOSE_CURLY_BRACKET) {
136
- // Ok, it's fine
137
- return;
138
- }
139
- }
140
- }
141
-
142
- $content = $tokens[$stackPtr]['content'];
143
- $tokenCode = $tokens[$stackPtr]['code'];
144
- if ($isString) {
145
- $version = $this->targetedStringTokens[$content];
146
- } else {
147
- $version = $this->targetedTokens[$tokenCode];
148
- }
149
 
150
- if ($this->supportsAbove($version)) {
151
- $error = sprintf(
152
- "'%s' is a reserved keyword introduced in PHP version %s and cannot be invoked as a function (%s)",
153
- strtolower($content),
154
- $version,
155
- $tokens[$stackPtr]['type']
156
- );
157
- $phpcsFile->addError($error, $stackPtr);
158
- }
159
  }
160
  }//end process()
161
 
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_ForbiddenNamesAsInvokedFunctionsSniff.
15
  *
16
+ * Prohibits the use of reserved keywords invoked as functions.
17
  *
18
  * PHP version 5.4
19
  *
26
  {
27
 
28
  /**
29
+ * List of tokens to register.
30
  *
31
  * @var array
32
  */
54
  );
55
 
56
  /**
57
+ * T_STRING keywords to recognize as targetted tokens.
58
+ *
59
+ * Compatibility for PHP versions where the keyword is not yet recognized
60
+ * as its own token.
61
  *
62
  * @var array
63
  */
64
  protected $targetedStringTokens = array(
65
+ 'goto' => '5.3',
66
+ 'namespace' => '5.3',
67
  'callable' => '5.4',
68
  'insteadof' => '5.4',
69
  'trait' => '5.4',
85
  */
86
  public function register()
87
  {
88
+ $tokens = array_keys($this->targetedTokens);
89
+ $tokens[] = T_STRING;
90
+
91
+ return $tokens;
92
  }//end register()
93
 
94
  /**
102
  */
103
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
104
  {
105
+ $tokens = $phpcsFile->getTokens();
106
+ $tokenCode = $tokens[$stackPtr]['code'];
107
+ $tokenContentLc = strtolower($tokens[$stackPtr]['content']);
108
+ $isString = false;
109
 
110
  // For string tokens we only care if the string is a reserved word used
111
  // as a function. This only happens in older versions of PHP where the
112
  // token doesn't exist yet for that keyword.
113
+ if ($tokenCode === T_STRING
114
+ && (isset($this->targetedStringTokens[$tokenContentLc]) === false)
115
  ) {
116
  return;
117
  }
118
 
119
+ if ($tokenCode === T_STRING) {
120
  $isString = true;
121
  }
122
 
123
  // Make sure this is a function call.
124
+ $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
125
+ if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS) {
126
  // Not a function call.
127
  return;
128
  }
129
 
130
+ // This sniff isn't concerned about function declaration.
131
+ $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
132
+ if ($prev !== false && $tokens[$prev]['code'] === T_FUNCTION) {
133
+ return;
134
+ }
135
 
136
+ // For the word catch, it is valid to have an open parenthesis
137
+ // after it, but only if it is preceded by a right curly brace.
138
+ if ($tokenCode === T_CATCH) {
139
+ if ($prev !== false && $tokens[$prev]['code'] === T_CLOSE_CURLY_BRACKET) {
140
+ // Ok, it's fine
141
  return;
142
  }
143
+ }
144
 
145
+ if ($isString) {
146
+ $version = $this->targetedStringTokens[$tokenContentLc];
147
+ } else {
148
+ $version = $this->targetedTokens[$tokenCode];
149
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
+ if ($this->supportsAbove($version)) {
152
+ $error = "'%s' is a reserved keyword introduced in PHP version %s and cannot be invoked as a function (%s)";
153
+ $data = array(
154
+ $tokenContentLc,
155
+ $version,
156
+ $tokens[$stackPtr]['type'],
157
+ );
158
+ $phpcsFile->addError($error, $stackPtr, 'Found', $data);
 
159
  }
160
  }//end process()
161
 
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenNamesSniff.php CHANGED
@@ -13,7 +13,7 @@
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff.
15
  *
16
- * Prohibits the use of reserved keywords as class, function, namespace or constant names
17
  *
18
  * PHP version 5.4
19
  *
@@ -26,8 +26,8 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_S
26
  {
27
 
28
  /**
29
- * A list of keywords that can not be used as function, class and namespace name or constant name
30
- * Mentions since which version it's not allowed
31
  *
32
  * @var array(string => string)
33
  */
@@ -104,13 +104,12 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_S
104
 
105
  /**
106
  * A list of keywords that can follow use statements.
107
- * Mentions since which version it's not allowed
108
  *
109
  * @var array(string => string)
110
  */
111
  protected $validUseNames = array(
112
- 'const',
113
- 'function',
114
  );
115
 
116
  /**
@@ -118,7 +117,18 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_S
118
  *
119
  * @var array
120
  */
121
- protected $targetedTokens = array(T_CLASS, T_FUNCTION, T_NAMESPACE, T_STRING, T_CONST, T_USE, T_AS, T_EXTENDS, T_TRAIT);
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  /**
124
  * Returns an array of tokens this test wants to listen for.
@@ -148,9 +158,9 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_S
148
  $tokens = $phpcsFile->getTokens();
149
 
150
  /**
151
- * We distinguish between the class, function and namespace names or the define statements
152
  */
153
- if ($tokens[$stackPtr]['type'] == 'T_STRING') {
154
  $this->processString($phpcsFile, $stackPtr, $tokens);
155
  } else {
156
  $this->processNonString($phpcsFile, $stackPtr, $tokens);
@@ -170,28 +180,43 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_S
170
  */
171
  public function processNonString(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
172
  {
173
- if (in_array(strtolower($tokens[$stackPtr + 2]['content']), array_keys($this->invalidNames)) === false) {
 
 
 
 
 
 
174
  return;
175
  }
176
 
177
- // PHP 5.6 allows for use const and use function
178
  if ($this->supportsAbove('5.6')
179
- && $tokens[$stackPtr]['type'] == 'T_USE'
180
- && in_array(strtolower($tokens[$stackPtr + 2]['content']), $this->validUseNames)
181
  ) {
182
  return;
183
  }
184
 
185
- if (isset($tokens[$stackPtr - 2]) && $tokens[$stackPtr - 2]['type'] == 'T_NEW' && $tokens[$stackPtr - 1]['type'] == 'T_WHITESPACE' && $tokens[$stackPtr]['type'] == 'T_ANON_CLASS') {
 
 
 
 
 
186
  return;
187
  }
188
 
189
- if ($this->supportsAbove($this->invalidNames[strtolower($tokens[$stackPtr + 2]['content'])])) {
190
- $error = "Function name, class name, namespace name or constant name can not be reserved keyword '" . $tokens[$stackPtr + 2]['content'] . "' (since version " . $this->invalidNames[strtolower($tokens[$stackPtr + 2]['content'])] . ")";
191
- $phpcsFile->addError($error, $stackPtr);
 
 
 
 
192
  }
193
 
194
- }//end process()
195
 
196
  /**
197
  * Processes this test, when one of its tokens is encountered.
@@ -206,35 +231,36 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_S
206
  */
207
  public function processString(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
208
  {
 
 
209
  // Special case for 5.3 where we want to find usage of traits, but
210
  // trait is not a token.
211
- if ($tokens[$stackPtr]['content'] == 'trait') {
212
  return $this->processNonString($phpcsFile, $stackPtr, $tokens);
213
  }
214
 
215
- // Look for any define/defined token (both T_STRING ones, blame Tokenizer)
216
- if ($tokens[$stackPtr]['content'] != 'define' && $tokens[$stackPtr]['content'] != 'defined') {
217
  return;
218
  }
219
 
220
- // Look for the end of the define/defined
221
- $closingParenthesis = $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr);
222
- if ($closingParenthesis === false) {
223
  return;
224
  }
225
 
226
- // Look for define name between current position and end of define/defined
227
- $defineContent = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr, $closingParenthesis);
228
- if ($defineContent === false) {
229
- return;
230
- }
231
 
232
- foreach ($this->invalidNames as $key => $value) {
233
- if (substr(strtolower($tokens[$defineContent]['content']), 1, -1) == $key) {
234
- $error = "Function name, class name, namespace name or constant name can not be reserved keyword '" . $key . "' (since version " . $value . ")";
235
- $phpcsFile->addError($error, $stackPtr);
236
- }
 
 
237
  }
238
- }//end process()
239
 
240
  }//end class
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff.
15
  *
16
+ * Prohibits the use of reserved keywords as class, function, namespace or constant names.
17
  *
18
  * PHP version 5.4
19
  *
26
  {
27
 
28
  /**
29
+ * A list of keywords that can not be used as function, class and namespace name or constant name.
30
+ * Mentions since which version it's not allowed.
31
  *
32
  * @var array(string => string)
33
  */
104
 
105
  /**
106
  * A list of keywords that can follow use statements.
 
107
  *
108
  * @var array(string => string)
109
  */
110
  protected $validUseNames = array(
111
+ 'const' => true,
112
+ 'function' => true,
113
  );
114
 
115
  /**
117
  *
118
  * @var array
119
  */
120
+ protected $targetedTokens = array(
121
+ T_CLASS,
122
+ T_FUNCTION,
123
+ T_NAMESPACE,
124
+ T_STRING,
125
+ T_CONST,
126
+ T_USE,
127
+ T_AS,
128
+ T_EXTENDS,
129
+ T_TRAIT,
130
+ T_INTERFACE,
131
+ );
132
 
133
  /**
134
  * Returns an array of tokens this test wants to listen for.
158
  $tokens = $phpcsFile->getTokens();
159
 
160
  /**
161
+ * We distinguish between the class, function and namespace names or the define statements.
162
  */
163
+ if ($tokens[$stackPtr]['type'] === 'T_STRING') {
164
  $this->processString($phpcsFile, $stackPtr, $tokens);
165
  } else {
166
  $this->processNonString($phpcsFile, $stackPtr, $tokens);
180
  */
181
  public function processNonString(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
182
  {
183
+ $nextNonEmpty = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
184
+ if ($nextNonEmpty === false) {
185
+ return;
186
+ }
187
+
188
+ $nextContentLc = strtolower($tokens[$nextNonEmpty]['content']);
189
+ if (isset($this->invalidNames[$nextContentLc]) === false) {
190
  return;
191
  }
192
 
193
+ // PHP 5.6 allows for use const and use function.
194
  if ($this->supportsAbove('5.6')
195
+ && $tokens[$stackPtr]['type'] === 'T_USE'
196
+ && isset($this->validUseNames[$nextContentLc]) === true
197
  ) {
198
  return;
199
  }
200
 
201
+ // Deal with anonymous classes.
202
+ $prevNonEmpty = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
203
+ if ($prevNonEmpty !== false
204
+ && $tokens[$prevNonEmpty]['type'] === 'T_NEW'
205
+ && $tokens[$stackPtr]['type'] === 'T_ANON_CLASS'
206
+ ) {
207
  return;
208
  }
209
 
210
+ if ($this->supportsAbove($this->invalidNames[$nextContentLc])) {
211
+ $error = "Function name, class name, namespace name or constant name can not be reserved keyword '%s' (since version %s)";
212
+ $data = array(
213
+ $tokens[$nextNonEmpty]['content'],
214
+ $this->invalidNames[$nextContentLc],
215
+ );
216
+ $phpcsFile->addError($error, $stackPtr, 'Found', $data);
217
  }
218
 
219
+ }//end processNonString()
220
 
221
  /**
222
  * Processes this test, when one of its tokens is encountered.
231
  */
232
  public function processString(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
233
  {
234
+ $tokenContentLc = strtolower($tokens[$stackPtr]['content']);
235
+
236
  // Special case for 5.3 where we want to find usage of traits, but
237
  // trait is not a token.
238
+ if ($tokenContentLc === 'trait') {
239
  return $this->processNonString($phpcsFile, $stackPtr, $tokens);
240
  }
241
 
242
+ // Look for any define/defined tokens (both T_STRING ones, blame Tokenizer).
243
+ if ($tokenContentLc !== 'define' && $tokenContentLc !== 'defined') {
244
  return;
245
  }
246
 
247
+ // Retrieve the define(d) constant name.
248
+ $firstParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 1);
249
+ if ($firstParam === false) {
250
  return;
251
  }
252
 
253
+ $defineName = strtolower($firstParam['raw']);
254
+ $defineName = $this->stripQuotes($defineName);
 
 
 
255
 
256
+ if (isset($this->invalidNames[$defineName]) && $this->supportsAbove($this->invalidNames[$defineName])) {
257
+ $error = "Function name, class name, namespace name or constant name can not be reserved keyword '%s' (since PHP version %s)";
258
+ $data = array(
259
+ $defineName,
260
+ $this->invalidNames[$defineName],
261
+ );
262
+ $phpcsFile->addError($error, $stackPtr, 'Found', $data);
263
  }
264
+ }//end processString()
265
 
266
  }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ForbiddenNegativeBitshiftSniff.php CHANGED
@@ -12,7 +12,7 @@
12
  /**
13
  * PHPCompatibility_Sniffs_PHP_ForbiddenNegativeBitshift.
14
  *
15
- * Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0
16
  *
17
  * @category PHP
18
  * @package PHPCompatibility
@@ -43,15 +43,23 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNegativeBitshiftSniff extends PHPComp
43
  */
44
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
45
  {
46
- if ($this->supportsAbove('7.0')) {
47
- $tokens = $phpcsFile->getTokens();
48
-
49
- $nextNumber = $phpcsFile->findNext(T_LNUMBER, $stackPtr, null, false, null, true);
50
- if ($tokens[$nextNumber - 1]['code'] == T_MINUS) {
51
- $error = 'Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0';
52
- $phpcsFile->addError($error, $nextNumber - 1);
53
- }
54
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }//end process()
56
 
57
  }//end class
12
  /**
13
  * PHPCompatibility_Sniffs_PHP_ForbiddenNegativeBitshift.
14
  *
15
+ * Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0.
16
  *
17
  * @category PHP
18
  * @package PHPCompatibility
43
  */
44
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
45
  {
46
+ if ($this->supportsAbove('7.0') === false) {
47
+ return;
 
 
 
 
 
 
48
  }
49
+
50
+ $nextNumber = $phpcsFile->findNext(T_LNUMBER, $stackPtr + 1, null, false, null, true);
51
+ if($nextNumber === false || ($stackPtr + 1) === $nextNumber) {
52
+ return;
53
+ }
54
+
55
+ $hasMinusSign = $phpcsFile->findNext(T_MINUS, $stackPtr + 1, $nextNumber, false, null, true);
56
+ if($hasMinusSign === false) {
57
+ return;
58
+ }
59
+
60
+ $error = 'Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0';
61
+ $phpcsFile->addError($error, $hasMinusSign);
62
+
63
  }//end process()
64
 
65
  }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/MbstringReplaceEModifierSniff.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * PHPCompatibility_Sniffs_PHP_MbstringReplaceEModifierSniff.
4
+ *
5
+ * PHP version 7.1
6
+ *
7
+ * @category PHP
8
+ * @package PHPCompatibility
9
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
10
+ */
11
+
12
+ /**
13
+ * PHPCompatibility_Sniffs_PHP_MbstringReplaceEModifierSniff.
14
+ *
15
+ * @category PHP
16
+ * @package PHPCompatibility
17
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
18
+ */
19
+ class PHPCompatibility_Sniffs_PHP_MbstringReplaceEModifierSniff extends PHPCompatibility_Sniff
20
+ {
21
+
22
+ /**
23
+ * Functions to check for.
24
+ *
25
+ * Key is the function name, value the parameter position of the options parameter.
26
+ *
27
+ * @var array
28
+ */
29
+ protected $functions = array(
30
+ 'mb_ereg_replace' => 4,
31
+ 'mb_eregi_replace' => 4,
32
+ 'mb_regex_set_options' => 1,
33
+ );
34
+
35
+
36
+ /**
37
+ * Returns an array of tokens this test wants to listen for.
38
+ *
39
+ * @return array
40
+ */
41
+ public function register()
42
+ {
43
+ return array(T_STRING);
44
+ }//end register()
45
+
46
+
47
+ /**
48
+ * Processes this test, when one of its tokens is encountered.
49
+ *
50
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
51
+ * @param int $stackPtr The position of the current token in the
52
+ * stack passed in $tokens.
53
+ *
54
+ * @return void
55
+ */
56
+ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
57
+ {
58
+ if ($this->supportsAbove('7.1') === false) {
59
+ return;
60
+ }
61
+
62
+ $tokens = $phpcsFile->getTokens();
63
+ $functionNameLc = strtolower($tokens[$stackPtr]['content']);
64
+
65
+ // Bow out if not one of the functions we're targetting.
66
+ if ( isset($this->functions[$functionNameLc]) === false ) {
67
+ return;
68
+ }
69
+
70
+ // Get the options parameter in the function call.
71
+ $optionsParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->functions[$functionNameLc]);
72
+ if ($optionsParam === false) {
73
+ return;
74
+ }
75
+
76
+ $stringToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $optionsParam['start'], $optionsParam['end'] + 1);
77
+ if ($stringToken === false) {
78
+ // No string token found in the options parameter, so skip it (e.g. variable passed in).
79
+ return;
80
+ }
81
+
82
+ /**
83
+ * Get the content of any string tokens in the options parameter and remove the quotes.
84
+ */
85
+ $options = $this->stripQuotes($tokens[$stringToken]['content']);
86
+ if ($stringToken !== $optionsParam['end']) {
87
+ while ($stringToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stringToken + 1, $optionsParam['end'] + 1)) {
88
+ if ($tokens[$stringToken]['code'] === T_CONSTANT_ENCAPSED_STRING) {
89
+ $options .= $this->stripQuotes($tokens[$stringToken]['content']);
90
+ }
91
+ }
92
+ }
93
+
94
+ if (strpos($options, 'e') !== false) {
95
+ $error = 'The Mbstring regex "e" modifier is deprecated since PHP 7.1.';
96
+
97
+ // The alternative mb_ereg_replace_callback() function is only available since 5.4.1
98
+ if ($this->supportsBelow('5.4.1') === false) {
99
+ $error .= ' Use mb_ereg_replace_callback() instead (PHP 5.4.1+).';
100
+ }
101
+
102
+ $phpcsFile->addError($error, $stackPtr, 'Found');
103
+ }
104
+
105
+ }//end process()
106
+
107
+ }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewAnonymousClassesSniff.php CHANGED
@@ -46,17 +46,18 @@ class PHPCompatibility_Sniffs_PHP_NewAnonymousClassesSniff extends PHPCompatibil
46
  */
47
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
48
  {
 
 
 
 
49
  $whitespace = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, $stackPtr + 2);
50
  $class = $phpcsFile->findNext(T_ANON_CLASS, $stackPtr + 2, $stackPtr + 3);
51
  if ($whitespace === false || $class === false) {
52
  return;
53
  }
54
 
55
- if ($this->supportsAbove('7.0')) {
56
- return;
57
- } else {
58
- $phpcsFile->addError('Anonymous classes are not supported in PHP 5.6 or earlier', $stackPtr);
59
- }
60
  }//end process()
61
 
62
 
46
  */
47
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
48
  {
49
+ if ($this->supportsBelow('5.6') === false) {
50
+ return;
51
+ }
52
+
53
  $whitespace = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, $stackPtr + 2);
54
  $class = $phpcsFile->findNext(T_ANON_CLASS, $stackPtr + 2, $stackPtr + 3);
55
  if ($whitespace === false || $class === false) {
56
  return;
57
  }
58
 
59
+ $phpcsFile->addError('Anonymous classes are not supported in PHP 5.6 or earlier', $stackPtr);
60
+
 
 
 
61
  }//end process()
62
 
63
 
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewClassesSniff.php CHANGED
@@ -193,6 +193,11 @@ class PHPCompatibility_Sniffs_PHP_NewClassesSniff extends PHPCompatibility_Sniff
193
  */
194
  public function register()
195
  {
 
 
 
 
 
196
  return array(
197
  T_NEW,
198
  T_CLASS,
@@ -234,9 +239,10 @@ class PHPCompatibility_Sniffs_PHP_NewClassesSniff extends PHPCompatibility_Sniff
234
  return;
235
  }
236
 
237
- $className = substr($FQClassName, 1); // Remove global namespace indicator.
 
238
 
239
- if (array_key_exists($className, $this->newClasses) === false) {
240
  return;
241
  }
242
 
@@ -252,20 +258,16 @@ class PHPCompatibility_Sniffs_PHP_NewClassesSniff extends PHPCompatibility_Sniff
252
  * @param int $stackPtr The position of the function
253
  * in the token array.
254
  * @param string $className The name of the class.
255
- * @param string $pattern The pattern used for the match.
256
  *
257
  * @return void
258
  */
259
- protected function addError($phpcsFile, $stackPtr, $className, $pattern=null)
260
  {
261
- if ($pattern === null) {
262
- $pattern = $className;
263
- }
264
-
265
- $error = '';
266
 
267
- $isError = false;
268
- foreach ($this->newClasses[$pattern] as $version => $present) {
269
  if ($this->supportsBelow($version)) {
270
  if ($present === false) {
271
  $isError = true;
193
  */
194
  public function register()
195
  {
196
+ // Handle case-insensitivity of class names.
197
+ $keys = array_keys( $this->newClasses );
198
+ $keys = array_map( 'strtolower', $keys );
199
+ $this->newClasses = array_combine( $keys, $this->newClasses );
200
+
201
  return array(
202
  T_NEW,
203
  T_CLASS,
239
  return;
240
  }
241
 
242
+ $className = substr($FQClassName, 1); // Remove global namespace indicator.
243
+ $classNameLc = strtolower($className);
244
 
245
+ if (isset($this->newClasses[$classNameLc]) === false) {
246
  return;
247
  }
248
 
258
  * @param int $stackPtr The position of the function
259
  * in the token array.
260
  * @param string $className The name of the class.
 
261
  *
262
  * @return void
263
  */
264
+ protected function addError($phpcsFile, $stackPtr, $className)
265
  {
266
+ $error = '';
267
+ $isError = false;
268
+ $classNameLc = strtolower($className);
 
 
269
 
270
+ foreach ($this->newClasses[$classNameLc] as $version => $present) {
 
271
  if ($this->supportsBelow($version)) {
272
  if ($present === false) {
273
  $isError = true;
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewExecutionDirectivesSniff.php CHANGED
@@ -123,7 +123,7 @@ class PHPCompatibility_Sniffs_PHP_NewExecutionDirectivesSniff extends PHPCompati
123
  return;
124
  }
125
 
126
- $this->addErrorOnInvalidValue($phpcsFile, $valuePtr, $directiveContent);
127
  }
128
 
129
  }//end process()
@@ -193,13 +193,13 @@ class PHPCompatibility_Sniffs_PHP_NewExecutionDirectivesSniff extends PHPCompati
193
  *
194
  * @return void
195
  */
196
- protected function addErrorOnInvalidValue($phpcsFile, $stackPtr, $directive)
197
  {
198
  $tokens = $phpcsFile->getTokens();
199
 
200
  $value = $tokens[$stackPtr]['content'];
201
  if ($tokens[$stackPtr]['code'] === T_CONSTANT_ENCAPSED_STRING) {
202
- $value = trim($value, '\'"');
203
  }
204
 
205
  $isError = false;
@@ -221,7 +221,7 @@ class PHPCompatibility_Sniffs_PHP_NewExecutionDirectivesSniff extends PHPCompati
221
  $directive,
222
  $value,
223
  );
224
- $phpcsFile->addError($error, $stackPtr, 'InvalidDirectiveValueFound', $data);
225
  }
226
  }// addErrorOnInvalidValue()
227
 
123
  return;
124
  }
125
 
126
+ $this->addWarningOnInvalidValue($phpcsFile, $valuePtr, $directiveContent);
127
  }
128
 
129
  }//end process()
193
  *
194
  * @return void
195
  */
196
+ protected function addWarningOnInvalidValue($phpcsFile, $stackPtr, $directive)
197
  {
198
  $tokens = $phpcsFile->getTokens();
199
 
200
  $value = $tokens[$stackPtr]['content'];
201
  if ($tokens[$stackPtr]['code'] === T_CONSTANT_ENCAPSED_STRING) {
202
+ $value = $this->stripQuotes($value);
203
  }
204
 
205
  $isError = false;
221
  $directive,
222
  $value,
223
  );
224
+ $phpcsFile->addWarning($error, $stackPtr, 'InvalidDirectiveValueFound', $data);
225
  }
226
  }// addErrorOnInvalidValue()
227
 
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewFunctionArrayDereferencingSniff.php CHANGED
@@ -37,28 +37,46 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionArrayDereferencingSniff extends PHP
37
  */
38
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
39
  {
 
 
 
 
40
  $tokens = $phpcsFile->getTokens();
41
 
42
- $ignore = array(
43
- T_DOUBLE_COLON,
44
- T_OBJECT_OPERATOR,
45
- T_FUNCTION,
46
- T_CONST,
47
- );
48
 
49
- $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
50
- if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
51
- // Not a call to a PHP function.
52
  return;
53
  }
54
 
55
- if (isset($tokens[$stackPtr + 1]) && $tokens[$stackPtr + 1]['type'] == 'T_OPEN_PARENTHESIS') {
56
- $closeParenthesis = $tokens[$stackPtr + 1]['parenthesis_closer'];
57
- if ($tokens[$closeParenthesis + 1]['type'] == 'T_OPEN_SQUARE_BRACKET') {
58
- if ($this->supportsBelow('5.3')) {
59
- $phpcsFile->addError('Function array dereferencing is not present in PHP version 5.3 or earlier', $stackPtr + 3);
60
- }
 
 
 
 
 
 
 
 
 
61
  }
62
  }
 
 
 
 
 
 
 
63
  }//end process()
64
  }//end class
37
  */
38
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
39
  {
40
+ if ($this->supportsBelow('5.3') === false) {
41
+ return;
42
+ }
43
+
44
  $tokens = $phpcsFile->getTokens();
45
 
46
+ // Next non-empty token should be the open parenthesis.
47
+ $openParenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true);
48
+ if ($openParenthesis === false || $tokens[$openParenthesis]['code'] !== T_OPEN_PARENTHESIS) {
49
+ return;
50
+ }
 
51
 
52
+ // Don't throw errors during live coding.
53
+ if (isset($tokens[$openParenthesis]['parenthesis_closer']) === false) {
 
54
  return;
55
  }
56
 
57
+ // Is this T_STRING really a function or method call ?
58
+ $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
59
+ if($prevToken !== false && in_array($tokens[$prevToken]['code'], array(T_DOUBLE_COLON, T_OBJECT_OPERATOR), true) === false) {
60
+ $ignore = array(
61
+ T_FUNCTION,
62
+ T_CONST,
63
+ T_USE,
64
+ T_NEW,
65
+ T_CLASS,
66
+ T_INTERFACE,
67
+ );
68
+
69
+ if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
70
+ // Not a call to a PHP function or method.
71
+ return;
72
  }
73
  }
74
+
75
+ $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
76
+ $nextNonEmpty = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($closeParenthesis + 1), null, true, null, true);
77
+ if ($nextNonEmpty !== false && $tokens[$nextNonEmpty]['type'] === 'T_OPEN_SQUARE_BRACKET') {
78
+ $phpcsFile->addError('Function array dereferencing is not present in PHP version 5.3 or earlier', $nextNonEmpty);
79
+ }
80
+
81
  }//end process()
82
  }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewFunctionParametersSniff.php CHANGED
@@ -16,14 +16,6 @@
16
  */
17
  class PHPCompatibility_Sniffs_PHP_NewFunctionParametersSniff extends PHPCompatibility_Sniff
18
  {
19
-
20
- /**
21
- * If true, forbidden functions will be considered regular expressions.
22
- *
23
- * @var bool
24
- */
25
- protected $patternMatch = false;
26
-
27
  /**
28
  * A list of new functions, not present in older versions.
29
  *
@@ -731,12 +723,6 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionParametersSniff extends PHPCompatib
731
  // they want to check for, so now we can cache out the list.
732
  $this->newFunctionParametersNames = array_keys($this->newFunctionParameters);
733
 
734
- if ($this->patternMatch === true) {
735
- foreach ($this->newFunctionParametersNames as $i => $name) {
736
- $this->newFunctionParametersNames[$i] = '/'.$name.'/i';
737
- }
738
- }
739
-
740
  return array(T_STRING);
741
  }//end register()
742
 
16
  */
17
  class PHPCompatibility_Sniffs_PHP_NewFunctionParametersSniff extends PHPCompatibility_Sniff
18
  {
 
 
 
 
 
 
 
 
19
  /**
20
  * A list of new functions, not present in older versions.
21
  *
723
  // they want to check for, so now we can cache out the list.
724
  $this->newFunctionParametersNames = array_keys($this->newFunctionParameters);
725
 
 
 
 
 
 
 
726
  return array(T_STRING);
727
  }//end register()
728
 
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewFunctionsSniff.php CHANGED
@@ -16,14 +16,6 @@
16
  */
17
  class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sniff
18
  {
19
-
20
- /**
21
- * If true, forbidden functions will be considered regular expressions.
22
- *
23
- * @var bool
24
- */
25
- protected $patternMatch = false;
26
-
27
  /**
28
  * A list of new functions, not present in older versions.
29
  *
@@ -1236,12 +1228,6 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
1236
  $this->forbiddenFunctionNames = array_map('strtolower', $this->forbiddenFunctionNames);
1237
  $this->forbiddenFunctions = array_combine($this->forbiddenFunctionNames, $this->forbiddenFunctions);
1238
 
1239
- if ($this->patternMatch === true) {
1240
- foreach ($this->forbiddenFunctionNames as $i => $name) {
1241
- $this->forbiddenFunctionNames[$i] = '/'.$name.'/i';
1242
- }
1243
- }
1244
-
1245
  return array(T_STRING);
1246
 
1247
  }//end register()
@@ -1277,31 +1263,12 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
1277
  }
1278
 
1279
  $function = strtolower($tokens[$stackPtr]['content']);
1280
- $pattern = null;
1281
 
1282
- if ($this->patternMatch === true) {
1283
- $count = 0;
1284
- $pattern = preg_replace(
1285
- $this->forbiddenFunctionNames,
1286
- $this->forbiddenFunctionNames,
1287
- $function,
1288
- 1,
1289
- $count
1290
- );
1291
-
1292
- if ($count === 0) {
1293
- return;
1294
- }
1295
-
1296
- // Remove the pattern delimiters and modifier.
1297
- $pattern = substr($pattern, 1, -2);
1298
- } else {
1299
- if (in_array($function, $this->forbiddenFunctionNames) === false) {
1300
- return;
1301
- }
1302
  }
1303
 
1304
- $this->addError($phpcsFile, $stackPtr, $tokens[$stackPtr]['content'], $pattern);
1305
 
1306
  }//end process()
1307
 
@@ -1313,20 +1280,16 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
1313
  * @param int $stackPtr The position of the function
1314
  * in the token array.
1315
  * @param string $function The name of the function.
1316
- * @param string $pattern The pattern used for the match.
1317
  *
1318
  * @return void
1319
  */
1320
- protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
1321
  {
1322
- if ($pattern === null) {
1323
- $pattern = strtolower($function);
1324
- }
1325
-
1326
- $error = '';
1327
 
1328
  $isError = false;
1329
- foreach ($this->forbiddenFunctions[$pattern] as $version => $present) {
1330
  if ($this->supportsBelow($version)) {
1331
  if ($present === false) {
1332
  $isError = true;
16
  */
17
  class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sniff
18
  {
 
 
 
 
 
 
 
 
19
  /**
20
  * A list of new functions, not present in older versions.
21
  *
1228
  $this->forbiddenFunctionNames = array_map('strtolower', $this->forbiddenFunctionNames);
1229
  $this->forbiddenFunctions = array_combine($this->forbiddenFunctionNames, $this->forbiddenFunctions);
1230
 
 
 
 
 
 
 
1231
  return array(T_STRING);
1232
 
1233
  }//end register()
1263
  }
1264
 
1265
  $function = strtolower($tokens[$stackPtr]['content']);
 
1266
 
1267
+ if (in_array($function, $this->forbiddenFunctionNames) === false) {
1268
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1269
  }
1270
 
1271
+ $this->addError($phpcsFile, $stackPtr, $tokens[$stackPtr]['content']);
1272
 
1273
  }//end process()
1274
 
1280
  * @param int $stackPtr The position of the function
1281
  * in the token array.
1282
  * @param string $function The name of the function.
 
1283
  *
1284
  * @return void
1285
  */
1286
+ protected function addError($phpcsFile, $stackPtr, $function)
1287
  {
1288
+ $functionLc = strtolower($function);
1289
+ $error = '';
 
 
 
1290
 
1291
  $isError = false;
1292
+ foreach ($this->forbiddenFunctions[$functionLc] as $version => $present) {
1293
  if ($this->supportsBelow($version)) {
1294
  if ($present === false) {
1295
  $isError = true;
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewGroupUseDeclarationsSniff.php CHANGED
@@ -44,7 +44,7 @@ class PHPCompatibility_Sniffs_PHP_NewGroupUseDeclarationsSniff extends PHPCompat
44
  */
45
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
  {
47
- if (!$this->supportsAbove('7.0')) {
48
  $phpcsFile->addError('Group use declarations are not allowed in PHP 5.6 or earlier', $stackPtr);
49
  }
50
  }//end process()
44
  */
45
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
  {
47
+ if ($this->supportsBelow('5.6')) {
48
  $phpcsFile->addError('Group use declarations are not allowed in PHP 5.6 or earlier', $stackPtr);
49
  }
50
  }//end process()
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewHashAlgorithmsSniff.php ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * PHPCompatibility_Sniffs_PHP_NewHashAlgorithmsSniff.
4
+ *
5
+ * @category PHP
6
+ * @package PHPCompatibility
7
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
8
+ */
9
+
10
+ /**
11
+ * PHPCompatibility_Sniffs_PHP_NewHashAlgorithmsSniff.
12
+ *
13
+ * @category PHP
14
+ * @package PHPCompatibility
15
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
16
+ */
17
+ class PHPCompatibility_Sniffs_PHP_NewHashAlgorithmsSniff extends PHPCompatibility_Sniff
18
+ {
19
+ /**
20
+ * A list of new hash algorithms, not present in older versions.
21
+ *
22
+ * The array lists : version number with false (not present) or true (present).
23
+ * If's sufficient to list the first version where the hash algorithm appears.
24
+ *
25
+ * @var array(string => array(string => bool))
26
+ */
27
+ protected $newAlgorithms = array(
28
+ 'md2' => array(
29
+ '5.2' => false,
30
+ '5.3' => true,
31
+ ),
32
+ 'ripemd256' => array(
33
+ '5.2' => false,
34
+ '5.3' => true,
35
+ ),
36
+ 'ripemd320' => array(
37
+ '5.2' => false,
38
+ '5.3' => true,
39
+ ),
40
+ 'salsa10' => array(
41
+ '5.2' => false,
42
+ '5.3' => true,
43
+ ),
44
+ 'salsa20' => array(
45
+ '5.2' => false,
46
+ '5.3' => true,
47
+ ),
48
+ 'snefru256' => array(
49
+ '5.2' => false,
50
+ '5.3' => true,
51
+ ),
52
+ 'sha224' => array(
53
+ '5.2' => false,
54
+ '5.3' => true,
55
+ ),
56
+ 'joaat' => array(
57
+ '5.3' => false,
58
+ '5.4' => true,
59
+ ),
60
+ 'fnv132' => array(
61
+ '5.3' => false,
62
+ '5.4' => true,
63
+ ),
64
+ 'fnv164' => array(
65
+ '5.3' => false,
66
+ '5.4' => true,
67
+ ),
68
+ 'gost-crypto' => array(
69
+ '5.5' => false,
70
+ '5.6' => true,
71
+ ),
72
+ );
73
+
74
+
75
+ /**
76
+ * Returns an array of tokens this test wants to listen for.
77
+ *
78
+ * @return array
79
+ */
80
+ public function register()
81
+ {
82
+ return array(T_STRING);
83
+
84
+ }//end register()
85
+
86
+
87
+ /**
88
+ * Processes this test, when one of its tokens is encountered.
89
+ *
90
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
91
+ * @param int $stackPtr The position of the current token in the
92
+ * stack passed in $tokens.
93
+ *
94
+ * @return void
95
+ */
96
+ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
97
+ {
98
+ $algo = $this->getHashAlgorithmParameter($phpcsFile, $stackPtr);
99
+ if (empty($algo) || is_string($algo) === false) {
100
+ return;
101
+ }
102
+
103
+ // Bow out if not one of the algorithms we're targetting.
104
+ if (isset($this->newAlgorithms[$algo]) === false) {
105
+ return;
106
+ }
107
+
108
+ // Check if the algorithm used is new.
109
+ $errorInfo = $this->getErrorInfo($algo);
110
+
111
+ if ($errorInfo['not_in_version'] !== '') {
112
+ $this->addError($phpcsFile, $stackPtr, $algo, $errorInfo);
113
+ }
114
+
115
+ }//end process()
116
+
117
+
118
+ /**
119
+ * Retrieve the relevant (version) information for the error message.
120
+ *
121
+ * @param string $algorithm The name of the algorithm.
122
+ *
123
+ * @return array
124
+ */
125
+ protected function getErrorInfo($algorithm)
126
+ {
127
+ $errorInfo = array(
128
+ 'not_in_version' => '',
129
+ );
130
+
131
+ foreach ($this->newAlgorithms[$algorithm] as $version => $present) {
132
+ if ($present === false && $this->supportsBelow($version)) {
133
+ $errorInfo['not_in_version'] = $version;
134
+ }
135
+ }
136
+
137
+ return $errorInfo;
138
+
139
+ }//end getErrorInfo()
140
+
141
+
142
+ /**
143
+ * Generates the error or warning for this sniff.
144
+ *
145
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
146
+ * @param int $stackPtr The position of the function
147
+ * in the token array.
148
+ * @param string $algorithm The name of the algorithm.
149
+ * @param array $errorInfo Array with details about the versions
150
+ * in which the algorithm was deprecated
151
+ * and/or removed.
152
+ *
153
+ * @return void
154
+ */
155
+ protected function addError($phpcsFile, $stackPtr, $algorithm, $errorInfo)
156
+ {
157
+ $error = 'The %s hash algorithm is not present in PHP version %s or earlier ';
158
+ $errorCode = $algorithm . 'Found';
159
+ $data = array(
160
+ $algorithm,
161
+ $errorInfo['not_in_version'],
162
+ );
163
+
164
+ $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
165
+
166
+ }//end addError()
167
+
168
+ }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewIniDirectivesSniff.php CHANGED
@@ -156,35 +156,29 @@ class PHPCompatibility_Sniffs_PHP_NewIniDirectivesSniff extends PHPCompatibility
156
  ),
157
 
158
  'mbstring.strict_detection' => array(
159
- '5.0' => false,
160
- '5.1' => false,
161
  '5.1.2' => true,
162
  ),
163
  'mssql.charset' => array(
164
- '5.0' => false,
165
- '5.1' => false,
166
  '5.1.2' => true,
167
  ),
168
 
169
  'gd.jpeg_ignore_warning' => array(
170
- '5.0' => false,
171
- '5.1' => false,
172
  '5.1.3' => true,
173
  ),
174
 
175
  'fbsql.show_timestamp_decimals' => array(
176
- '5.0' => false,
177
- '5.1' => false,
178
  '5.1.5' => true,
179
  ),
180
  'soap.wsdl_cache' => array(
181
- '5.0' => false,
182
- '5.1' => false,
183
  '5.1.5' => true,
184
  ),
185
  'soap.wsdl_cache_limit' => array(
186
- '5.0' => false,
187
- '5.1' => false,
188
  '5.1.5' => true,
189
  ),
190
 
@@ -214,26 +208,22 @@ class PHPCompatibility_Sniffs_PHP_NewIniDirectivesSniff extends PHPCompatibility
214
  ),
215
 
216
  'cgi.check_shebang_line' => array(
217
- '5.1' => false,
218
- '5.2' => false,
219
  '5.2.1' => true
220
  ),
221
 
222
  'max_input_nesting_level' => array(
223
- '5.1' => false,
224
- '5.2' => false,
225
  '5.2.3' => true
226
  ),
227
 
228
  'mysqli.allow_local_infile' => array(
229
- '5.1' => false,
230
- '5.2' => false,
231
  '5.2.4' => true,
232
  ),
233
 
234
  'max_file_uploads' => array(
235
- '5.1' => false,
236
- '5.2' => false,
237
  '5.2.12' => true,
238
  ),
239
 
@@ -315,20 +305,17 @@ class PHPCompatibility_Sniffs_PHP_NewIniDirectivesSniff extends PHPCompatibility
315
  ),
316
 
317
  'curl.cainfo' => array(
318
- '5.2' => false,
319
- '5.3' => false,
320
  '5.3.7' => true,
321
  ),
322
 
323
  'max_input_vars' => array(
324
- '5.2' => false,
325
- '5.3' => false,
326
  '5.3.9' => true,
327
  ),
328
 
329
  'sqlite3.extension_dir' => array(
330
- '5.2' => false,
331
- '5.3' => false,
332
  '5.3.11' => true,
333
  ),
334
 
@@ -436,8 +423,7 @@ class PHPCompatibility_Sniffs_PHP_NewIniDirectivesSniff extends PHPCompatibility
436
  ),
437
 
438
  'session.use_strict_mode' => array(
439
- '5.4' => false,
440
- '5.5' => false,
441
  '5.5.2' => true,
442
  ),
443
 
@@ -506,31 +492,40 @@ class PHPCompatibility_Sniffs_PHP_NewIniDirectivesSniff extends PHPCompatibility
506
  return;
507
  }
508
 
509
- $iniToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr, null);
510
- $filteredToken = trim($tokens[$iniToken]['content'], '\'"');
511
- if (isset($this->newIniDirectives[$filteredToken]) === false) {
512
  return;
513
  }
514
 
515
- $error = '';
 
 
 
516
 
 
517
  foreach ($this->newIniDirectives[$filteredToken] as $version => $present) {
518
- if ($version !== 'alternative') {
519
- if ($this->supportsBelow($version)) {
520
- if ($present === true) {
521
- $error .= " not available before version " . $version;
522
- }
523
- }
524
  }
525
  }
526
 
527
- if (strlen($error) > 0) {
528
- $error = "INI directive '" . $filteredToken . "' is" . $error;
 
 
 
 
 
529
  if (isset($this->newIniDirectives[$filteredToken]['alternative'])) {
530
- $error .= ". This directive was previously called '" . $this->newIniDirectives[$filteredToken]['alternative'] . "'.";
 
531
  }
532
 
533
- $phpcsFile->addWarning($error, $stackPtr);
 
 
 
 
534
  }
535
 
536
  }//end process()
156
  ),
157
 
158
  'mbstring.strict_detection' => array(
159
+ '5.1.1' => false,
 
160
  '5.1.2' => true,
161
  ),
162
  'mssql.charset' => array(
163
+ '5.1.1' => false,
 
164
  '5.1.2' => true,
165
  ),
166
 
167
  'gd.jpeg_ignore_warning' => array(
168
+ '5.1.2' => false,
 
169
  '5.1.3' => true,
170
  ),
171
 
172
  'fbsql.show_timestamp_decimals' => array(
173
+ '5.1.4' => false,
 
174
  '5.1.5' => true,
175
  ),
176
  'soap.wsdl_cache' => array(
177
+ '5.1.4' => false,
 
178
  '5.1.5' => true,
179
  ),
180
  'soap.wsdl_cache_limit' => array(
181
+ '5.1.4' => false,
 
182
  '5.1.5' => true,
183
  ),
184
 
208
  ),
209
 
210
  'cgi.check_shebang_line' => array(
211
+ '5.2.0' => false,
 
212
  '5.2.1' => true
213
  ),
214
 
215
  'max_input_nesting_level' => array(
216
+ '5.2.2' => false,
 
217
  '5.2.3' => true
218
  ),
219
 
220
  'mysqli.allow_local_infile' => array(
221
+ '5.2.3' => false,
 
222
  '5.2.4' => true,
223
  ),
224
 
225
  'max_file_uploads' => array(
226
+ '5.2.11' => false,
 
227
  '5.2.12' => true,
228
  ),
229
 
305
  ),
306
 
307
  'curl.cainfo' => array(
308
+ '5.3.6' => false,
 
309
  '5.3.7' => true,
310
  ),
311
 
312
  'max_input_vars' => array(
313
+ '5.3.8' => false,
 
314
  '5.3.9' => true,
315
  ),
316
 
317
  'sqlite3.extension_dir' => array(
318
+ '5.3.10' => false,
 
319
  '5.3.11' => true,
320
  ),
321
 
423
  ),
424
 
425
  'session.use_strict_mode' => array(
426
+ '5.5.1' => false,
 
427
  '5.5.2' => true,
428
  ),
429
 
492
  return;
493
  }
494
 
495
+ $iniToken = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 1);
496
+ if ($iniToken === false) {
 
497
  return;
498
  }
499
 
500
+ $filteredToken = $this->stripQuotes($iniToken['raw']);
501
+ if (isset($this->newIniDirectives[$filteredToken]) === false) {
502
+ return;
503
+ }
504
 
505
+ $notInVersion = '';
506
  foreach ($this->newIniDirectives[$filteredToken] as $version => $present) {
507
+ if ($version !== 'alternative' && $present === false && $this->supportsBelow($version)) {
508
+ $notInVersion = $version;
 
 
 
 
509
  }
510
  }
511
 
512
+ if ($notInVersion !== '') {
513
+ $error = "INI directive '%s' is not present in PHP version %s or earlier";
514
+ $isError = ($function !== 'ini_get') ? true : false;
515
+ $data = array(
516
+ $filteredToken,
517
+ $notInVersion
518
+ );
519
  if (isset($this->newIniDirectives[$filteredToken]['alternative'])) {
520
+ $error .= ". This directive was previously called '%s'.";
521
+ $data[] = $this->newIniDirectives[$filteredToken]['alternative'];
522
  }
523
 
524
+ if ($isError === true) {
525
+ $phpcsFile->addError($error, $iniToken['end'], 'Found', $data);
526
+ } else {
527
+ $phpcsFile->addWarning($error, $iniToken['end'], 'Found', $data);
528
+ }
529
  }
530
 
531
  }//end process()
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewInterfacesSniff.php CHANGED
@@ -135,17 +135,19 @@ class PHPCompatibility_Sniffs_PHP_NewInterfacesSniff extends PHPCompatibility_Sn
135
  if ($checkMethods === true && isset($this->unsupportedMethods[$lcInterface]) === true) {
136
  $nextFunc = $stackPtr;
137
  while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) {
138
- $funcNamePos = $phpcsFile->findNext(T_STRING, $nextFunc);
139
- $funcName = strtolower($tokens[$funcNamePos]['content']);
 
 
140
 
141
  if (isset($this->unsupportedMethods[$lcInterface][$funcName]) === true) {
142
  $error = 'Classes that implement interface %s do not support the method %s(). See %s';
143
  $data = array(
144
  $interface,
145
- $tokens[$funcNamePos]['content'],
146
  $this->unsupportedMethods[$lcInterface][$funcName],
147
  );
148
- $phpcsFile->addError($error, $funcNamePos, 'UnsupportedMethod', $data);
149
  }
150
  }
151
  }
@@ -161,20 +163,16 @@ class PHPCompatibility_Sniffs_PHP_NewInterfacesSniff extends PHPCompatibility_Sn
161
  * @param int $stackPtr The position of the function
162
  * in the token array.
163
  * @param string $interface The name of the interface.
164
- * @param string $pattern The pattern used for the match.
165
  *
166
  * @return void
167
  */
168
- protected function addError($phpcsFile, $stackPtr, $interface, $pattern=null)
169
  {
170
- if ($pattern === null) {
171
- $pattern = strtolower($interface);
172
- }
173
-
174
- $error = '';
175
 
176
  $isError = false;
177
- foreach ($this->newInterfaces[$pattern] as $version => $present) {
178
  if ($this->supportsBelow($version)) {
179
  if ($present === false) {
180
  $isError = true;
135
  if ($checkMethods === true && isset($this->unsupportedMethods[$lcInterface]) === true) {
136
  $nextFunc = $stackPtr;
137
  while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) {
138
+ $funcName = strtolower($phpcsFile->getDeclarationName($nextFunc));
139
+ if ($funcName === '') {
140
+ continue;
141
+ }
142
 
143
  if (isset($this->unsupportedMethods[$lcInterface][$funcName]) === true) {
144
  $error = 'Classes that implement interface %s do not support the method %s(). See %s';
145
  $data = array(
146
  $interface,
147
+ $funcName,
148
  $this->unsupportedMethods[$lcInterface][$funcName],
149
  );
150
+ $phpcsFile->addError($error, $nextFunc, 'UnsupportedMethod', $data);
151
  }
152
  }
153
  }
163
  * @param int $stackPtr The position of the function
164
  * in the token array.
165
  * @param string $interface The name of the interface.
 
166
  *
167
  * @return void
168
  */
169
+ protected function addError($phpcsFile, $stackPtr, $interface)
170
  {
171
+ $interfaceLc = strtolower($interface);
172
+ $error = '';
 
 
 
173
 
174
  $isError = false;
175
+ foreach ($this->newInterfaces[$interfaceLc] as $version => $present) {
176
  if ($this->supportsBelow($version)) {
177
  if ($present === false) {
178
  $isError = true;
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewKeywordsSniff.php CHANGED
@@ -26,10 +26,12 @@ class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Snif
26
  * A list of new keywords, not present in older versions.
27
  *
28
  * The array lists : version number with false (not present) or true (present).
29
- * If's sufficient to list the first version where the keyword appears.
30
  *
31
- * If you add a condition, make sure to add the appropriate logic for it as well as
32
- * this will not resolve itself automatically.
 
 
33
  *
34
  * @var array(string => array(string => int|string|null))
35
  */
@@ -43,37 +45,43 @@ class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Snif
43
  '5.2' => false,
44
  '5.3' => true,
45
  'description' => '"const" keyword',
46
- 'condition' => 'T_CLASS', // Keyword is only new when not in class context.
47
  ),
48
  'T_CALLABLE' => array(
49
  '5.3' => false,
50
  '5.4' => true,
51
- 'description' => '"callable" keyword'
 
52
  ),
53
  'T_DIR' => array(
54
  '5.2' => false,
55
  '5.3' => true,
56
- 'description' => '__DIR__ magic constant'
 
57
  ),
58
  'T_GOTO' => array(
59
  '5.2' => false,
60
  '5.3' => true,
61
- 'description' => '"goto" keyword'
 
62
  ),
63
  'T_INSTEADOF' => array(
64
  '5.3' => false,
65
  '5.4' => true,
66
- 'description' => '"insteadof" keyword (for traits)'
 
67
  ),
68
  'T_NAMESPACE' => array(
69
  '5.2' => false,
70
  '5.3' => true,
71
- 'description' => '"namespace" keyword'
 
72
  ),
73
  'T_NS_C' => array(
74
  '5.2' => false,
75
  '5.3' => true,
76
- 'description' => '__NAMESPACE__ magic constant'
 
77
  ),
78
  'T_USE' => array(
79
  '5.2' => false,
@@ -83,35 +91,48 @@ class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Snif
83
  'T_TRAIT' => array(
84
  '5.3' => false,
85
  '5.4' => true,
86
- 'description' => '"trait" keyword'
 
87
  ),
88
  'T_TRAIT_C' => array(
89
  '5.3' => false,
90
  '5.4' => true,
91
- 'description' => '__TRAIT__ magic constant'
 
92
  ),
93
  'T_YIELD' => array(
94
  '5.4' => false,
95
  '5.5' => true,
96
- 'description' => '"yield" keyword (for generators)'
 
97
  ),
98
  'T_FINALLY' => array(
99
  '5.4' => false,
100
  '5.5' => true,
101
- 'description' => '"finally" keyword (in exception handling)'
 
102
  ),
103
  'T_START_NOWDOC' => array(
104
  '5.2' => false,
105
  '5.3' => true,
106
- 'description' => 'nowdoc functionality'
107
  ),
108
  'T_END_NOWDOC' => array(
109
  '5.2' => false,
110
  '5.3' => true,
111
- 'description' => 'nowdoc functionality'
112
  ),
113
  );
114
 
 
 
 
 
 
 
 
 
 
115
 
116
  /**
117
  * Returns an array of tokens this test wants to listen for.
@@ -120,12 +141,26 @@ class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Snif
120
  */
121
  public function register()
122
  {
123
- $tokens = array();
 
124
  foreach ($this->newKeywords as $token => $versions) {
125
  if (defined($token)) {
126
  $tokens[] = constant($token);
127
  }
 
 
 
 
 
 
 
 
 
 
 
 
128
  }
 
129
  return $tokens;
130
 
131
  }//end register()
@@ -142,38 +177,44 @@ class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Snif
142
  */
143
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
144
  {
145
- $tokens = $phpcsFile->getTokens();
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
  $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
148
  $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
149
 
 
150
  // Skip attempts to use keywords as functions or class names - the former
151
- // will be reported by FrobiddenNamesAsInvokedFunctionsSniff, whilst the
152
- // latter doesn't yet have an appropriate sniff.
153
  // Either type will result in false-positives when targetting lower versions
154
  // of PHP where the name was not reserved, unless we explicitly check for
155
  // them.
156
  if (
157
- $tokens[$nextToken]['type'] != 'T_OPEN_PARENTHESIS'
158
  &&
159
- $tokens[$prevToken]['type'] != 'T_CLASS'
160
  ) {
161
- // Skip based on special conditions.
162
- if (
163
- isset($this->newKeywords[$tokens[$stackPtr]['type']]['condition'])
164
- &&
165
- (empty($tokens[$stackPtr]['conditions']) === false
166
- &&
167
- is_array($tokens[$stackPtr]['conditions']))
168
- ) {
169
- foreach ($tokens[$stackPtr]['conditions'] as $condPtr => $condType) {
170
- if ($condType === constant($this->newKeywords[$tokens[$stackPtr]['type']]['condition'])) {
171
- return;
172
- }
173
  }
174
  }
175
 
176
- $this->addError($phpcsFile, $stackPtr, $tokens[$stackPtr]['type']);
177
  }
178
  }//end process()
179
 
@@ -185,40 +226,31 @@ class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Snif
185
  * @param int $stackPtr The position of the function
186
  * in the token array.
187
  * @param string $keywordName The name of the keyword.
188
- * @param string $pattern The pattern used for the match.
189
  *
190
  * @return void
191
  */
192
- protected function addError($phpcsFile, $stackPtr, $keywordName, $pattern=null)
193
  {
194
- if ($pattern === null) {
195
- $pattern = $keywordName;
196
- }
197
-
198
- $error = '';
199
-
200
- $isError = false;
201
- foreach ($this->newKeywords[$pattern] as $version => $present) {
202
- if (in_array($version, array('condition', 'description'), true)) {
203
  continue;
204
  }
205
 
206
- if ($this->supportsBelow($version)) {
207
- if ($present === false) {
208
- $isError = true;
209
- $error .= 'not present in PHP version ' . $version . ' or earlier';
210
- }
211
  }
212
  }
213
- if (strlen($error) > 0) {
214
- $error = $this->newKeywords[$keywordName]['description'] . ' is ' . $error;
215
 
216
- if ($isError === true) {
217
- $phpcsFile->addError($error, $stackPtr);
218
- } else {
219
- $phpcsFile->addWarning($error, $stackPtr);
220
- }
 
 
221
  }
 
222
  }//end addError()
223
 
224
  }//end class
26
  * A list of new keywords, not present in older versions.
27
  *
28
  * The array lists : version number with false (not present) or true (present).
29
+ * If's sufficient to list the last version which did not contain the keyword.
30
  *
31
+ * Description will be used as part of the error message.
32
+ * Condition is an array of valid scope conditions to check for.
33
+ * If you need a condition of a different type, make sure to add the appropriate
34
+ * logic for it as well as this will not resolve itself automatically.
35
  *
36
  * @var array(string => array(string => int|string|null))
37
  */
45
  '5.2' => false,
46
  '5.3' => true,
47
  'description' => '"const" keyword',
48
+ 'condition' => array(T_CLASS), // Keyword is only new when not in class context.
49
  ),
50
  'T_CALLABLE' => array(
51
  '5.3' => false,
52
  '5.4' => true,
53
+ 'description' => '"callable" keyword',
54
+ 'content' => 'callable',
55
  ),
56
  'T_DIR' => array(
57
  '5.2' => false,
58
  '5.3' => true,
59
+ 'description' => '__DIR__ magic constant',
60
+ 'content' => '__DIR__',
61
  ),
62
  'T_GOTO' => array(
63
  '5.2' => false,
64
  '5.3' => true,
65
+ 'description' => '"goto" keyword',
66
+ 'content' => 'goto',
67
  ),
68
  'T_INSTEADOF' => array(
69
  '5.3' => false,
70
  '5.4' => true,
71
+ 'description' => '"insteadof" keyword (for traits)',
72
+ 'content' => 'insteadof',
73
  ),
74
  'T_NAMESPACE' => array(
75
  '5.2' => false,
76
  '5.3' => true,
77
+ 'description' => '"namespace" keyword',
78
+ 'content' => 'namespace',
79
  ),
80
  'T_NS_C' => array(
81
  '5.2' => false,
82
  '5.3' => true,
83
+ 'description' => '__NAMESPACE__ magic constant',
84
+ 'content' => '__NAMESPACE__',
85
  ),
86
  'T_USE' => array(
87
  '5.2' => false,
91
  'T_TRAIT' => array(
92
  '5.3' => false,
93
  '5.4' => true,
94
+ 'description' => '"trait" keyword',
95
+ 'content' => 'trait',
96
  ),
97
  'T_TRAIT_C' => array(
98
  '5.3' => false,
99
  '5.4' => true,
100
+ 'description' => '__TRAIT__ magic constant',
101
+ 'content' => '__TRAIT__',
102
  ),
103
  'T_YIELD' => array(
104
  '5.4' => false,
105
  '5.5' => true,
106
+ 'description' => '"yield" keyword (for generators)',
107
+ 'content' => 'yield',
108
  ),
109
  'T_FINALLY' => array(
110
  '5.4' => false,
111
  '5.5' => true,
112
+ 'description' => '"finally" keyword (in exception handling)',
113
+ 'content' => 'finally',
114
  ),
115
  'T_START_NOWDOC' => array(
116
  '5.2' => false,
117
  '5.3' => true,
118
+ 'description' => 'nowdoc functionality',
119
  ),
120
  'T_END_NOWDOC' => array(
121
  '5.2' => false,
122
  '5.3' => true,
123
+ 'description' => 'nowdoc functionality',
124
  ),
125
  );
126
 
127
+ /**
128
+ * Translation table for T_STRING tokens.
129
+ *
130
+ * Will be set up from the register() method.
131
+ *
132
+ * @var array(string => string)
133
+ */
134
+ protected $translateContentToToken = array();
135
+
136
 
137
  /**
138
  * Returns an array of tokens this test wants to listen for.
141
  */
142
  public function register()
143
  {
144
+ $tokens = array();
145
+ $translate = array();
146
  foreach ($this->newKeywords as $token => $versions) {
147
  if (defined($token)) {
148
  $tokens[] = constant($token);
149
  }
150
+ if (isset($versions['content'])) {
151
+ $translate[$versions['content']] = $token;
152
+ }
153
+ }
154
+
155
+ /*
156
+ * Deal with tokens not recognized by the PHP version the sniffer is run
157
+ * under and (not correctly) compensated for by PHPCS.
158
+ */
159
+ if (empty($translate) === false) {
160
+ $this->translateContentToToken = $translate;
161
+ $tokens[] = T_STRING;
162
  }
163
+
164
  return $tokens;
165
 
166
  }//end register()
177
  */
178
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
179
  {
180
+ $tokens = $phpcsFile->getTokens();
181
+ $tokenType = $tokens[$stackPtr]['type'];
182
+
183
+ // Translate T_STRING token if necessary.
184
+ if ($tokens[$stackPtr]['type'] === 'T_STRING') {
185
+ $content = $tokens[$stackPtr]['content'];
186
+ if (isset($this->translateContentToToken[$content]) === false) {
187
+ // Not one of the tokens we're looking for.
188
+ return;
189
+ }
190
+
191
+ $tokenType = $this->translateContentToToken[$content];
192
+ }
193
 
194
  $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
195
  $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
196
 
197
+
198
  // Skip attempts to use keywords as functions or class names - the former
199
+ // will be reported by ForbiddenNamesAsInvokedFunctionsSniff, whilst the
200
+ // latter will be (partially) reported by the ForbiddenNames sniff.
201
  // Either type will result in false-positives when targetting lower versions
202
  // of PHP where the name was not reserved, unless we explicitly check for
203
  // them.
204
  if (
205
+ ($nextToken === false || $tokens[$nextToken]['type'] !== 'T_OPEN_PARENTHESIS')
206
  &&
207
+ ($prevToken === false || $tokens[$prevToken]['type'] !== 'T_CLASS' || $tokens[$prevToken]['type'] !== 'T_INTERFACE')
208
  ) {
209
+ // Skip based on token scope condition.
210
+ if (isset($this->newKeywords[$tokenType]['condition'])) {
211
+ $condition = $this->newKeywords[$tokenType]['condition'];
212
+ if ($this->tokenHasScope($phpcsFile, $stackPtr, $condition) === true) {
213
+ return;
 
 
 
 
 
 
 
214
  }
215
  }
216
 
217
+ $this->addError($phpcsFile, $stackPtr, $tokenType);
218
  }
219
  }//end process()
220
 
226
  * @param int $stackPtr The position of the function
227
  * in the token array.
228
  * @param string $keywordName The name of the keyword.
 
229
  *
230
  * @return void
231
  */
232
+ protected function addError($phpcsFile, $stackPtr, $keywordName)
233
  {
234
+ $notInVersion = '';
235
+ foreach ($this->newKeywords[$keywordName] as $version => $present) {
236
+ if (in_array($version, array('condition', 'description', 'content'), true)) {
 
 
 
 
 
 
237
  continue;
238
  }
239
 
240
+ if ($present === false && $this->supportsBelow($version)) {
241
+ $notInVersion = $version;
 
 
 
242
  }
243
  }
 
 
244
 
245
+ if ($notInVersion !== '') {
246
+ $error = '%s is not present in PHP version %s or earlier';
247
+ $data = array(
248
+ $this->newKeywords[$keywordName]['description'],
249
+ $notInVersion,
250
+ );
251
+ $phpcsFile->addError($error, $stackPtr, 'Found', $data);
252
  }
253
+
254
  }//end addError()
255
 
256
  }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewScalarReturnTypeDeclarationsSniff.php CHANGED
@@ -89,20 +89,15 @@ class PHPCompatibility_Sniffs_PHP_NewScalarReturnTypeDeclarationsSniff extends P
89
  * @param int $stackPtr The position of the function
90
  * in the token array.
91
  * @param string $typeName The type.
92
- * @param string $pattern The pattern used for the match.
93
  *
94
  * @return void
95
  */
96
- protected function addError($phpcsFile, $stackPtr, $typeName, $pattern=null)
97
  {
98
- if ($pattern === null) {
99
- $pattern = $typeName;
100
- }
101
-
102
  $error = '';
103
 
104
  $isError = false;
105
- foreach ($this->newTypes[$pattern] as $version => $present) {
106
  if ($this->supportsBelow($version)) {
107
  if ($present === false) {
108
  $isError = true;
89
  * @param int $stackPtr The position of the function
90
  * in the token array.
91
  * @param string $typeName The type.
 
92
  *
93
  * @return void
94
  */
95
+ protected function addError($phpcsFile, $stackPtr, $typeName)
96
  {
 
 
 
 
97
  $error = '';
98
 
99
  $isError = false;
100
+ foreach ($this->newTypes[$typeName] as $version => $present) {
101
  if ($this->supportsBelow($version)) {
102
  if ($present === false) {
103
  $isError = true;
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/NewScalarTypeDeclarationsSniff.php CHANGED
@@ -92,6 +92,10 @@ class PHPCompatibility_Sniffs_PHP_NewScalarTypeDeclarationsSniff extends PHPComp
92
  {
93
  // Get all parameters from method signature.
94
  $paramNames = $this->getMethodParameters($phpcsFile, $stackPtr);
 
 
 
 
95
  $supportsPHP4 = $this->supportsBelow('4.4');
96
 
97
  foreach ($paramNames as $param) {
@@ -131,20 +135,15 @@ class PHPCompatibility_Sniffs_PHP_NewScalarTypeDeclarationsSniff extends PHPComp
131
  * @param int $stackPtr The position of the function
132
  * in the token array.
133
  * @param string $typeName The type.
134
- * @param string $pattern The pattern used for the match.
135
  *
136
  * @return void
137
  */
138
- protected function addError($phpcsFile, $stackPtr, $typeName, $pattern=null)
139
  {
140
- if ($pattern === null) {
141
- $pattern = $typeName;
142
- }
143
-
144
  $error = '';
145
 
146
  $isError = false;
147
- foreach ($this->newTypes[$pattern] as $version => $present) {
148
  if ($this->supportsBelow($version)) {
149
  if ($present === false) {
150
  $isError = true;
92
  {
93
  // Get all parameters from method signature.
94
  $paramNames = $this->getMethodParameters($phpcsFile, $stackPtr);
95
+ if (empty($paramNames)) {
96
+ return;
97
+ }
98
+
99
  $supportsPHP4 = $this->supportsBelow('4.4');
100
 
101
  foreach ($paramNames as $param) {
135
  * @param int $stackPtr The position of the function
136
  * in the token array.
137
  * @param string $typeName The type.
 
138
  *
139
  * @return void
140
  */
141
+ protected function addError($phpcsFile, $stackPtr, $typeName)
142
  {
 
 
 
 
143
  $error = '';
144
 
145
  $isError = false;
146
+ foreach ($this->newTypes[$typeName] as $version => $present) {
147
  if ($this->supportsBelow($version)) {
148
  if ($present === false) {
149
  $isError = true;
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ParameterShadowSuperGlobalsSniff.php CHANGED
@@ -36,9 +36,6 @@ class PHPCompatibility_Sniffs_PHP_ParameterShadowSuperGlobalsSniff extends PHPCo
36
  * @return array
37
  */
38
  public function register() {
39
- // Prepare for case-insensitive compare.
40
- $this->superglobals = array_map('strtolower', $this->superglobals);
41
-
42
  return array(T_FUNCTION);
43
  }
44
 
@@ -62,9 +59,7 @@ class PHPCompatibility_Sniffs_PHP_ParameterShadowSuperGlobalsSniff extends PHPCo
62
  }
63
 
64
  foreach ($parameters as $param) {
65
- $paramNameLc = strtolower($param['name']);
66
-
67
- if (in_array($paramNameLc, $this->superglobals, true)) {
68
  $error = 'Parameter shadowing super global (%s) causes fatal error since PHP 5.4';
69
  $data = array($param['name']);
70
  $phpcsFile->addError($error, $stackPtr, 'Found', $data);
36
  * @return array
37
  */
38
  public function register() {
 
 
 
39
  return array(T_FUNCTION);
40
  }
41
 
59
  }
60
 
61
  foreach ($parameters as $param) {
62
+ if (in_array($param['name'], $this->superglobals, true)) {
 
 
63
  $error = 'Parameter shadowing super global (%s) causes fatal error since PHP 5.4';
64
  $data = array($param['name']);
65
  $phpcsFile->addError($error, $stackPtr, 'Found', $data);
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/PregReplaceEModifierSniff.php CHANGED
@@ -32,6 +32,18 @@ class PHPCompatibility_Sniffs_PHP_PregReplaceEModifierSniff extends PHPCompatibi
32
  'preg_filter' => true,
33
  );
34
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  /**
36
  * Returns an array of tokens this test wants to listen for.
37
  *
@@ -53,69 +65,61 @@ class PHPCompatibility_Sniffs_PHP_PregReplaceEModifierSniff extends PHPCompatibi
53
  */
54
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
55
  {
56
- if ($this->supportsAbove('5.5')) {
57
- $tokens = $phpcsFile->getTokens();
58
-
59
- if ( isset($this->functions[$tokens[$stackPtr]['content']]) === false ) {
60
- return;
61
- } else {
62
-
63
- $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
64
-
65
- if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
66
- return;
67
- }
68
-
69
- $firstParam = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true);
70
 
71
- /**
72
- * If argument is not a string, then skip test (e.g. if variable passed in).
73
- */
74
- if ($tokens[$firstParam]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
75
- return;
76
- }
77
 
78
- /**
79
- * Regex is a T_CONSTANT_ENCAPSED_STRING, so we need to remove the quotes
80
- */
81
- $regex = "";
82
- while (isset($tokens[$firstParam]) && $tokens[$firstParam]['code'] != T_COMMA) {
83
- if ($tokens[$firstParam]['code'] == T_CONSTANT_ENCAPSED_STRING) {
84
- $regex .= $tokens[$firstParam]['content'];
85
- }
86
- $firstParam++;
87
- }
88
 
89
- $doublesSeparators = array(
90
- '{' => '}',
91
- '[' => ']',
92
- '(' => ')',
93
- '<' => '>',
94
- );
95
 
96
- $regex = substr($regex, 1, -1);
 
 
 
 
97
 
98
- $regexFirstChar = substr($regex, 0, 1);
99
- $regexEndPos = (array_key_exists($regexFirstChar, $doublesSeparators)) ?
100
- strrpos($regex, $doublesSeparators[$regexFirstChar])
101
- : strrpos($regex, $regexFirstChar);
 
 
 
 
 
 
 
 
 
 
 
102
 
103
- if($regexEndPos) {
104
- $modifiers = substr($regex, $regexEndPos + 1);
105
 
106
- if (strpos($modifiers, "e") !== false) {
107
- if ($this->supportsAbove('7.0')) {
108
- $error = 'preg_replace() - /e modifier is forbidden in PHP 7.0';
109
- } else {
110
- $error = 'preg_replace() - /e modifier is deprecated in PHP 5.5';
111
- }
112
- $phpcsFile->addError($error, $stackPtr);
113
- }
114
  }
 
 
115
  }
116
  }
117
 
118
-
119
  }//end process()
120
 
121
  }//end class
32
  'preg_filter' => true,
33
  );
34
 
35
+ /**
36
+ * Regex bracket delimiters.
37
+ *
38
+ * @var array
39
+ */
40
+ protected $doublesSeparators = array(
41
+ '{' => '}',
42
+ '[' => ']',
43
+ '(' => ')',
44
+ '<' => '>',
45
+ );
46
+
47
  /**
48
  * Returns an array of tokens this test wants to listen for.
49
  *
65
  */
66
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
67
  {
68
+ if ($this->supportsAbove('5.5') === false) {
69
+ return;
70
+ }
 
 
 
 
 
 
 
 
 
 
 
71
 
72
+ $tokens = $phpcsFile->getTokens();
73
+ $functionName = $tokens[$stackPtr]['content'];
74
+ $functionNameLc = strtolower($functionName);
 
 
 
75
 
76
+ // Bow out if not one of the functions we're targetting.
77
+ if ( isset($this->functions[$functionNameLc]) === false ) {
78
+ return;
79
+ }
 
 
 
 
 
 
80
 
81
+ // Get the first parameter in the function call as that should contain the regex.
82
+ $firstParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 1);
83
+ if ($firstParam === false) {
84
+ return;
85
+ }
 
86
 
87
+ $stringToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $firstParam['start'], $firstParam['end'] + 1);
88
+ if ($stringToken === false) {
89
+ // No string token found in the first parameter, so skip it (e.g. if variable passed in).
90
+ return;
91
+ }
92
 
93
+ /*
94
+ * The first parameter might be build up of a combination of strings,
95
+ * variables and function calls, but in that case, generally the start
96
+ * and end will still be strings. And as that's all we're concerned with,
97
+ * just use the raw content of the first parameter for further processing.
98
+ */
99
+ $regex = $this->stripQuotes($firstParam['raw']);
100
+
101
+ $regexFirstChar = substr($regex, 0, 1);
102
+ if (isset($this->doublesSeparators[$regexFirstChar])) {
103
+ $regexEndPos = strrpos($regex, $this->doublesSeparators[$regexFirstChar]);
104
+ }
105
+ else {
106
+ $regexEndPos = strrpos($regex, $regexFirstChar);
107
+ }
108
 
109
+ if($regexEndPos) {
110
+ $modifiers = substr($regex, $regexEndPos + 1);
111
 
112
+ if (strpos($modifiers, 'e') !== false) {
113
+ if ($this->supportsAbove('7.0')) {
114
+ $error = '%s() - /e modifier is forbidden since PHP 7.0';
115
+ } else {
116
+ $error = '%s() - /e modifier is deprecated since PHP 5.5';
 
 
 
117
  }
118
+ $data = array($functionName);
119
+ $phpcsFile->addError($error, $stackPtr, 'Found', $data);
120
  }
121
  }
122
 
 
123
  }//end process()
124
 
125
  }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/RemovedAlternativePHPTagsSniff.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * PHPCompatibility_Sniffs_PHP_RemovedAlternativePHPTags.
4
+ *
5
+ * @category PHP
6
+ * @package PHPCompatibility
7
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
8
+ */
9
+
10
+ /**
11
+ * PHPCompatibility_Sniffs_PHP_RemovedAlternativePHPTags.
12
+ *
13
+ * Check for usage of alternative PHP tags - removed in PHP 7.0.
14
+ *
15
+ * @category PHP
16
+ * @package PHPCompatibility
17
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
18
+ *
19
+ * Based on `Generic_Sniffs_PHP_DisallowAlternativePHPTags` by Juliette Reinders Folmer
20
+ * which was merged into PHPCS 2.7.0.
21
+ */
22
+ class PHPCompatibility_Sniffs_PHP_RemovedAlternativePHPTagsSniff extends PHPCompatibility_Sniff
23
+ {
24
+
25
+ /**
26
+ * Whether ASP tags are enabled or not.
27
+ *
28
+ * @var bool
29
+ */
30
+ private $_aspTags = false;
31
+
32
+ /**
33
+ * Returns an array of tokens this test wants to listen for.
34
+ *
35
+ * @return array
36
+ */
37
+ public function register()
38
+ {
39
+ if (version_compare(phpversion(), '7.0', '<') === true) {
40
+ $this->_aspTags = (boolean) ini_get('asp_tags');
41
+ }
42
+
43
+ return array(
44
+ T_OPEN_TAG,
45
+ T_OPEN_TAG_WITH_ECHO,
46
+ T_INLINE_HTML,
47
+ );
48
+
49
+ }//end register()
50
+
51
+
52
+ /**
53
+ * Processes this test, when one of its tokens is encountered.
54
+ *
55
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
56
+ * @param int $stackPtr The position of the current token
57
+ * in the stack passed in $tokens.
58
+ *
59
+ * @return void
60
+ */
61
+ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
62
+ {
63
+ if ($this->supportsAbove('7.0') === false) {
64
+ return;
65
+ }
66
+
67
+ $tokens = $phpcsFile->getTokens();
68
+ $openTag = $tokens[$stackPtr];
69
+ $content = trim($openTag['content']);
70
+
71
+ if ($content === '' || $content === '<?php') {
72
+ return;
73
+ }
74
+
75
+ if ($openTag['code'] === T_OPEN_TAG || $openTag['code'] === T_OPEN_TAG_WITH_ECHO) {
76
+
77
+ if ($content === '<%' || $content === '<%=') {
78
+ $data = array(
79
+ 'ASP',
80
+ $content,
81
+ );
82
+ $errorCode = 'ASPOpenTagFound';
83
+ }
84
+ else if (strpos($content, '<script ') !== false) {
85
+ $data = array(
86
+ 'Script',
87
+ $content,
88
+ );
89
+ $errorCode = 'ScriptOpenTagFound';
90
+ }
91
+ else {
92
+ return;
93
+ }
94
+ }
95
+ // Account for incorrect script open tags.
96
+ // The "(?:<s)?" in the regex is to work-around a bug in the tokenizer in PHP 5.2.
97
+ else if ($openTag['code'] === T_INLINE_HTML
98
+ && preg_match('`((?:<s)?cript (?:[^>]+)?language=[\'"]?php[\'"]?(?:[^>]+)?>)`i', $content, $match) === 1
99
+ ) {
100
+ $found = $match[1];
101
+ if (version_compare(phpversion(), '5.3', '<')) {
102
+ // Add the missing '<s' at the start of the match for PHP 5.2.
103
+ $found = '<s' . $match[1];
104
+ }
105
+
106
+ $data = array(
107
+ 'Script',
108
+ $found,
109
+ );
110
+ $errorCode = 'ScriptOpenTagFound';
111
+ }
112
+
113
+ if (isset($errorCode, $data)) {
114
+ $error = '%s style opening tags have been removed in PHP 7.0. Found "%s"';
115
+ $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
116
+ return;
117
+ }
118
+
119
+
120
+ // If we're still here, we can't be sure if what we find was really intended as ASP open tags.
121
+ if ($openTag['code'] === T_INLINE_HTML && $this->_aspTags === false) {
122
+ if (strpos($content, '<%') !== false) {
123
+ $error = 'Possible use of ASP style opening tags detected. ASP style opening tags have been removed in PHP 7.0. Found: %s';
124
+ $snippet = $this->getSnippet($content, '<%');
125
+ $data = array('<%'.$snippet);
126
+
127
+ $phpcsFile->addWarning($error, $stackPtr, 'MaybeASPOpenTagFound', $data);
128
+ }
129
+ }
130
+
131
+ }//end process()
132
+
133
+
134
+ /**
135
+ * Get a snippet from a HTML token.
136
+ *
137
+ * @param string $content The content of the HTML token.
138
+ * @param string $start_at Partial string to use as a starting point for the snippet.
139
+ * @param int $length The target length of the snippet to get. Defaults to 25.
140
+ *
141
+ * @return string
142
+ */
143
+ protected function getSnippet($content, $start_at = '', $length = 25)
144
+ {
145
+ $start_pos = 0;
146
+
147
+ if ($start_at !== '') {
148
+ $start_pos = strpos($content, $start_at);
149
+ if ($start_pos !== false) {
150
+ $start_pos += strlen($start_at);
151
+ }
152
+ }
153
+
154
+ $snippet = substr($content, $start_pos, $length);
155
+ if ((strlen($content) - $start_pos) > $length) {
156
+ $snippet .= '...';
157
+ }
158
+
159
+ return $snippet;
160
+
161
+ }//end getSnippet()
162
+
163
+ }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/RemovedFunctionParametersSniff.php CHANGED
@@ -16,18 +16,10 @@
16
  */
17
  class PHPCompatibility_Sniffs_PHP_RemovedFunctionParametersSniff extends PHPCompatibility_Sniff
18
  {
19
-
20
- /**
21
- * If true, forbidden functions will be considered regular expressions.
22
- *
23
- * @var bool
24
- */
25
- protected $patternMatch = false;
26
-
27
  /**
28
  * A list of removed function parameters, which were present in older versions.
29
  *
30
- * The array lists : version number with true (deprecated and false (removed).
31
  * The index is the location of the parameter in the parameter list, starting at 0 !
32
  * If's sufficient to list the first version where the function was deprecated/removed.
33
  *
@@ -81,12 +73,6 @@ class PHPCompatibility_Sniffs_PHP_RemovedFunctionParametersSniff extends PHPComp
81
  // they want to check for, so now we can cache out the list.
82
  $this->removedFunctionParametersNames = array_keys($this->removedFunctionParameters);
83
 
84
- if ($this->patternMatch === true) {
85
- foreach ($this->removedFunctionParametersNames as $i => $name) {
86
- $this->removedFunctionParametersNames[$i] = '/'.$name.'/i';
87
- }
88
- }
89
-
90
  return array(T_STRING);
91
  }//end register()
92
 
16
  */
17
  class PHPCompatibility_Sniffs_PHP_RemovedFunctionParametersSniff extends PHPCompatibility_Sniff
18
  {
 
 
 
 
 
 
 
 
19
  /**
20
  * A list of removed function parameters, which were present in older versions.
21
  *
22
+ * The array lists : version number with true (deprecated) and false (removed).
23
  * The index is the location of the parameter in the parameter list, starting at 0 !
24
  * If's sufficient to list the first version where the function was deprecated/removed.
25
  *
73
  // they want to check for, so now we can cache out the list.
74
  $this->removedFunctionParametersNames = array_keys($this->removedFunctionParameters);
75
 
 
 
 
 
 
 
76
  return array(T_STRING);
77
  }//end register()
78
 
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/RemovedGlobalVariablesSniff.php CHANGED
@@ -56,14 +56,14 @@ class PHPCompatibility_Sniffs_PHP_RemovedGlobalVariablesSniff extends PHPCompati
56
  */
57
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
58
  {
59
- $tokens = $phpcsFile->getTokens();
60
- $varNameUc = strtoupper(substr($tokens[$stackPtr]['content'], 1));
61
 
62
- if (isset($this->removedGlobalVariables[$varNameUc]) === false) {
63
  return;
64
  }
65
 
66
- $versionList = $this->removedGlobalVariables[$varNameUc];
67
 
68
  $error = '';
69
  $isError = false;
56
  */
57
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
58
  {
59
+ $tokens = $phpcsFile->getTokens();
60
+ $varName = substr($tokens[$stackPtr]['content'], 1);
61
 
62
+ if (isset($this->removedGlobalVariables[$varName]) === false) {
63
  return;
64
  }
65
 
66
+ $versionList = $this->removedGlobalVariables[$varName];
67
 
68
  $error = '';
69
  $isError = false;
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/RemovedHashAlgorithmsSniff.php CHANGED
@@ -13,7 +13,7 @@
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff.
15
  *
16
- * Discourages the use of deprecated and removed hash algorithms
17
  *
18
  * PHP version 5.4
19
  *
@@ -26,16 +26,20 @@ class PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff extends PHPCompatib
26
  {
27
 
28
  /**
29
- * List of functions using the algorithm as parameter (always the first parameter)
30
  *
31
- * @var array
 
 
 
32
  */
33
- protected $algoFunctions = array(
34
- 'hash_file',
35
- 'hash_hmac_file',
36
- 'hash_hmac',
37
- 'hash_init',
38
- 'hash'
 
39
  );
40
 
41
  /**
@@ -61,36 +65,94 @@ class PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff extends PHPCompatib
61
  */
62
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
63
  {
64
- if ($this->supportsAbove('5.4')) {
65
- $tokens = $phpcsFile->getTokens();
 
 
66
 
67
- if (in_array($tokens[$stackPtr]['content'], $this->algoFunctions) === true) {
68
- $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
 
 
69
 
70
- if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
71
- return;
72
- }
 
 
 
 
 
73
 
74
- $firstParam = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true);
75
-
76
- /**
77
- * Algorithm is a T_CONSTANT_ENCAPSED_STRING, so we need to remove the quotes
78
- */
79
- $algo = strtolower($tokens[$firstParam]['content']);
80
- $algo = substr($algo, 1, strlen($algo) - 2);
81
- switch ($algo) {
82
- case 'salsa10':
83
- case 'salsa20':
84
- $error = 'The Salsa10 and Salsa20 hash algorithms have been removed since PHP 5.4';
85
- $phpcsFile->addError($error, $stackPtr);
86
- break;
87
- }
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  }
90
  }
91
 
 
92
 
93
- }//end process()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
 
95
 
96
  }//end class
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff.
15
  *
16
+ * Discourages the use of deprecated and removed hash algorithms.
17
  *
18
  * PHP version 5.4
19
  *
26
  {
27
 
28
  /**
29
+ * A list of removed hash algorithms, which were present in older versions.
30
  *
31
+ * The array lists : version number with false (deprecated) and true (removed).
32
+ * If's sufficient to list the first version where the hash algorithm was deprecated/removed.
33
+ *
34
+ * @var array(string => array(string => bool))
35
  */
36
+ protected $removedAlgorithms = array(
37
+ 'salsa10' => array(
38
+ '5.4' => true,
39
+ ),
40
+ 'salsa20' => array(
41
+ '5.4' => true,
42
+ ),
43
  );
44
 
45
  /**
65
  */
66
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
67
  {
68
+ $algo = $this->getHashAlgorithmParameter($phpcsFile, $stackPtr);
69
+ if (empty($algo) || is_string($algo) === false) {
70
+ return;
71
+ }
72
 
73
+ // Bow out if not one of the algorithms we're targetting.
74
+ if (isset($this->removedAlgorithms[$algo]) === false) {
75
+ return;
76
+ }
77
 
78
+ // Check if the algorithm used is deprecated or removed.
79
+ $errorInfo = $this->getErrorInfo($algo);
80
+
81
+ if ($errorInfo['deprecated'] !== '' || $errorInfo['removed'] !== '') {
82
+ $this->addError($phpcsFile, $stackPtr, $algo, $errorInfo);
83
+ }
84
+
85
+ }//end process()
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
+ /**
89
+ * Retrieve the relevant (version) information for the error message.
90
+ *
91
+ * @param string $algorithm The name of the algorithm.
92
+ *
93
+ * @return array
94
+ */
95
+ protected function getErrorInfo($algorithm)
96
+ {
97
+ $errorInfo = array(
98
+ 'deprecated' => '',
99
+ 'removed' => '',
100
+ 'error' => false,
101
+ );
102
+
103
+ foreach ($this->removedAlgorithms[$algorithm] as $version => $removed) {
104
+ if ($this->supportsAbove($version)) {
105
+ if ($removed === true && $errorInfo['removed'] === '') {
106
+ $errorInfo['removed'] = $version;
107
+ $errorInfo['error'] = true;
108
+ } elseif ($errorInfo['deprecated'] === '') {
109
+ $errorInfo['deprecated'] = $version;
110
+ }
111
  }
112
  }
113
 
114
+ return $errorInfo;
115
 
116
+ }//end getErrorInfo()
117
+
118
+
119
+ /**
120
+ * Generates the error or warning for this sniff.
121
+ *
122
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
123
+ * @param int $stackPtr The position of the function
124
+ * in the token array.
125
+ * @param string $algorithm The name of the algorithm.
126
+ * @param array $errorInfo Array with details about the versions
127
+ * in which the algorithm was deprecated
128
+ * and/or removed.
129
+ *
130
+ * @return void
131
+ */
132
+ protected function addError($phpcsFile, $stackPtr, $algorithm, $errorInfo)
133
+ {
134
+ $error = 'The %s hash algorithm is ';
135
+ $errorCode = $algorithm . 'Found';
136
+ $data = array($algorithm);
137
+
138
+ if ($errorInfo['deprecated'] !== '') {
139
+ $error .= 'deprecated since PHP version %s and ';
140
+ $data[] = $errorInfo['deprecated'];
141
+ }
142
+ if ($errorInfo['removed'] !== '') {
143
+ $error .= 'removed since PHP version %s and ';
144
+ $data[] = $errorInfo['removed'];
145
+ }
146
+
147
+ // Remove the last 'and' from the message.
148
+ $error = substr($error, 0, strlen($error) - 5);
149
+
150
+ if ($errorInfo['error'] === true) {
151
+ $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
152
+ } else {
153
+ $phpcsFile->addWarning($error, $stackPtr, $errorCode, $data);
154
+ }
155
 
156
+ }//end addError()
157
 
158
  }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/RequiredOptionalFunctionParametersSniff.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @category PHP
6
  * @package PHPCompatibility
7
- * @author Wim Godden <wim.godden@cu.be>
8
  */
9
 
10
  /**
@@ -12,7 +12,7 @@
12
  *
13
  * @category PHP
14
  * @package PHPCompatibility
15
- * @author Wim Godden <wim.godden@cu.be>
16
  */
17
  class PHPCompatibility_Sniffs_PHP_RequiredOptionalFunctionParametersSniff extends PHPCompatibility_Sniff
18
  {
4
  *
5
  * @category PHP
6
  * @package PHPCompatibility
7
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
8
  */
9
 
10
  /**
12
  *
13
  * @category PHP
14
  * @package PHPCompatibility
15
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
16
  */
17
  class PHPCompatibility_Sniffs_PHP_RequiredOptionalFunctionParametersSniff extends PHPCompatibility_Sniff
18
  {
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ShortArraySniff.php CHANGED
@@ -2,17 +2,6 @@
2
 
3
  class PHPCompatibility_Sniffs_PHP_ShortArraySniff extends PHPCompatibility_Sniff
4
  {
5
- /** @var array */
6
- protected $supportByVersion = array(
7
- '5.3' => false,
8
- '5.4' => true
9
- );
10
-
11
- /** @var array */
12
- protected $errorByForbiddenTokens = array(
13
- 'T_OPEN_SHORT_ARRAY' => 'Short array syntax (open)',
14
- 'T_CLOSE_SHORT_ARRAY' => 'Short array syntax (close)'
15
- );
16
 
17
  /**
18
  * Returns an array of tokens this test wants to listen for.
@@ -21,7 +10,10 @@ class PHPCompatibility_Sniffs_PHP_ShortArraySniff extends PHPCompatibility_Sniff
21
  */
22
  public function register()
23
  {
24
- return array(T_OPEN_TAG);
 
 
 
25
  }//end register()
26
 
27
 
@@ -36,24 +28,24 @@ class PHPCompatibility_Sniffs_PHP_ShortArraySniff extends PHPCompatibility_Sniff
36
  */
37
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
38
  {
 
 
 
 
39
  $tokens = $phpcsFile->getTokens();
 
 
 
 
40
 
41
- foreach ($tokens as $currentToken) {
42
- if (!isset($this->errorByForbiddenTokens[$currentToken['type']])) {
43
- continue;
44
- }
45
-
46
- foreach ($this->supportByVersion as $version => $support) {
47
- if ($this->supportsBelow($version)) {
48
- if ($support) {
49
- continue;
50
- }
51
-
52
- $error = $this->errorByForbiddenTokens[$currentToken['type']] . ' is available since 5.4';
53
- $phpcsFile->addError($error, $stackPtr);
54
- }
55
- }
56
  }
 
 
 
57
  }//end process()
58
 
59
  }//end class
2
 
3
  class PHPCompatibility_Sniffs_PHP_ShortArraySniff extends PHPCompatibility_Sniff
4
  {
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  /**
7
  * Returns an array of tokens this test wants to listen for.
10
  */
11
  public function register()
12
  {
13
+ return array(
14
+ T_OPEN_SHORT_ARRAY,
15
+ T_CLOSE_SHORT_ARRAY,
16
+ );
17
  }//end register()
18
 
19
 
28
  */
29
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
30
  {
31
+ if ($this->supportsBelow('5.3') === false) {
32
+ return;
33
+ }
34
+
35
  $tokens = $phpcsFile->getTokens();
36
+ $token = $tokens[$stackPtr];
37
+
38
+ $error = '%s is available since 5.4';
39
+ $data = array();
40
 
41
+ if ($token['type'] === 'T_OPEN_SHORT_ARRAY' ) {
42
+ $data[] = 'Short array syntax (open)';
43
+ } elseif ($token['type'] === 'T_CLOSE_SHORT_ARRAY' ) {
44
+ $data[] = 'Short array syntax (close)';
 
 
 
 
 
 
 
 
 
 
 
45
  }
46
+
47
+ $phpcsFile->addError($error, $stackPtr, 'Found', $data);
48
+
49
  }//end process()
50
 
51
  }//end class
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/TernaryOperatorsSniff.php CHANGED
@@ -47,20 +47,20 @@ class PHPCompatibility_Sniffs_PHP_TernaryOperatorsSniff extends PHPCompatibility
47
  */
48
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
49
  {
50
- if (!$this->supportsAbove('5.3')) {
51
- $tokens = $phpcsFile->getTokens();
 
 
 
52
 
53
- // Get next non-whitespace token, and check it isn't the related inline else
54
- // symbol, which is not allowed prior to PHP 5.3.
55
- $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens,
56
- ($stackPtr + 1), null, true);
57
 
58
- if ($tokens[$next]['code'] == T_INLINE_ELSE) {
59
- $error = sprintf(
60
- "Middle may not be omitted from ternary operators in PHP < 5.3"
61
- );
62
- $phpcsFile->addWarning($error, $stackPtr);
63
- }
64
  }
65
  }
66
  }
47
  */
48
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
49
  {
50
+ if ($this->supportsBelow('5.2') === false) {
51
+ return;
52
+ }
53
+
54
+ $tokens = $phpcsFile->getTokens();
55
 
56
+ // Get next non-whitespace token, and check it isn't the related inline else
57
+ // symbol, which is not allowed prior to PHP 5.3.
58
+ $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens,
59
+ ($stackPtr + 1), null, true);
60
 
61
+ if ($next !== false && $tokens[$next]['code'] === T_INLINE_ELSE) {
62
+ $error = 'Middle may not be omitted from ternary operators in PHP < 5.3';
63
+ $phpcsFile->addWarning($error, $stackPtr);
 
 
 
64
  }
65
  }
66
  }
vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility/Sniffs/PHP/ValidIntegersSniff.php CHANGED
@@ -101,7 +101,7 @@ class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sn
101
  /**
102
  * Could the current token an potentially be a binary integer ?
103
  *
104
- * @param array $token Token stack.
105
  * @param int $stackPtr The current position in the token stack.
106
  *
107
  * @return bool
@@ -126,7 +126,7 @@ class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sn
126
  /**
127
  * Is the current token an invalid binary integer ?
128
  *
129
- * @param array $token Token stack.
130
  * @param int $stackPtr The current position in the token stack.
131
  *
132
  * @return bool
@@ -149,7 +149,7 @@ class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sn
149
  * Retrieve the content of the tokens which together look like a binary integer.
150
  *
151
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
152
- * @param array $token Token stack.
153
  * @param int $stackPtr The position of the current token in
154
  * the stack.
155
  *
@@ -172,7 +172,7 @@ class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sn
172
  /**
173
  * Is the current token an invalid octal integer ?
174
  *
175
- * @param array $token Token stack.
176
  * @param int $stackPtr The current position in the token stack.
177
  *
178
  * @return bool
@@ -190,7 +190,7 @@ class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sn
190
  /**
191
  * Is the current token a hexidecimal numeric string ?
192
  *
193
- * @param array $token Token stack.
194
  * @param int $stackPtr The current position in the token stack.
195
  *
196
  * @return bool
@@ -198,7 +198,7 @@ class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sn
198
  private function isHexidecimalNumericString($tokens, $stackPtr) {
199
  $token = $tokens[$stackPtr];
200
 
201
- if ($token['code'] === T_CONSTANT_ENCAPSED_STRING && preg_match('`^([\'"])0x[a-f0-9]+\1$`iD', $token['content']) === 1) {
202
  return true;
203
  }
204
 
101
  /**
102
  * Could the current token an potentially be a binary integer ?
103
  *
104
+ * @param array $tokens Token stack.
105
  * @param int $stackPtr The current position in the token stack.
106
  *
107
  * @return bool
126
  /**
127
  * Is the current token an invalid binary integer ?
128
  *
129
+ * @param array $tokens Token stack.
130
  * @param int $stackPtr The current position in the token stack.
131
  *
132
  * @return bool
149
  * Retrieve the content of the tokens which together look like a binary integer.
150
  *
151
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
152
+ * @param array $tokens Token stack.
153
  * @param int $stackPtr The position of the current token in
154
  * the stack.
155
  *
172
  /**
173
  * Is the current token an invalid octal integer ?
174
  *
175
+ * @param array $tokens Token stack.
176
  * @param int $stackPtr The current position in the token stack.
177
  *
178
  * @return bool
190
  /**
191
  * Is the current token a hexidecimal numeric string ?
192
  *
193
+ * @param array $tokens Token stack.
194
  * @param int $stackPtr The current position in the token stack.
195
  *
196
  * @return bool
198
  private function isHexidecimalNumericString($tokens, $stackPtr) {
199
  $token = $tokens[$stackPtr];
200
 
201
+ if ($token['code'] === T_CONSTANT_ENCAPSED_STRING && preg_match('`^0x[a-f0-9]+$`iD', $this->stripQuotes($token['content'])) === 1) {
202
  return true;
203
  }
204
 
vendor/wimg/php-compatibility/.coveralls.yml CHANGED
@@ -1,3 +1,3 @@
1
- src_dir: Sniffs
2
  coverage_clover: build/logs/clover.xml
3
  json_path: build/logs/coveralls-upload.json
 
 
1
  coverage_clover: build/logs/clover.xml
2
  json_path: build/logs/coveralls-upload.json
3
+ service_name: travis-ci
vendor/wimg/php-compatibility/.scrutinizer.yml CHANGED
@@ -1,6 +1,6 @@
1
  filter:
2
  excluded_paths:
3
- - 'Tests/sniff-examples/*'
4
 
5
  tools:
6
  php_sim: true
1
  filter:
2
  excluded_paths:
3
+ - 'Tests/*'
4
 
5
  tools:
6
  php_sim: true
vendor/wimg/php-compatibility/README.md CHANGED
@@ -2,6 +2,7 @@ PHP Compatibility Coding Standard for PHP_CodeSniffer
2
  =====================================================
3
  [![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=wimg&url=https://github.com/wimg/PHPCompatibility&title=PHPCompatibility&language=&tags=github&category=software)
4
  [![Build Status](https://travis-ci.org/wimg/PHPCompatibility.png?branch=master)](https://travis-ci.org/wimg/PHPCompatibility)
 
5
  [![Latest Stable Version](https://poser.pugx.org/wimg/php-compatibility/v/stable.png)](https://packagist.org/packages/wimg/php-compatibility)
6
  [![Latest Unstable Version](https://poser.pugx.org/wimg/php-compatibility/v/unstable.png)](https://packagist.org/packages/wimg/php-compatibility)
7
  [![License](https://poser.pugx.org/wimg/php-compatibility/license.png)](https://packagist.org/packages/wimg/php-compatibility)
@@ -10,11 +11,22 @@ This is a set of sniffs for [PHP_CodeSniffer](http://pear.php.net/PHP_CodeSniffe
10
  It will allow you to analyse your code for compatibility with higher and lower versions of PHP.
11
 
12
 
 
 
 
 
 
 
 
 
 
13
  Thank you
14
  ---------
15
  Thanks to all contributors for their valuable contributions.
16
-
17
- Thanks to [![WPEngine](https://cu.be/img/wpengine.png)](http://wpengine.com) for their support on the PHP 7.0 sniffs.
 
 
18
 
19
 
20
  Installation (method 1)
@@ -71,18 +83,18 @@ Alternatively, you can add PHPCompatibility to a custom PHPCS ruleset.
71
 
72
  You can also set the `testVersion` from within the ruleset:
73
  ```xml
74
- <arg name="testVersion" value="5.3-5.5"/>
75
  ```
76
 
77
- Other advanced options, such as changing the message type or severity, as described in the [PHPCS Annotated ruleset](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml) wiki page are, of course, also supported.
78
 
79
 
80
- ##### PHPCompatibility specific options
81
 
82
  At this moment, there is one sniff which has a property which can be set via the ruleset. More custom properties may become available in the future.
83
 
84
  The `PHPCompatibility.PHP.RemovedExtensions` sniff checks for removed extensions based on the function prefix used for these extensions.
85
- This might clash with userland function using the same function prefix.
86
 
87
  To whitelist userland functions, you can pass a comma-delimited list of function names to the sniff.
88
  ```xml
@@ -134,6 +146,23 @@ on the sniffs, the following installation steps are required.
134
  PHPCompatibility. It will read the `phpunit.xml` file and execute the tests
135
 
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  License
138
  -------
139
  This code is released under the GNU Lesser General Public License (LGPL). For more information, visit http://www.gnu.org/copyleft/lesser.html
2
  =====================================================
3
  [![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=wimg&url=https://github.com/wimg/PHPCompatibility&title=PHPCompatibility&language=&tags=github&category=software)
4
  [![Build Status](https://travis-ci.org/wimg/PHPCompatibility.png?branch=master)](https://travis-ci.org/wimg/PHPCompatibility)
5
+ [![Coverage Status](https://coveralls.io/repos/github/wimg/PHPCompatibility/badge.svg?branch=master)](https://coveralls.io/github/wimg/PHPCompatibility?branch=master)
6
  [![Latest Stable Version](https://poser.pugx.org/wimg/php-compatibility/v/stable.png)](https://packagist.org/packages/wimg/php-compatibility)
7
  [![Latest Unstable Version](https://poser.pugx.org/wimg/php-compatibility/v/unstable.png)](https://packagist.org/packages/wimg/php-compatibility)
8
  [![License](https://poser.pugx.org/wimg/php-compatibility/license.png)](https://packagist.org/packages/wimg/php-compatibility)
11
  It will allow you to analyse your code for compatibility with higher and lower versions of PHP.
12
 
13
 
14
+ PHP Version Support
15
+ -------
16
+
17
+ The project aims to cover all PHP compatibility changes introduced since PHP 5.0 up to the latest PHP release. This is an ongoing process and coverage is not yet 100% (if, indeed, it ever could be). Progress is tracked on [our Github issue tracker](https://github.com/wimg/PHPCompatibility/issues).
18
+
19
+ Pull requests that check for compatibility issues in PHP4 code - in particular between PHP 4 and PHP 5.0 - are very welcome as there are still situations where people need help upgrading legacy systems. However, coverage for changes introduced before PHP 5.1 will remain patchy as sniffs for this are not actively being developed at this time.
20
+
21
+ The sniffs are designed to give the same results regardless of which PHP version you are using to run CodeSniffer. Therefore you should get consistent results independently of the PHP version used in your test environment.
22
+
23
  Thank you
24
  ---------
25
  Thanks to all contributors for their valuable contributions.
26
+
27
+ [![WPEngine](https://cu.be/img/wpengine.png)](https://wpengine.com)
28
+
29
+ Thanks to [WP Engine](https://wpengine.com) for their support on the PHP 7.0 sniffs.
30
 
31
 
32
  Installation (method 1)
83
 
84
  You can also set the `testVersion` from within the ruleset:
85
  ```xml
86
+ <config name="testVersion" value="5.3-5.5"/>
87
  ```
88
 
89
+ Other advanced options, such as changing the message type or severity of select sniffs, as described in the [PHPCS Annotated ruleset](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml) wiki page are, of course, also supported.
90
 
91
 
92
+ #### PHPCompatibility specific options
93
 
94
  At this moment, there is one sniff which has a property which can be set via the ruleset. More custom properties may become available in the future.
95
 
96
  The `PHPCompatibility.PHP.RemovedExtensions` sniff checks for removed extensions based on the function prefix used for these extensions.
97
+ This might clash with userland functions using the same function prefix.
98
 
99
  To whitelist userland functions, you can pass a comma-delimited list of function names to the sniff.
100
  ```xml
146
  PHPCompatibility. It will read the `phpunit.xml` file and execute the tests
147
 
148
 
149
+ #### Issues when running the PHPCS Unit tests for another standard
150
+
151
+ This sniff library uses its own PHPUnit setup rather than the PHPCS native unit testing framework to allow for testing the sniffs with various config settings for the `testVersion` variable.
152
+
153
+ If you are running the PHPCS native unit tests or the unit tests for another sniff library which uses the PHPCS native unit testing framework, PHPUnit might throw errors related to this sniff library depending on your setup.
154
+
155
+ This will generally only happen if you have both PHPCompatibility as well as another custom sniff library in your PHPCS `installed_paths` setting.
156
+
157
+ To fix these errors, make sure you are running PHPCS 2.7.1 or higher and add the following to the `phpunit.xml` file for the sniff library you are testing:
158
+ ```xml
159
+ <php>
160
+ <env name="PHPCS_IGNORE_TESTS" value="PHPCompatibility"/>
161
+ </php>
162
+ ```
163
+
164
+ This will prevent PHPCS trying to include the PHPCompatibility unit tests when creating the test suite.
165
+
166
  License
167
  -------
168
  This code is released under the GNU Lesser General Public License (LGPL). For more information, visit http://www.gnu.org/copyleft/lesser.html
vendor/wimg/php-compatibility/Sniff.php CHANGED
@@ -22,6 +22,24 @@
22
  abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
23
  {
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  /* The testVersion configuration variable may be in any of the following formats:
26
  * 1) Omitted/empty, in which case no version is specified. This effectively
27
  * disables all the checks provided by this standard.
@@ -76,7 +94,7 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
76
  return $arrTestVersions[$testVersion];
77
  }
78
  else {
79
- return array(null, null);
80
  }
81
  }
82
 
@@ -108,6 +126,21 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
108
  }
109
  }//end supportsBelow()
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  /**
112
  * Returns the name(s) of the interface(s) that the specified class implements.
113
  *
@@ -123,8 +156,12 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
123
  *
124
  * @return array|false
125
  */
126
- public function findImplementedInterfaceNames($phpcsFile, $stackPtr)
127
  {
 
 
 
 
128
  $tokens = $phpcsFile->getTokens();
129
 
130
  // Check for the existence of the token.
@@ -238,10 +275,35 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
238
  return 0;
239
  }
240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  // Ok, we know we have a T_STRING with parameters and valid open & close parenthesis.
242
  $tokens = $phpcsFile->getTokens();
243
 
244
- $openParenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
245
  $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
246
 
247
  // Which nesting level is the one we are interested in ?
@@ -250,44 +312,108 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
250
  $nestedParenthesisCount = count($tokens[$openParenthesis]['nested_parenthesis']) + 1;
251
  }
252
 
253
- $nextComma = $openParenthesis;
254
- $cnt = 0;
255
- while ($nextComma = $phpcsFile->findNext(array(T_COMMA, T_CLOSE_PARENTHESIS), $nextComma + 1, $closeParenthesis + 1)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  // Ignore comma's at a lower nesting level.
257
  if (
258
- $tokens[$nextComma]['type'] == 'T_COMMA'
259
  &&
260
  isset($tokens[$nextComma]['nested_parenthesis'])
261
  &&
262
- count($tokens[$nextComma]['nested_parenthesis']) != $nestedParenthesisCount
263
  ) {
264
  continue;
265
  }
266
 
267
  // Ignore closing parenthesis if not 'ours'.
268
- if ($tokens[$nextComma]['type'] == 'T_CLOSE_PARENTHESIS' && $nextComma != $closeParenthesis) {
269
  continue;
270
  }
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  $cnt++;
273
  }
274
 
275
- return $cnt;
276
  }
277
 
278
 
279
  /**
280
- * Verify whether a token is within a class scope.
281
  *
282
- * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
283
- * @param int $stackPtr The position of the token.
284
- * @param bool $strict Whether to strictly check for the T_CLASS
285
- * scope or also accept interfaces and traits
286
- * as scope.
287
  *
288
- * @return bool True if within class scope, false otherwise.
 
 
 
 
 
 
 
 
289
  */
290
- public function inClassScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $strict = true)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  {
292
  $tokens = $phpcsFile->getTokens();
293
 
@@ -301,15 +427,24 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
301
  return false;
302
  }
303
 
304
- $validScope = array(T_CLASS);
305
- if ($strict === false) {
306
- $validScope[] = T_INTERFACE;
307
- $validScope[] = T_TRAIT;
308
  }
309
 
310
- // Check for class scope.
 
 
 
 
 
 
 
 
 
 
311
  foreach ($tokens[$stackPtr]['conditions'] as $pointer => $type) {
312
- if (in_array($type, $validScope, true)) {
313
  return true;
314
  }
315
  }
@@ -318,6 +453,29 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
318
  }
319
 
320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  /**
322
  * Returns the fully qualified class name for a new class instantiation.
323
  *
@@ -348,7 +506,12 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
348
  T_WHITESPACE,
349
  );
350
 
351
- $start = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
 
 
 
 
 
352
  $end = $phpcsFile->findNext($find, ($start + 1), null, true, null, true);
353
  $className = $phpcsFile->getTokensAsString($start, ($end - $start));
354
  $className = trim($className);
@@ -414,6 +577,11 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
414
  return '';
415
  }
416
 
 
 
 
 
 
417
  // Nothing to do if 'parent' or 'static' as we don't know how far the class tree extends.
418
  if (in_array($tokens[$stackPtr - 1]['code'], array(T_PARENT, T_STATIC), true)) {
419
  return '';
@@ -423,8 +591,8 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
423
  if ($tokens[$stackPtr - 1]['code'] === T_SELF) {
424
  $classDeclarationPtr = $phpcsFile->findPrevious(T_CLASS, $stackPtr - 1);
425
  if ($classDeclarationPtr === false) {
426
- return '';
427
- }
428
  $className = $phpcsFile->getDeclarationName($classDeclarationPtr);
429
  return $this->getFQName($phpcsFile, $classDeclarationPtr, $className);
430
  }
@@ -521,8 +689,8 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
521
  if ($namespace !== false) {
522
  return $namespace;
523
  }
 
524
  }
525
- break; // We only need to check the highest level condition.
526
  }
527
  }
528
 
@@ -635,7 +803,7 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
635
  * @param int $stackPtr The position in the stack of the T_FUNCTION token
636
  * to acquire the parameters for.
637
  *
638
- * @return array
639
  * @throws PHP_CodeSniffer_Exception If the specified $stackPtr is not of
640
  * type T_FUNCTION.
641
  */
@@ -785,4 +953,50 @@ abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
785
 
786
  }//end getMethodParameters()
787
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
788
  }//end class
22
  abstract class PHPCompatibility_Sniff implements PHP_CodeSniffer_Sniff
23
  {
24
 
25
+ /**
26
+ * List of functions using hash algorithm as parameter (always the first parameter).
27
+ *
28
+ * Used by the new/removed hash algorithm sniffs.
29
+ * Key is the function name, value is the 1-based parameter position in the function call.
30
+ *
31
+ * @var array
32
+ */
33
+ protected $hashAlgoFunctions = array(
34
+ 'hash_file' => 1,
35
+ 'hash_hmac_file' => 1,
36
+ 'hash_hmac' => 1,
37
+ 'hash_init' => 1,
38
+ 'hash_pbkdf2' => 1,
39
+ 'hash' => 1,
40
+ );
41
+
42
+
43
  /* The testVersion configuration variable may be in any of the following formats:
44
  * 1) Omitted/empty, in which case no version is specified. This effectively
45
  * disables all the checks provided by this standard.
94
  return $arrTestVersions[$testVersion];
95
  }
96
  else {
97
+ return array(null, null);
98
  }
99
  }
100
 
126
  }
127
  }//end supportsBelow()
128
 
129
+
130
+ /**
131
+ * Strip quotes surrounding an arbitrary string.
132
+ *
133
+ * Intended for use with the content of a T_CONSTANT_ENCAPSED_STRING.
134
+ *
135
+ * @param string $string The raw string.
136
+ *
137
+ * @return string String without quotes around it.
138
+ */
139
+ public function stripQuotes($string) {
140
+ return preg_replace('`^([\'"])(.*)\1$`Ds', '$2', $string);
141
+ }
142
+
143
+
144
  /**
145
  * Returns the name(s) of the interface(s) that the specified class implements.
146
  *
156
  *
157
  * @return array|false
158
  */
159
+ public function findImplementedInterfaceNames(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
160
  {
161
+ if (method_exists($phpcsFile, 'findImplementedInterfaceNames')) {
162
+ return $phpcsFile->findImplementedInterfaceNames($stackPtr);
163
+ }
164
+
165
  $tokens = $phpcsFile->getTokens();
166
 
167
  // Check for the existence of the token.
275
  return 0;
276
  }
277
 
278
+ return count($this->getFunctionCallParameters($phpcsFile, $stackPtr));
279
+ }
280
+
281
+
282
+ /**
283
+ * Get information on all parameters passed to a function call.
284
+ *
285
+ * Expects to be passed the T_STRING stack pointer for the function call.
286
+ * If passed a T_STRING which is *not* a function call, the behaviour is unreliable.
287
+ *
288
+ * Will return an multi-dimentional array with the start token pointer, end token
289
+ * pointer and raw parameter value for all parameters. Index will be 1-based.
290
+ * If no parameters are found, will return an empty array.
291
+ *
292
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
293
+ * @param int $stackPtr The position of the function call token.
294
+ *
295
+ * @return array
296
+ */
297
+ public function getFunctionCallParameters(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
298
+ {
299
+ if ($this->doesFunctionCallHaveParameters($phpcsFile, $stackPtr) === false) {
300
+ return array();
301
+ }
302
+
303
  // Ok, we know we have a T_STRING with parameters and valid open & close parenthesis.
304
  $tokens = $phpcsFile->getTokens();
305
 
306
+ $openParenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
307
  $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
308
 
309
  // Which nesting level is the one we are interested in ?
312
  $nestedParenthesisCount = count($tokens[$openParenthesis]['nested_parenthesis']) + 1;
313
  }
314
 
315
+ $parameters = array();
316
+ $nextComma = $openParenthesis;
317
+ $paramStart = $openParenthesis + 1;
318
+ $cnt = 1;
319
+ while ($nextComma = $phpcsFile->findNext(array(T_COMMA, T_CLOSE_PARENTHESIS, T_OPEN_SHORT_ARRAY), $nextComma + 1, $closeParenthesis + 1)) {
320
+ // Ignore anything within short array definition brackets.
321
+ if (
322
+ $tokens[$nextComma]['type'] === 'T_OPEN_SHORT_ARRAY'
323
+ &&
324
+ ( isset($tokens[$nextComma]['bracket_opener']) && $tokens[$nextComma]['bracket_opener'] === $nextComma )
325
+ &&
326
+ isset($tokens[$nextComma]['bracket_closer'])
327
+ ) {
328
+ // Skip forward to the end of the short array definition.
329
+ $nextComma = $tokens[$nextComma]['bracket_closer'];
330
+ continue;
331
+ }
332
+
333
  // Ignore comma's at a lower nesting level.
334
  if (
335
+ $tokens[$nextComma]['type'] === 'T_COMMA'
336
  &&
337
  isset($tokens[$nextComma]['nested_parenthesis'])
338
  &&
339
+ count($tokens[$nextComma]['nested_parenthesis']) !== $nestedParenthesisCount
340
  ) {
341
  continue;
342
  }
343
 
344
  // Ignore closing parenthesis if not 'ours'.
345
+ if ($tokens[$nextComma]['type'] === 'T_CLOSE_PARENTHESIS' && $nextComma !== $closeParenthesis) {
346
  continue;
347
  }
348
 
349
+ // Ok, we've reached the end of the parameter.
350
+ $parameters[$cnt]['start'] = $paramStart;
351
+ $parameters[$cnt]['end'] = $nextComma - 1;
352
+ $parameters[$cnt]['raw'] = trim($phpcsFile->getTokensAsString($paramStart, ($nextComma - $paramStart)));
353
+
354
+ // Check if there are more tokens before the closing parenthesis.
355
+ // Prevents code like the following from setting a third parameter:
356
+ // functionCall( $param1, $param2, );
357
+ $hasNextParam = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $nextComma + 1, $closeParenthesis, true, null, true);
358
+ if ($hasNextParam === false) {
359
+ break;
360
+ }
361
+
362
+ // Prepare for the next parameter.
363
+ $paramStart = $nextComma + 1;
364
  $cnt++;
365
  }
366
 
367
+ return $parameters;
368
  }
369
 
370
 
371
  /**
372
+ * Get information on a specific parameter passed to a function call.
373
  *
374
+ * Expects to be passed the T_STRING stack pointer for the function call.
375
+ * If passed a T_STRING which is *not* a function call, the behaviour is unreliable.
 
 
 
376
  *
377
+ * Will return a array with the start token pointer, end token pointer and the raw value
378
+ * of the parameter at a specific offset.
379
+ * If the specified parameter is not found, will return false.
380
+ *
381
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
382
+ * @param int $stackPtr The position of the function call token.
383
+ * @param int $paramOffset The 1-based index position of the parameter to retrieve.
384
+ *
385
+ * @return array|false
386
  */
387
+ public function getFunctionCallParameter(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $paramOffset)
388
+ {
389
+ $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
390
+
391
+ if (isset($parameters[$paramOffset]) === false) {
392
+ return false;
393
+ }
394
+ else {
395
+ return $parameters[$paramOffset];
396
+ }
397
+ }
398
+
399
+
400
+ /**
401
+ * Verify whether a token is within a scoped condition.
402
+ *
403
+ * If the optional $validScopes parameter has been passed, the function
404
+ * will check that the token has at least one condition which is of a
405
+ * type defined in $validScopes.
406
+ *
407
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
408
+ * @param int $stackPtr The position of the token.
409
+ * @param array|int $validScopes Optional. Array of valid scopes
410
+ * or int value of a valid scope.
411
+ *
412
+ * @return bool Without the optional $scopeTypes: True if within a scope, false otherwise.
413
+ * If the $scopeTypes are set: True if *one* of the conditions is a
414
+ * valid scope, false otherwise.
415
+ */
416
+ public function tokenHasScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $validScopes = null)
417
  {
418
  $tokens = $phpcsFile->getTokens();
419
 
427
  return false;
428
  }
429
 
430
+ // Ok, there are conditions, do we have to check for specific ones ?
431
+ if (isset($validScopes) === false) {
432
+ return true;
 
433
  }
434
 
435
+ if (is_int($validScopes)) {
436
+ // Received an integer, so cast to array.
437
+ $validScopes = (array) $validScopes;
438
+ }
439
+
440
+ if (empty($validScopes) || is_array($validScopes) === false) {
441
+ // No valid scope types received, so will not comply.
442
+ return false;
443
+ }
444
+
445
+ // Check for required scope types.
446
  foreach ($tokens[$stackPtr]['conditions'] as $pointer => $type) {
447
+ if (in_array($type, $validScopes, true)) {
448
  return true;
449
  }
450
  }
453
  }
454
 
455
 
456
+ /**
457
+ * Verify whether a token is within a class scope.
458
+ *
459
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
460
+ * @param int $stackPtr The position of the token.
461
+ * @param bool $strict Whether to strictly check for the T_CLASS
462
+ * scope or also accept interfaces and traits
463
+ * as scope.
464
+ *
465
+ * @return bool True if within class scope, false otherwise.
466
+ */
467
+ public function inClassScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $strict = true)
468
+ {
469
+ $validScopes = array(T_CLASS);
470
+ if ($strict === false) {
471
+ $validScopes[] = T_INTERFACE;
472
+ $validScopes[] = T_TRAIT;
473
+ }
474
+
475
+ return $this->tokenHasScope($phpcsFile, $stackPtr, $validScopes);
476
+ }
477
+
478
+
479
  /**
480
  * Returns the fully qualified class name for a new class instantiation.
481
  *
506
  T_WHITESPACE,
507
  );
508
 
509
+ $start = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
510
+ // Bow out if the next token is a variable as we don't know where it was defined.
511
+ if ($tokens[$start]['code'] === T_VARIABLE) {
512
+ return '';
513
+ }
514
+
515
  $end = $phpcsFile->findNext($find, ($start + 1), null, true, null, true);
516
  $className = $phpcsFile->getTokensAsString($start, ($end - $start));
517
  $className = trim($className);
577
  return '';
578
  }
579
 
580
+ // Nothing to do if previous token is a variable as we don't know where it was defined.
581
+ if ($tokens[$stackPtr - 1]['code'] === T_VARIABLE) {
582
+ return '';
583
+ }
584
+
585
  // Nothing to do if 'parent' or 'static' as we don't know how far the class tree extends.
586
  if (in_array($tokens[$stackPtr - 1]['code'], array(T_PARENT, T_STATIC), true)) {
587
  return '';
591
  if ($tokens[$stackPtr - 1]['code'] === T_SELF) {
592
  $classDeclarationPtr = $phpcsFile->findPrevious(T_CLASS, $stackPtr - 1);
593
  if ($classDeclarationPtr === false) {
594
+ return '';
595
+ }
596
  $className = $phpcsFile->getDeclarationName($classDeclarationPtr);
597
  return $this->getFQName($phpcsFile, $classDeclarationPtr, $className);
598
  }
689
  if ($namespace !== false) {
690
  return $namespace;
691
  }
692
+ break; // Nested namespaces is not possible.
693
  }
 
694
  }
695
  }
696
 
803
  * @param int $stackPtr The position in the stack of the T_FUNCTION token
804
  * to acquire the parameters for.
805
  *
806
+ * @return array|false
807
  * @throws PHP_CodeSniffer_Exception If the specified $stackPtr is not of
808
  * type T_FUNCTION.
809
  */
953
 
954
  }//end getMethodParameters()
955
 
956
+
957
+ /**
958
+ * Get the hash algorithm name from the parameter in a hash function call.
959
+ *
960
+ * @param PHP_CodeSniffer_File $phpcsFile Instance of phpcsFile.
961
+ * @param int $stackPtr The position of the T_STRING function token.
962
+ *
963
+ * @return string|false The algorithm name without quotes if this was a relevant hash
964
+ * function call or false if it was not.
965
+ */
966
+ public function getHashAlgorithmParameter(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
967
+ {
968
+ $tokens = $phpcsFile->getTokens();
969
+
970
+ // Check for the existence of the token.
971
+ if (isset($tokens[$stackPtr]) === false) {
972
+ return false;
973
+ }
974
+
975
+ if ($tokens[$stackPtr]['code'] !== T_STRING) {
976
+ return false;
977
+ }
978
+
979
+ $functionName = $tokens[$stackPtr]['content'];
980
+ $functionNameLc = strtolower($functionName);
981
+
982
+ // Bow out if not one of the functions we're targetting.
983
+ if (isset($this->hashAlgoFunctions[$functionNameLc]) === false) {
984
+ return false;
985
+ }
986
+
987
+ // Get the parameter from the function call which should contain the algorithm name.
988
+ $algoParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->hashAlgoFunctions[$functionNameLc]);
989
+ if ($algoParam === false) {
990
+ return false;
991
+ }
992
+
993
+ /**
994
+ * Algorithm is a T_CONSTANT_ENCAPSED_STRING, so we need to remove the quotes.
995
+ */
996
+ $algo = strtolower(trim($algoParam['raw']));
997
+ $algo = $this->stripQuotes($algo);
998
+
999
+ return $algo;
1000
+ }
1001
+
1002
  }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/ConstantArraysUsingDefineSniff.php CHANGED
@@ -44,6 +44,10 @@ class PHPCompatibility_Sniffs_PHP_ConstantArraysUsingDefineSniff extends PHPComp
44
  */
45
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
  {
 
 
 
 
47
  $tokens = $phpcsFile->getTokens();
48
 
49
  $ignore = array(
@@ -60,28 +64,18 @@ class PHPCompatibility_Sniffs_PHP_ConstantArraysUsingDefineSniff extends PHPComp
60
  }
61
 
62
  $function = strtolower($tokens[$stackPtr]['content']);
 
 
 
63
 
64
- if ($function === 'define') {
65
- $openParenthesis = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, null, null, null, true);
66
- if ($openParenthesis === false) {
67
- return;
68
- }
69
-
70
- $comma = $phpcsFile->findNext(T_COMMA, $openParenthesis, $tokens[$openParenthesis]['parenthesis_closer']);
71
-
72
- if ($comma === false) {
73
- return;
74
- }
75
-
76
- $array = $phpcsFile->findNext(array(T_ARRAY, T_OPEN_SHORT_ARRAY), $comma, $tokens[$openParenthesis]['parenthesis_closer']);
77
 
78
- if ($array !== false) {
79
- if ($this->supportsAbove('7.0')) {
80
- return;
81
- } else {
82
- $phpcsFile->addError('Constant arrays using define are not allowed in PHP 5.6 or earlier', $array);
83
- }
84
- }
85
  }
86
  }
87
  }
44
  */
45
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
  {
47
+ if ($this->supportsBelow('5.6') !== true) {
48
+ return;
49
+ }
50
+
51
  $tokens = $phpcsFile->getTokens();
52
 
53
  $ignore = array(
64
  }
65
 
66
  $function = strtolower($tokens[$stackPtr]['content']);
67
+ if ($function !== 'define') {
68
+ return;
69
+ }
70
 
71
+ $secondParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 2);
72
+ if (isset($secondParam['start'], $secondParam['end']) === false) {
73
+ return;
74
+ }
 
 
 
 
 
 
 
 
 
75
 
76
+ $array = $phpcsFile->findNext(array(T_ARRAY, T_OPEN_SHORT_ARRAY), $secondParam['start'], ($secondParam['end'] + 1));
77
+ if ($array !== false) {
78
+ $phpcsFile->addError('Constant arrays using define are not allowed in PHP 5.6 or earlier', $array);
 
 
 
 
79
  }
80
  }
81
  }
vendor/wimg/php-compatibility/Sniffs/PHP/DeprecatedFunctionsSniff.php CHANGED
@@ -18,14 +18,6 @@
18
  */
19
  class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibility_Sniff
20
  {
21
-
22
- /**
23
- * If true, forbidden functions will be considered regular expressions.
24
- *
25
- * @var bool
26
- */
27
- protected $patternMatch = false;
28
-
29
  /**
30
  * A list of forbidden functions with their alternatives.
31
  *
@@ -636,6 +628,15 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibil
636
  ),
637
  );
638
 
 
 
 
 
 
 
 
 
 
639
  /**
640
  * Returns an array of tokens this test wants to listen for.
641
  *
@@ -647,12 +648,6 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibil
647
  // they want to check for, so now we can cache out the list.
648
  $this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions);
649
 
650
- if ($this->patternMatch === true) {
651
- foreach ($this->forbiddenFunctionNames as $i => $name) {
652
- $this->forbiddenFunctionNames[$i] = '/'.$name.'/i';
653
- }
654
- }
655
-
656
  return array(T_STRING);
657
 
658
  }//end register()
@@ -687,31 +682,12 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibil
687
  }
688
 
689
  $function = strtolower($tokens[$stackPtr]['content']);
690
- $pattern = null;
691
-
692
- if ($this->patternMatch === true) {
693
- $count = 0;
694
- $pattern = preg_replace(
695
- $this->forbiddenFunctionNames,
696
- $this->forbiddenFunctionNames,
697
- $function,
698
- 1,
699
- $count
700
- );
701
-
702
- if ($count === 0) {
703
- return;
704
- }
705
 
706
- // Remove the pattern delimiters and modifier.
707
- $pattern = substr($pattern, 1, -2);
708
- } else {
709
- if (in_array($function, $this->forbiddenFunctionNames) === false) {
710
- return;
711
- }
712
  }
713
 
714
- $this->addError($phpcsFile, $stackPtr, $function, $pattern);
715
 
716
  }//end process()
717
 
@@ -722,21 +698,16 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibil
722
  * @param int $stackPtr The position of the forbidden function
723
  * in the token array.
724
  * @param string $function The name of the forbidden function.
725
- * @param string $pattern The pattern used for the match.
726
  *
727
  * @return void
728
  */
729
- protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
730
  {
731
- if ($pattern === null) {
732
- $pattern = $function;
733
- }
734
-
735
  $error = '';
736
 
737
  $isError = false;
738
  $previousVersionStatus = null;
739
- foreach ($this->forbiddenFunctions[$pattern] as $version => $forbidden) {
740
  if ($this->supportsAbove($version)) {
741
  if ($version != 'alternative') {
742
  if ($previousVersionStatus !== $forbidden) {
@@ -756,8 +727,8 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibil
756
  $error = 'The use of function ' . $function . ' is ' . $error;
757
  $error = substr($error, 0, strlen($error) - 5);
758
 
759
- if ($this->forbiddenFunctions[$pattern]['alternative'] !== null) {
760
- $error .= '; use ' . $this->forbiddenFunctions[$pattern]['alternative'] . ' instead';
761
  }
762
 
763
  if ($isError === true) {
18
  */
19
  class PHPCompatibility_Sniffs_PHP_DeprecatedFunctionsSniff extends PHPCompatibility_Sniff
20
  {
 
 
 
 
 
 
 
 
21
  /**
22
  * A list of forbidden functions with their alternatives.
23
  *
628
  ),
629
  );
630
 
631
+ /**
632
+ * List of just the function names.
633
+ *
634
+ * Will be set automatically in the register() method.
635
+ *
636
+ * @var array
637
+ */
638
+ protected $forbiddenFunctionNames = array();
639
+
640
  /**
641
  * Returns an array of tokens this test wants to listen for.
642
  *
648
  // they want to check for, so now we can cache out the list.
649
  $this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions);
650
 
 
 
 
 
 
 
651
  return array(T_STRING);
652
 
653
  }//end register()
682
  }
683
 
684
  $function = strtolower($tokens[$stackPtr]['content']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
685
 
686
+ if (in_array($function, $this->forbiddenFunctionNames) === false) {
687
+ return;
 
 
 
 
688
  }
689
 
690
+ $this->addError($phpcsFile, $stackPtr, $function);
691
 
692
  }//end process()
693
 
698
  * @param int $stackPtr The position of the forbidden function
699
  * in the token array.
700
  * @param string $function The name of the forbidden function.
 
701
  *
702
  * @return void
703
  */
704
+ protected function addError($phpcsFile, $stackPtr, $function)
705
  {
 
 
 
 
706
  $error = '';
707
 
708
  $isError = false;
709
  $previousVersionStatus = null;
710
+ foreach ($this->forbiddenFunctions[$function] as $version => $forbidden) {
711
  if ($this->supportsAbove($version)) {
712
  if ($version != 'alternative') {
713
  if ($previousVersionStatus !== $forbidden) {
727
  $error = 'The use of function ' . $function . ' is ' . $error;
728
  $error = substr($error, 0, strlen($error) - 5);
729
 
730
+ if ($this->forbiddenFunctions[$function]['alternative'] !== null) {
731
+ $error .= '; use ' . $this->forbiddenFunctions[$function]['alternative'] . ' instead';
732
  }
733
 
734
  if ($isError === true) {
vendor/wimg/php-compatibility/Sniffs/PHP/DeprecatedIniDirectivesSniff.php CHANGED
@@ -222,12 +222,16 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedIniDirectivesSniff extends PHPCompat
222
  }
223
 
224
  $function = strtolower($tokens[$stackPtr]['content']);
225
- if ($function != 'ini_get' && $function != 'ini_set') {
226
  return;
227
  }
228
 
229
- $iniToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr, null);
230
- $filteredToken = trim($tokens[$iniToken]['content'], '\'"');
 
 
 
 
231
  if (isset($this->deprecatedIniDirectives[$filteredToken]) === false) {
232
  return;
233
  }
@@ -239,7 +243,7 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedIniDirectivesSniff extends PHPCompat
239
  if ($version !== 'alternative') {
240
  if ($this->supportsAbove($version)) {
241
  if ($forbidden === true) {
242
- $isError = ($function != 'ini_get') ?: false;
243
  $error .= " forbidden";
244
  } else {
245
  $isError = false;
@@ -258,9 +262,9 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedIniDirectivesSniff extends PHPCompat
258
  }
259
 
260
  if ($isError === true) {
261
- $phpcsFile->addError($error, $stackPtr);
262
  } else {
263
- $phpcsFile->addWarning($error, $stackPtr);
264
  }
265
  }
266
 
222
  }
223
 
224
  $function = strtolower($tokens[$stackPtr]['content']);
225
+ if ($function !== 'ini_get' && $function !== 'ini_set') {
226
  return;
227
  }
228
 
229
+ $iniToken = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 1);
230
+ if ($iniToken === false) {
231
+ return;
232
+ }
233
+
234
+ $filteredToken = $this->stripQuotes($iniToken['raw']);
235
  if (isset($this->deprecatedIniDirectives[$filteredToken]) === false) {
236
  return;
237
  }
243
  if ($version !== 'alternative') {
244
  if ($this->supportsAbove($version)) {
245
  if ($forbidden === true) {
246
+ $isError = ($function !== 'ini_get') ? true : false;
247
  $error .= " forbidden";
248
  } else {
249
  $isError = false;
262
  }
263
 
264
  if ($isError === true) {
265
+ $phpcsFile->addError($error, $iniToken['end']);
266
  } else {
267
+ $phpcsFile->addWarning($error, $iniToken['end']);
268
  }
269
  }
270
 
vendor/wimg/php-compatibility/Sniffs/PHP/DeprecatedPHP4StyleConstructorsSniff.php CHANGED
@@ -16,7 +16,8 @@
16
  * @package PHPCompatibility
17
  * @author Koen Eelen <koen.eelen@cu.be>
18
  */
19
- class PHPCompatibility_Sniffs_PHP_DeprecatedPHP4StyleConstructorsSniff extends PHPCompatibility_Sniff {
 
20
 
21
  public function register()
22
  {
@@ -45,7 +46,7 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedPHP4StyleConstructorsSniff extends P
45
 
46
  $class = $tokens[$stackPtr];
47
 
48
- if(!IsSet($class['scope_closer'])) {
49
  return;
50
  }
51
 
@@ -56,28 +57,31 @@ class PHPCompatibility_Sniffs_PHP_DeprecatedPHP4StyleConstructorsSniff extends P
56
  return;
57
  }
58
 
59
- $nextFunc = $stackPtr;
 
60
  $newConstructorFound = false;
61
  $oldConstructorFound = false;
62
- $oldConstructorPos = false;
63
  while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) {
64
  $funcName = $phpcsFile->getDeclarationName($nextFunc);
65
  if (empty($funcName) || is_string($funcName) === false) {
66
  continue;
67
  }
68
 
69
- if ($funcName === '__construct') {
 
 
70
  $newConstructorFound = true;
71
  }
72
 
73
- if ($funcName === $className) {
74
  $oldConstructorFound = true;
75
  $oldConstructorPos = $phpcsFile->findNext(T_STRING, $nextFunc);
76
  }
77
  }
78
 
79
  if ($newConstructorFound === false && $oldConstructorFound === true) {
80
- $phpcsFile->addError('Deprecated PHP4 style constructor are not supported since PHP7', $oldConstructorPos);
81
  }
82
  }
83
  }
16
  * @package PHPCompatibility
17
  * @author Koen Eelen <koen.eelen@cu.be>
18
  */
19
+ class PHPCompatibility_Sniffs_PHP_DeprecatedPHP4StyleConstructorsSniff extends PHPCompatibility_Sniff
20
+ {
21
 
22
  public function register()
23
  {
46
 
47
  $class = $tokens[$stackPtr];
48
 
49
+ if (isset($class['scope_closer']) === false) {
50
  return;
51
  }
52
 
57
  return;
58
  }
59
 
60
+ $nextFunc = $stackPtr;
61
+ $classNameLc = strtolower($className);
62
  $newConstructorFound = false;
63
  $oldConstructorFound = false;
64
+ $oldConstructorPos = -1;
65
  while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) {
66
  $funcName = $phpcsFile->getDeclarationName($nextFunc);
67
  if (empty($funcName) || is_string($funcName) === false) {
68
  continue;
69
  }
70
 
71
+ $funcNameLc = strtolower($funcName);
72
+
73
+ if ($funcNameLc === '__construct') {
74
  $newConstructorFound = true;
75
  }
76
 
77
+ if ($funcNameLc === $classNameLc) {
78
  $oldConstructorFound = true;
79
  $oldConstructorPos = $phpcsFile->findNext(T_STRING, $nextFunc);
80
  }
81
  }
82
 
83
  if ($newConstructorFound === false && $oldConstructorFound === true) {
84
+ $phpcsFile->addError('Use of deprecated PHP4 style class constructor is not supported since PHP 7', $oldConstructorPos);
85
  }
86
  }
87
  }
vendor/wimg/php-compatibility/Sniffs/PHP/EmptyNonVariableSniff.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * PHPCompatibility_Sniffs_PHP_EmptyNonVariableSniff.
4
+ *
5
+ * PHP version 5.5
6
+ *
7
+ * @category PHP
8
+ * @package PHPCompatibility
9
+ */
10
+
11
+ /**
12
+ * PHPCompatibility_Sniffs_PHP_EmptyNonVariableSniff.
13
+ *
14
+ * Verify that nothing but variables are passed to empty().
15
+ *
16
+ * PHP version 5.5
17
+ *
18
+ * @category PHP
19
+ * @package PHPCompatibility
20
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
21
+ */
22
+ class PHPCompatibility_Sniffs_PHP_EmptyNonVariableSniff extends PHPCompatibility_Sniff
23
+ {
24
+ /**
25
+ * List of tokens to check against.
26
+ *
27
+ * @var array
28
+ */
29
+ protected $tokenBlackList = array();
30
+
31
+ /**
32
+ * List of brackets which can be part of a variable variable.
33
+ *
34
+ * Key is the open bracket token, value the close bracket token.
35
+ *
36
+ * @var array
37
+ */
38
+ protected $bracketTokens = array(
39
+ T_OPEN_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
40
+ T_OPEN_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET,
41
+ );
42
+
43
+
44
+ /**
45
+ * Returns an array of tokens this test wants to listen for.
46
+ *
47
+ * @return array
48
+ */
49
+ public function register()
50
+ {
51
+ // Set the token blacklist only once.
52
+ $tokenBlackList = array_unique(array_merge(
53
+ PHP_CodeSniffer_Tokens::$assignmentTokens,
54
+ PHP_CodeSniffer_Tokens::$equalityTokens,
55
+ PHP_CodeSniffer_Tokens::$comparisonTokens,
56
+ PHP_CodeSniffer_Tokens::$operators,
57
+ PHP_CodeSniffer_Tokens::$booleanOperators,
58
+ PHP_CodeSniffer_Tokens::$castTokens,
59
+ array(T_OPEN_PARENTHESIS, T_STRING_CONCAT)
60
+ ));
61
+ $this->tokenBlackList = array_combine($tokenBlackList, $tokenBlackList);
62
+
63
+ return array(T_EMPTY);
64
+ }
65
+
66
+ /**
67
+ * Processes this test, when one of its tokens is encountered.
68
+ *
69
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
70
+ * @param int $stackPtr The position of the current token in the
71
+ * stack passed in $tokens.
72
+ *
73
+ * @return void
74
+ */
75
+ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
76
+ {
77
+ if ($this->supportsBelow('5.4') === false) {
78
+ return;
79
+ }
80
+
81
+ $tokens = $phpcsFile->getTokens();
82
+
83
+ $open = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true);
84
+ if ($open === false || isset($tokens[$open]['parenthesis_closer']) === false) {
85
+ return;
86
+ }
87
+
88
+ $close = $tokens[$open]['parenthesis_closer'];
89
+
90
+ // If no variable at all was found, then it's definitely a no-no.
91
+ $hasVariable = $phpcsFile->findNext(T_VARIABLE, $open + 1, $close);
92
+ if ($hasVariable === false) {
93
+ $this->addError($phpcsFile, $stackPtr);
94
+ return;
95
+ }
96
+
97
+ // Check if the variable found is at the right level. Deeper levels are always an error.
98
+ if (isset($tokens[$open + 1]['nested_parenthesis'], $tokens[$hasVariable]['nested_parenthesis'])) {
99
+ $nestingLevel = count($tokens[$open + 1]['nested_parenthesis']);
100
+ if (count($tokens[$hasVariable]['nested_parenthesis']) !== $nestingLevel) {
101
+ $this->addError($phpcsFile, $stackPtr);
102
+ return;
103
+ }
104
+ }
105
+
106
+ // Ok, so the first variable is at the right level, now are there any
107
+ // blacklisted tokens within the empty() ?
108
+ $hasBadToken = $phpcsFile->findNext($this->tokenBlackList, $open + 1, $close);
109
+ if ($hasBadToken === false) {
110
+ return;
111
+ }
112
+
113
+ // If there are also bracket tokens, the blacklisted token might be part of a variable
114
+ // variable, but if there are no bracket tokens, we know we have an error.
115
+ $hasBrackets = $phpcsFile->findNext($this->bracketTokens, $open + 1, $close);
116
+ if ($hasBrackets === false) {
117
+ $this->addError($phpcsFile, $stackPtr);
118
+ return;
119
+ }
120
+
121
+ // Ok, we have both a blacklisted token as well as brackets, so we need to walk
122
+ // the tokens of the variable variable.
123
+ for ($i = ($open + 1); $i < $close; $i++) {
124
+ // If this is a bracket token, skip to the end of the bracketed expression.
125
+ if (isset($this->bracketTokens[$tokens[$i]['code']], $tokens[$i]['bracket_closer'])) {
126
+ $i = $tokens[$i]['bracket_closer'];
127
+ continue;
128
+ }
129
+
130
+ // If it's a blacklisted token, not within brackets, we have an error.
131
+ if (isset($this->tokenBlackList[$tokens[$i]['code']])) {
132
+ $this->addError($phpcsFile, $stackPtr);
133
+ return;
134
+ }
135
+ }
136
+ }
137
+
138
+
139
+ /**
140
+ * Add the error message.
141
+ *
142
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
143
+ * @param int $stackPtr The position of the current token in the
144
+ * stack passed in $tokens.
145
+ *
146
+ * @return void
147
+ */
148
+ protected function addError($phpcsFile, $stackPtr)
149
+ {
150
+ $error = 'Only variables can be passed to empty() prior to PHP 5.5.';
151
+ $phpcsFile->addError($error, $stackPtr, 'Found');
152
+ }
153
+ }
vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenBreakContinueVariableArgumentsSniff.php CHANGED
@@ -13,7 +13,7 @@
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_ForbiddenBreakContinueVariableArguments.
15
  *
16
- * Discourages the use of assigning the return value of new by reference
17
  *
18
  * PHP version 5.4
19
  *
@@ -24,6 +24,8 @@
24
  */
25
  class PHPCompatibility_Sniffs_PHP_ForbiddenBreakContinueVariableArgumentsSniff extends PHPCompatibility_Sniff
26
  {
 
 
27
 
28
  /**
29
  * Returns an array of tokens this test wants to listen for.
@@ -47,33 +49,42 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenBreakContinueVariableArgumentsSniff e
47
  */
48
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
49
  {
50
- if ($this->supportsAbove('5.4')) {
51
- $tokens = $phpcsFile->getTokens();
52
- $nextSemicolonToken = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr), null, false);
53
- for ($curToken = $stackPtr + 1; $curToken < $nextSemicolonToken; $curToken++) {
54
- $gotError = false;
55
- if ($tokens[$curToken]['type'] == 'T_STRING') {
56
- // If the next non-whitespace token after the string
57
- // is an opening parenthesis then it's a function call.
58
- $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $curToken + 1, null, true);
59
- if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
60
- continue;
61
- } else {
62
- $gotError = true;
63
- }
64
- }
65
- switch ($tokens[$curToken]['type']) {
66
- case 'T_VARIABLE':
67
- case 'T_FUNCTION':
68
- $gotError = true;
69
- break;
70
- }
71
- if ($gotError === true) {
72
- $error = 'Using a variable argument on break or continue is forbidden since PHP 5.4';
73
- $phpcsFile->addError($error, $stackPtr);
74
  }
75
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
 
77
  }//end process()
78
 
79
  }//end class
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_ForbiddenBreakContinueVariableArguments.
15
  *
16
+ * Forbids variable arguments on break or continue statements.
17
  *
18
  * PHP version 5.4
19
  *
24
  */
25
  class PHPCompatibility_Sniffs_PHP_ForbiddenBreakContinueVariableArgumentsSniff extends PHPCompatibility_Sniff
26
  {
27
+ const ERROR_TYPE_VARIABLE = 'a variable argument';
28
+ const ERROR_TYPE_ZERO = '0 as an argument';
29
 
30
  /**
31
  * Returns an array of tokens this test wants to listen for.
49
  */
50
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
51
  {
52
+ if ($this->supportsAbove('5.4') === false) {
53
+ return;
54
+ }
55
+
56
+ $tokens = $phpcsFile->getTokens();
57
+ $nextSemicolonToken = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr), null, false);
58
+ $isError = false;
59
+ $errorType = '';
60
+ for ($curToken = $stackPtr + 1; $curToken < $nextSemicolonToken; $curToken++) {
61
+ if ($tokens[$curToken]['type'] === 'T_STRING') {
62
+ // If the next non-whitespace token after the string
63
+ // is an opening parenthesis then it's a function call.
64
+ $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $curToken + 1, null, true);
65
+ if ($tokens[$openBracket]['code'] === T_OPEN_PARENTHESIS) {
66
+ $isError = true;
67
+ $errorType = self::ERROR_TYPE_VARIABLE;
68
+ break;
 
 
 
 
 
 
 
69
  }
70
  }
71
+ else if (in_array($tokens[$curToken]['type'], array('T_VARIABLE', 'T_FUNCTION', 'T_CLOSURE'), true)) {
72
+ $isError = true;
73
+ $errorType = self::ERROR_TYPE_VARIABLE;
74
+ break;
75
+ }
76
+ else if ($tokens[$curToken]['type'] === 'T_LNUMBER' && $tokens[$curToken]['content'] === '0') {
77
+ $isError = true;
78
+ $errorType = self::ERROR_TYPE_ZERO;
79
+ break;
80
+ }
81
+ }
82
+
83
+ if ($isError === true && !empty($errorType)) {
84
+ $error = 'Using ' . $errorType . ' on break or continue is forbidden since PHP 5.4';
85
+ $phpcsFile->addError($error, $stackPtr);
86
  }
87
+
88
  }//end process()
89
 
90
  }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenCallTimePassByReferenceSniff.php CHANGED
@@ -51,117 +51,157 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenCallTimePassByReferenceSniff extends
51
  */
52
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
53
  {
54
- if ($this->supportsAbove('5.4')) {
55
- $tokens = $phpcsFile->getTokens();
56
-
57
- // Skip tokens that are the names of functions or classes
58
- // within their definitions. For example: function myFunction...
59
- // "myFunction" is T_STRING but we should skip because it is not a
60
- // function or method *call*.
61
- $functionName = $stackPtr;
62
- $findTokens = array_merge(
63
- PHP_CodeSniffer_Tokens::$emptyTokens,
64
- array(T_BITWISE_AND)
65
- );
66
 
67
- $functionKeyword = $phpcsFile->findPrevious(
68
- $findTokens,
69
- ($stackPtr - 1),
70
- null,
71
- true
72
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
- if ($tokens[$functionKeyword]['code'] === T_FUNCTION
75
- || $tokens[$functionKeyword]['code'] === T_CLASS
 
 
76
  ) {
77
- return;
78
  }
79
 
80
- // If the next non-whitespace token after the function or method call
81
- // is not an opening parenthesis then it cant really be a *call*.
82
- $openBracket = $phpcsFile->findNext(
83
  PHP_CodeSniffer_Tokens::$emptyTokens,
84
- ($functionName + 1),
85
- null,
86
  true
87
  );
88
 
89
- if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
90
- return;
 
91
  }
92
 
93
- $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
94
-
95
- $nextSeparator = $openBracket;
96
- while (($nextSeparator = $phpcsFile->findNext(T_VARIABLE, ($nextSeparator + 1), $closeBracket)) !== false) {
97
- // Make sure the variable belongs directly to this function call
98
- // and is not inside a nested function call or array.
99
- if (isset($tokens[$nextSeparator]['nested_parenthesis'])) {
100
- $brackets = $tokens[$nextSeparator]['nested_parenthesis'];
101
- $lastBracket = array_pop($brackets);
102
- if ($lastBracket !== $closeBracket) {
103
- continue;
104
- }
105
- }
 
 
 
 
 
 
 
106
 
107
- // Checking this: $value = my_function(...[*]$arg...).
108
- $tokenBefore = $phpcsFile->findPrevious(
109
- PHP_CodeSniffer_Tokens::$emptyTokens,
110
- ($nextSeparator - 1),
111
- null,
112
- true
113
- );
114
-
115
- if ($tokens[$tokenBefore]['code'] === T_BITWISE_AND) {
116
- // Checking this: $value = my_function(...[*]&$arg...).
117
- $tokenBefore = $phpcsFile->findPrevious(
118
  PHP_CodeSniffer_Tokens::$emptyTokens,
119
  ($tokenBefore - 1),
120
- null,
121
  true
122
  );
123
-
124
- // We have to exclude all uses of T_BITWISE_AND that are not
125
- // references. We use a blacklist approach as we prefer false
126
- // positives to not identifying a pass-by-reference call at all.
127
- // The blacklist may not yet be complete.
128
- switch ($tokens[$tokenBefore]['code']) {
129
- // In these cases T_BITWISE_AND represents
130
- // the bitwise and operator.
131
- case T_LNUMBER:
132
- case T_VARIABLE:
133
- case T_CLOSE_SQUARE_BRACKET:
134
- case T_CLOSE_PARENTHESIS:
135
- continue;
136
-
137
- // Unfortunately the tokenizer fails to recognize global constants,
138
- // class-constants and -attributes. Any of these are returned is
139
- // treated as T_STRING.
140
- // So we step back another token and check if it is a class
141
- // operator (-> or ::), which means we have a false positive.
142
- // Global constants still remain uncovered.
143
- case T_STRING:
144
- $tokenBeforePlus = $phpcsFile->findPrevious(
145
- PHP_CodeSniffer_Tokens::$emptyTokens,
146
- ($tokenBefore - 1),
147
- null,
148
- true
149
- );
150
- if( T_DOUBLE_COLON === $tokens[$tokenBeforePlus]['code'] ||
151
- T_OBJECT_OPERATOR === $tokens[$tokenBeforePlus]['code']
152
- ) {
153
- continue;
154
- }
155
-
156
- default:
157
- // T_BITWISE_AND represents a pass-by-reference.
158
- $error = 'Using a call-time pass-by-reference is prohibited since php 5.4';
159
- $phpcsFile->addError($error, $tokenBefore, 'NotAllowed');
160
- break;
161
  }
162
- }//end if
163
- }//end while
164
- }
165
- }//end process()
 
 
 
 
 
 
 
 
166
 
167
  }//end class
51
  */
52
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
53
  {
54
+ if ($this->supportsAbove('5.3') === false) {
55
+ return;
56
+ }
 
 
 
 
 
 
 
 
 
57
 
58
+ $tokens = $phpcsFile->getTokens();
59
+
60
+ // Skip tokens that are the names of functions or classes
61
+ // within their definitions. For example: function myFunction...
62
+ // "myFunction" is T_STRING but we should skip because it is not a
63
+ // function or method *call*.
64
+ $findTokens = array_merge(
65
+ PHP_CodeSniffer_Tokens::$emptyTokens,
66
+ array(T_BITWISE_AND)
67
+ );
68
+
69
+ $prevNonEmpty = $phpcsFile->findPrevious(
70
+ $findTokens,
71
+ ($stackPtr - 1),
72
+ null,
73
+ true
74
+ );
75
+
76
+ if ($prevNonEmpty !== false && in_array($tokens[$prevNonEmpty]['code'], array(T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT), true)) {
77
+ return;
78
+ }
79
+
80
+ // If the next non-whitespace token after the function or method call
81
+ // is not an opening parenthesis then it can't really be a *call*.
82
+ $openBracket = $phpcsFile->findNext(
83
+ PHP_CodeSniffer_Tokens::$emptyTokens,
84
+ ($stackPtr + 1),
85
+ null,
86
+ true
87
+ );
88
+
89
+ if ($openBracket === false || $tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS
90
+ || isset($tokens[$openBracket]['parenthesis_closer']) === false
91
+ ) {
92
+ return;
93
+ }
94
+
95
+ // Get the function call parameters.
96
+ $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
97
+ if (count($parameters) === 0) {
98
+ return;
99
+ }
100
+
101
+ // Which nesting level is the one we are interested in ?
102
+ $nestedParenthesisCount = 1;
103
+ if (isset($tokens[$openBracket]['nested_parenthesis'])) {
104
+ $nestedParenthesisCount = count($tokens[$openBracket]['nested_parenthesis']) + 1;
105
+ }
106
+
107
+ foreach ($parameters as $parameter) {
108
+ if ($this->isCallTimePassByReferenceParam($phpcsFile, $parameter, $nestedParenthesisCount) === true) {
109
+ // T_BITWISE_AND represents a pass-by-reference.
110
+ $error = 'Using a call-time pass-by-reference is deprecated since PHP 5.3';
111
+ if($this->supportsAbove('5.4')) {
112
+ $error .= ' and prohibited since PHP 5.4';
113
+ }
114
+ $phpcsFile->addError($error, $parameter['start'], 'NotAllowed');
115
+ }
116
+ }
117
+ }//end process()
118
+
119
+
120
+ protected function isCallTimePassByReferenceParam(PHP_CodeSniffer_File $phpcsFile, $parameter, $nestingLevel)
121
+ {
122
+ $tokens = $phpcsFile->getTokens();
123
+
124
+ $searchStartToken = $parameter['start'] - 1;
125
+ $searchEndToken = $parameter['end'] + 1;
126
+ $nextVariable = $searchStartToken;
127
+ do {
128
+ $nextVariable = $phpcsFile->findNext(T_VARIABLE, ($nextVariable + 1), $searchEndToken);
129
+ if ($nextVariable === false) {
130
+ return false;
131
+ }
132
 
133
+ // Make sure the variable belongs directly to this function call
134
+ // and is not inside a nested function call or array.
135
+ if (isset($tokens[$nextVariable]['nested_parenthesis']) === false ||
136
+ (count($tokens[$nextVariable]['nested_parenthesis']) !== $nestingLevel)
137
  ) {
138
+ continue;
139
  }
140
 
141
+
142
+ // Checking this: $value = my_function(...[*]$arg...).
143
+ $tokenBefore = $phpcsFile->findPrevious(
144
  PHP_CodeSniffer_Tokens::$emptyTokens,
145
+ ($nextVariable - 1),
146
+ $searchStartToken,
147
  true
148
  );
149
 
150
+ if ($tokenBefore === false || $tokens[$tokenBefore]['code'] !== T_BITWISE_AND) {
151
+ // Nothing before the token or no &.
152
+ continue;
153
  }
154
 
155
+ // Checking this: $value = my_function(...[*]&$arg...).
156
+ $tokenBefore = $phpcsFile->findPrevious(
157
+ PHP_CodeSniffer_Tokens::$emptyTokens,
158
+ ($tokenBefore - 1),
159
+ $searchStartToken,
160
+ true
161
+ );
162
+
163
+ // We have to exclude all uses of T_BITWISE_AND that are not
164
+ // references. We use a blacklist approach as we prefer false
165
+ // positives to not identifying a pass-by-reference call at all.
166
+ // The blacklist may not yet be complete.
167
+ switch ($tokens[$tokenBefore]['code']) {
168
+ // In these cases T_BITWISE_AND represents
169
+ // the bitwise and operator.
170
+ case T_LNUMBER:
171
+ case T_VARIABLE:
172
+ case T_CLOSE_SQUARE_BRACKET:
173
+ case T_CLOSE_PARENTHESIS:
174
+ break;
175
 
176
+ // Unfortunately the tokenizer fails to recognize global constants,
177
+ // class-constants and -attributes. Any of these are returned is
178
+ // treated as T_STRING.
179
+ // So we step back another token and check if it is a class
180
+ // operator (-> or ::), which means we have a false positive.
181
+ // Global constants still remain uncovered.
182
+ case T_STRING:
183
+ $tokenBeforePlus = $phpcsFile->findPrevious(
 
 
 
184
  PHP_CodeSniffer_Tokens::$emptyTokens,
185
  ($tokenBefore - 1),
186
+ $searchStartToken,
187
  true
188
  );
189
+ if ($tokens[$tokenBeforePlus]['code'] === T_DOUBLE_COLON ||
190
+ $tokens[$tokenBeforePlus]['code'] === T_OBJECT_OPERATOR
191
+ ) {
192
+ break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  }
194
+ // If not a class constant: fall through.
195
+
196
+ default:
197
+ // The found T_BITWISE_AND represents a pass-by-reference.
198
+ return true;
199
+ }
200
+
201
+ } while($nextVariable < $searchEndToken);
202
+
203
+ // This code should never be reached, but here in case of weird bugs ;-)
204
+ return false;
205
+ }
206
 
207
  }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenFunctionParametersWithSameNameSniff.php CHANGED
@@ -45,24 +45,33 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenFunctionParametersWithSameNameSniff e
45
  */
46
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
47
  {
48
- if ($this->supportsAbove('7.0')) {
49
- $tokens = $phpcsFile->getTokens();
50
- $token = $tokens[$stackPtr];
51
- // Skip function without body.
52
- if (isset($token['scope_opener']) === false) {
53
- return;
54
- }
 
 
 
 
 
 
 
 
 
 
55
 
56
- // Get all parameters from method signature.
57
- $paramNames = array();
58
- foreach ($phpcsFile->getMethodParameters($stackPtr) as $param) {
59
- $paramNames[] = strtolower($param['name']);
60
- }
61
 
62
- if (count($paramNames) != count(array_unique($paramNames))) {
63
- $phpcsFile->addError('Functions can not have multiple parameters with the same name since PHP 7.0', $stackPtr);
64
- }
65
  }
 
66
  }//end process()
67
 
68
  }//end class
45
  */
46
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
47
  {
48
+ if ($this->supportsAbove('7.0') === false) {
49
+ return;
50
+ }
51
+
52
+ $tokens = $phpcsFile->getTokens();
53
+ $token = $tokens[$stackPtr];
54
+ // Skip function without body.
55
+ if (isset($token['scope_opener']) === false) {
56
+ return;
57
+ }
58
+
59
+ // Get all parameters from method signature.
60
+ $parameters = $phpcsFile->getMethodParameters($stackPtr);
61
+ if (empty($parameters) || is_array($parameters) === false) {
62
+ return;
63
+ }
64
+
65
 
66
+ $paramNames = array();
67
+ foreach ($parameters as $param) {
68
+ $paramNames[] = strtolower($param['name']);
69
+ }
 
70
 
71
+ if (count($paramNames) != count(array_unique($paramNames))) {
72
+ $phpcsFile->addError('Functions can not have multiple parameters with the same name since PHP 7.0', $stackPtr);
 
73
  }
74
+
75
  }//end process()
76
 
77
  }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenGlobalVariableVariableSniff.php CHANGED
@@ -50,9 +50,7 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenGlobalVariableVariableSniff extends P
50
  $variable = $phpcsFile->findNext(T_VARIABLE, $stackPtr, $stackPtr + 4, false);
51
 
52
  if (isset($tokens[$variable - 1]) && $tokens[$variable - 1]['type'] == 'T_DOLLAR') {
53
- $error = sprintf(
54
- "Global with variable variables are not allowed since PHP 7.0"
55
- );
56
  $phpcsFile->addError($error, $stackPtr);
57
  }
58
  }
50
  $variable = $phpcsFile->findNext(T_VARIABLE, $stackPtr, $stackPtr + 4, false);
51
 
52
  if (isset($tokens[$variable - 1]) && $tokens[$variable - 1]['type'] == 'T_DOLLAR') {
53
+ $error = 'Global with variable variables is not allowed since PHP 7.0';
 
 
54
  $phpcsFile->addError($error, $stackPtr);
55
  }
56
  }
vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenNamesAsInvokedFunctionsSniff.php CHANGED
@@ -13,7 +13,7 @@
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_ForbiddenNamesAsInvokedFunctionsSniff.
15
  *
16
- * Prohibits the use of reserved keywords invoked as functions
17
  *
18
  * PHP version 5.4
19
  *
@@ -26,7 +26,7 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesAsInvokedFunctionsSniff extends
26
  {
27
 
28
  /**
29
- * List of tokens to register
30
  *
31
  * @var array
32
  */
@@ -54,11 +54,16 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesAsInvokedFunctionsSniff extends
54
  );
55
 
56
  /**
57
- * targetedStringTokens
 
 
 
58
  *
59
  * @var array
60
  */
61
  protected $targetedStringTokens = array(
 
 
62
  'callable' => '5.4',
63
  'insteadof' => '5.4',
64
  'trait' => '5.4',
@@ -80,10 +85,10 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesAsInvokedFunctionsSniff extends
80
  */
81
  public function register()
82
  {
83
- return array_merge(
84
- array(T_STRING),
85
- array_keys($this->targetedTokens)
86
- );
87
  }//end register()
88
 
89
  /**
@@ -97,65 +102,60 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesAsInvokedFunctionsSniff extends
97
  */
98
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
99
  {
100
- $tokens = $phpcsFile->getTokens();
101
- $isString = false;
 
 
102
 
103
  // For string tokens we only care if the string is a reserved word used
104
  // as a function. This only happens in older versions of PHP where the
105
  // token doesn't exist yet for that keyword.
106
- if ($tokens[$stackPtr]['code'] == T_STRING
107
- && (!in_array($tokens[$stackPtr]['content'], array_keys($this->targetedStringTokens)))
108
  ) {
109
  return;
110
  }
111
 
112
- if ($tokens[$stackPtr]['code'] == T_STRING) {
113
  $isString = true;
114
  }
115
 
116
  // Make sure this is a function call.
117
- $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
118
- if ($next === false) {
119
  // Not a function call.
120
  return;
121
  }
122
 
123
- if ($tokens[$next]['code'] == T_OPEN_PARENTHESIS) {
124
- $prev = $phpcsFile->findPrevious(array(T_WHITESPACE, T_COMMENT), ($stackPtr - 1), null, true);
 
 
 
125
 
126
- // This sniff isn't concerned about function declaration
127
- if ($tokens[$prev]['code'] == T_FUNCTION) {
 
 
 
128
  return;
129
  }
 
130
 
131
- // For the word catch, it is valid to have an open parenthesis
132
- // after it, but only if it is preceded by a right curly brace
133
- if ($tokens[$stackPtr]['code'] == T_CATCH) {
134
- if ($prev !== false) {
135
- if ($tokens[$prev]['code'] == T_CLOSE_CURLY_BRACKET) {
136
- // Ok, it's fine
137
- return;
138
- }
139
- }
140
- }
141
-
142
- $content = $tokens[$stackPtr]['content'];
143
- $tokenCode = $tokens[$stackPtr]['code'];
144
- if ($isString) {
145
- $version = $this->targetedStringTokens[$content];
146
- } else {
147
- $version = $this->targetedTokens[$tokenCode];
148
- }
149
 
150
- if ($this->supportsAbove($version)) {
151
- $error = sprintf(
152
- "'%s' is a reserved keyword introduced in PHP version %s and cannot be invoked as a function (%s)",
153
- strtolower($content),
154
- $version,
155
- $tokens[$stackPtr]['type']
156
- );
157
- $phpcsFile->addError($error, $stackPtr);
158
- }
159
  }
160
  }//end process()
161
 
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_ForbiddenNamesAsInvokedFunctionsSniff.
15
  *
16
+ * Prohibits the use of reserved keywords invoked as functions.
17
  *
18
  * PHP version 5.4
19
  *
26
  {
27
 
28
  /**
29
+ * List of tokens to register.
30
  *
31
  * @var array
32
  */
54
  );
55
 
56
  /**
57
+ * T_STRING keywords to recognize as targetted tokens.
58
+ *
59
+ * Compatibility for PHP versions where the keyword is not yet recognized
60
+ * as its own token.
61
  *
62
  * @var array
63
  */
64
  protected $targetedStringTokens = array(
65
+ 'goto' => '5.3',
66
+ 'namespace' => '5.3',
67
  'callable' => '5.4',
68
  'insteadof' => '5.4',
69
  'trait' => '5.4',
85
  */
86
  public function register()
87
  {
88
+ $tokens = array_keys($this->targetedTokens);
89
+ $tokens[] = T_STRING;
90
+
91
+ return $tokens;
92
  }//end register()
93
 
94
  /**
102
  */
103
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
104
  {
105
+ $tokens = $phpcsFile->getTokens();
106
+ $tokenCode = $tokens[$stackPtr]['code'];
107
+ $tokenContentLc = strtolower($tokens[$stackPtr]['content']);
108
+ $isString = false;
109
 
110
  // For string tokens we only care if the string is a reserved word used
111
  // as a function. This only happens in older versions of PHP where the
112
  // token doesn't exist yet for that keyword.
113
+ if ($tokenCode === T_STRING
114
+ && (isset($this->targetedStringTokens[$tokenContentLc]) === false)
115
  ) {
116
  return;
117
  }
118
 
119
+ if ($tokenCode === T_STRING) {
120
  $isString = true;
121
  }
122
 
123
  // Make sure this is a function call.
124
+ $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
125
+ if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS) {
126
  // Not a function call.
127
  return;
128
  }
129
 
130
+ // This sniff isn't concerned about function declaration.
131
+ $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
132
+ if ($prev !== false && $tokens[$prev]['code'] === T_FUNCTION) {
133
+ return;
134
+ }
135
 
136
+ // For the word catch, it is valid to have an open parenthesis
137
+ // after it, but only if it is preceded by a right curly brace.
138
+ if ($tokenCode === T_CATCH) {
139
+ if ($prev !== false && $tokens[$prev]['code'] === T_CLOSE_CURLY_BRACKET) {
140
+ // Ok, it's fine
141
  return;
142
  }
143
+ }
144
 
145
+ if ($isString) {
146
+ $version = $this->targetedStringTokens[$tokenContentLc];
147
+ } else {
148
+ $version = $this->targetedTokens[$tokenCode];
149
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
+ if ($this->supportsAbove($version)) {
152
+ $error = "'%s' is a reserved keyword introduced in PHP version %s and cannot be invoked as a function (%s)";
153
+ $data = array(
154
+ $tokenContentLc,
155
+ $version,
156
+ $tokens[$stackPtr]['type'],
157
+ );
158
+ $phpcsFile->addError($error, $stackPtr, 'Found', $data);
 
159
  }
160
  }//end process()
161
 
vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenNamesSniff.php CHANGED
@@ -13,7 +13,7 @@
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff.
15
  *
16
- * Prohibits the use of reserved keywords as class, function, namespace or constant names
17
  *
18
  * PHP version 5.4
19
  *
@@ -26,8 +26,8 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_S
26
  {
27
 
28
  /**
29
- * A list of keywords that can not be used as function, class and namespace name or constant name
30
- * Mentions since which version it's not allowed
31
  *
32
  * @var array(string => string)
33
  */
@@ -104,13 +104,12 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_S
104
 
105
  /**
106
  * A list of keywords that can follow use statements.
107
- * Mentions since which version it's not allowed
108
  *
109
  * @var array(string => string)
110
  */
111
  protected $validUseNames = array(
112
- 'const',
113
- 'function',
114
  );
115
 
116
  /**
@@ -118,7 +117,18 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_S
118
  *
119
  * @var array
120
  */
121
- protected $targetedTokens = array(T_CLASS, T_FUNCTION, T_NAMESPACE, T_STRING, T_CONST, T_USE, T_AS, T_EXTENDS, T_TRAIT);
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  /**
124
  * Returns an array of tokens this test wants to listen for.
@@ -148,9 +158,9 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_S
148
  $tokens = $phpcsFile->getTokens();
149
 
150
  /**
151
- * We distinguish between the class, function and namespace names or the define statements
152
  */
153
- if ($tokens[$stackPtr]['type'] == 'T_STRING') {
154
  $this->processString($phpcsFile, $stackPtr, $tokens);
155
  } else {
156
  $this->processNonString($phpcsFile, $stackPtr, $tokens);
@@ -170,28 +180,43 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_S
170
  */
171
  public function processNonString(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
172
  {
173
- if (in_array(strtolower($tokens[$stackPtr + 2]['content']), array_keys($this->invalidNames)) === false) {
 
 
 
 
 
 
174
  return;
175
  }
176
 
177
- // PHP 5.6 allows for use const and use function
178
  if ($this->supportsAbove('5.6')
179
- && $tokens[$stackPtr]['type'] == 'T_USE'
180
- && in_array(strtolower($tokens[$stackPtr + 2]['content']), $this->validUseNames)
181
  ) {
182
  return;
183
  }
184
 
185
- if (isset($tokens[$stackPtr - 2]) && $tokens[$stackPtr - 2]['type'] == 'T_NEW' && $tokens[$stackPtr - 1]['type'] == 'T_WHITESPACE' && $tokens[$stackPtr]['type'] == 'T_ANON_CLASS') {
 
 
 
 
 
186
  return;
187
  }
188
 
189
- if ($this->supportsAbove($this->invalidNames[strtolower($tokens[$stackPtr + 2]['content'])])) {
190
- $error = "Function name, class name, namespace name or constant name can not be reserved keyword '" . $tokens[$stackPtr + 2]['content'] . "' (since version " . $this->invalidNames[strtolower($tokens[$stackPtr + 2]['content'])] . ")";
191
- $phpcsFile->addError($error, $stackPtr);
 
 
 
 
192
  }
193
 
194
- }//end process()
195
 
196
  /**
197
  * Processes this test, when one of its tokens is encountered.
@@ -206,35 +231,36 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff extends PHPCompatibility_S
206
  */
207
  public function processString(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
208
  {
 
 
209
  // Special case for 5.3 where we want to find usage of traits, but
210
  // trait is not a token.
211
- if ($tokens[$stackPtr]['content'] == 'trait') {
212
  return $this->processNonString($phpcsFile, $stackPtr, $tokens);
213
  }
214
 
215
- // Look for any define/defined token (both T_STRING ones, blame Tokenizer)
216
- if ($tokens[$stackPtr]['content'] != 'define' && $tokens[$stackPtr]['content'] != 'defined') {
217
  return;
218
  }
219
 
220
- // Look for the end of the define/defined
221
- $closingParenthesis = $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr);
222
- if ($closingParenthesis === false) {
223
  return;
224
  }
225
 
226
- // Look for define name between current position and end of define/defined
227
- $defineContent = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr, $closingParenthesis);
228
- if ($defineContent === false) {
229
- return;
230
- }
231
 
232
- foreach ($this->invalidNames as $key => $value) {
233
- if (substr(strtolower($tokens[$defineContent]['content']), 1, -1) == $key) {
234
- $error = "Function name, class name, namespace name or constant name can not be reserved keyword '" . $key . "' (since version " . $value . ")";
235
- $phpcsFile->addError($error, $stackPtr);
236
- }
 
 
237
  }
238
- }//end process()
239
 
240
  }//end class
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_ForbiddenNamesSniff.
15
  *
16
+ * Prohibits the use of reserved keywords as class, function, namespace or constant names.
17
  *
18
  * PHP version 5.4
19
  *
26
  {
27
 
28
  /**
29
+ * A list of keywords that can not be used as function, class and namespace name or constant name.
30
+ * Mentions since which version it's not allowed.
31
  *
32
  * @var array(string => string)
33
  */
104
 
105
  /**
106
  * A list of keywords that can follow use statements.
 
107
  *
108
  * @var array(string => string)
109
  */
110
  protected $validUseNames = array(
111
+ 'const' => true,
112
+ 'function' => true,
113
  );
114
 
115
  /**
117
  *
118
  * @var array
119
  */
120
+ protected $targetedTokens = array(
121
+ T_CLASS,
122
+ T_FUNCTION,
123
+ T_NAMESPACE,
124
+ T_STRING,
125
+ T_CONST,
126
+ T_USE,
127
+ T_AS,
128
+ T_EXTENDS,
129
+ T_TRAIT,
130
+ T_INTERFACE,
131
+ );
132
 
133
  /**
134
  * Returns an array of tokens this test wants to listen for.
158
  $tokens = $phpcsFile->getTokens();
159
 
160
  /**
161
+ * We distinguish between the class, function and namespace names or the define statements.
162
  */
163
+ if ($tokens[$stackPtr]['type'] === 'T_STRING') {
164
  $this->processString($phpcsFile, $stackPtr, $tokens);
165
  } else {
166
  $this->processNonString($phpcsFile, $stackPtr, $tokens);
180
  */
181
  public function processNonString(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
182
  {
183
+ $nextNonEmpty = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
184
+ if ($nextNonEmpty === false) {
185
+ return;
186
+ }
187
+
188
+ $nextContentLc = strtolower($tokens[$nextNonEmpty]['content']);
189
+ if (isset($this->invalidNames[$nextContentLc]) === false) {
190
  return;
191
  }
192
 
193
+ // PHP 5.6 allows for use const and use function.
194
  if ($this->supportsAbove('5.6')
195
+ && $tokens[$stackPtr]['type'] === 'T_USE'
196
+ && isset($this->validUseNames[$nextContentLc]) === true
197
  ) {
198
  return;
199
  }
200
 
201
+ // Deal with anonymous classes.
202
+ $prevNonEmpty = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
203
+ if ($prevNonEmpty !== false
204
+ && $tokens[$prevNonEmpty]['type'] === 'T_NEW'
205
+ && $tokens[$stackPtr]['type'] === 'T_ANON_CLASS'
206
+ ) {
207
  return;
208
  }
209
 
210
+ if ($this->supportsAbove($this->invalidNames[$nextContentLc])) {
211
+ $error = "Function name, class name, namespace name or constant name can not be reserved keyword '%s' (since version %s)";
212
+ $data = array(
213
+ $tokens[$nextNonEmpty]['content'],
214
+ $this->invalidNames[$nextContentLc],
215
+ );
216
+ $phpcsFile->addError($error, $stackPtr, 'Found', $data);
217
  }
218
 
219
+ }//end processNonString()
220
 
221
  /**
222
  * Processes this test, when one of its tokens is encountered.
231
  */
232
  public function processString(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
233
  {
234
+ $tokenContentLc = strtolower($tokens[$stackPtr]['content']);
235
+
236
  // Special case for 5.3 where we want to find usage of traits, but
237
  // trait is not a token.
238
+ if ($tokenContentLc === 'trait') {
239
  return $this->processNonString($phpcsFile, $stackPtr, $tokens);
240
  }
241
 
242
+ // Look for any define/defined tokens (both T_STRING ones, blame Tokenizer).
243
+ if ($tokenContentLc !== 'define' && $tokenContentLc !== 'defined') {
244
  return;
245
  }
246
 
247
+ // Retrieve the define(d) constant name.
248
+ $firstParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 1);
249
+ if ($firstParam === false) {
250
  return;
251
  }
252
 
253
+ $defineName = strtolower($firstParam['raw']);
254
+ $defineName = $this->stripQuotes($defineName);
 
 
 
255
 
256
+ if (isset($this->invalidNames[$defineName]) && $this->supportsAbove($this->invalidNames[$defineName])) {
257
+ $error = "Function name, class name, namespace name or constant name can not be reserved keyword '%s' (since PHP version %s)";
258
+ $data = array(
259
+ $defineName,
260
+ $this->invalidNames[$defineName],
261
+ );
262
+ $phpcsFile->addError($error, $stackPtr, 'Found', $data);
263
  }
264
+ }//end processString()
265
 
266
  }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/ForbiddenNegativeBitshiftSniff.php CHANGED
@@ -12,7 +12,7 @@
12
  /**
13
  * PHPCompatibility_Sniffs_PHP_ForbiddenNegativeBitshift.
14
  *
15
- * Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0
16
  *
17
  * @category PHP
18
  * @package PHPCompatibility
@@ -43,15 +43,23 @@ class PHPCompatibility_Sniffs_PHP_ForbiddenNegativeBitshiftSniff extends PHPComp
43
  */
44
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
45
  {
46
- if ($this->supportsAbove('7.0')) {
47
- $tokens = $phpcsFile->getTokens();
48
-
49
- $nextNumber = $phpcsFile->findNext(T_LNUMBER, $stackPtr, null, false, null, true);
50
- if ($tokens[$nextNumber - 1]['code'] == T_MINUS) {
51
- $error = 'Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0';
52
- $phpcsFile->addError($error, $nextNumber - 1);
53
- }
54
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }//end process()
56
 
57
  }//end class
12
  /**
13
  * PHPCompatibility_Sniffs_PHP_ForbiddenNegativeBitshift.
14
  *
15
+ * Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0.
16
  *
17
  * @category PHP
18
  * @package PHPCompatibility
43
  */
44
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
45
  {
46
+ if ($this->supportsAbove('7.0') === false) {
47
+ return;
 
 
 
 
 
 
48
  }
49
+
50
+ $nextNumber = $phpcsFile->findNext(T_LNUMBER, $stackPtr + 1, null, false, null, true);
51
+ if($nextNumber === false || ($stackPtr + 1) === $nextNumber) {
52
+ return;
53
+ }
54
+
55
+ $hasMinusSign = $phpcsFile->findNext(T_MINUS, $stackPtr + 1, $nextNumber, false, null, true);
56
+ if($hasMinusSign === false) {
57
+ return;
58
+ }
59
+
60
+ $error = 'Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0';
61
+ $phpcsFile->addError($error, $hasMinusSign);
62
+
63
  }//end process()
64
 
65
  }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/MbstringReplaceEModifierSniff.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * PHPCompatibility_Sniffs_PHP_MbstringReplaceEModifierSniff.
4
+ *
5
+ * PHP version 7.1
6
+ *
7
+ * @category PHP
8
+ * @package PHPCompatibility
9
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
10
+ */
11
+
12
+ /**
13
+ * PHPCompatibility_Sniffs_PHP_MbstringReplaceEModifierSniff.
14
+ *
15
+ * @category PHP
16
+ * @package PHPCompatibility
17
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
18
+ */
19
+ class PHPCompatibility_Sniffs_PHP_MbstringReplaceEModifierSniff extends PHPCompatibility_Sniff
20
+ {
21
+
22
+ /**
23
+ * Functions to check for.
24
+ *
25
+ * Key is the function name, value the parameter position of the options parameter.
26
+ *
27
+ * @var array
28
+ */
29
+ protected $functions = array(
30
+ 'mb_ereg_replace' => 4,
31
+ 'mb_eregi_replace' => 4,
32
+ 'mb_regex_set_options' => 1,
33
+ );
34
+
35
+
36
+ /**
37
+ * Returns an array of tokens this test wants to listen for.
38
+ *
39
+ * @return array
40
+ */
41
+ public function register()
42
+ {
43
+ return array(T_STRING);
44
+ }//end register()
45
+
46
+
47
+ /**
48
+ * Processes this test, when one of its tokens is encountered.
49
+ *
50
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
51
+ * @param int $stackPtr The position of the current token in the
52
+ * stack passed in $tokens.
53
+ *
54
+ * @return void
55
+ */
56
+ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
57
+ {
58
+ if ($this->supportsAbove('7.1') === false) {
59
+ return;
60
+ }
61
+
62
+ $tokens = $phpcsFile->getTokens();
63
+ $functionNameLc = strtolower($tokens[$stackPtr]['content']);
64
+
65
+ // Bow out if not one of the functions we're targetting.
66
+ if ( isset($this->functions[$functionNameLc]) === false ) {
67
+ return;
68
+ }
69
+
70
+ // Get the options parameter in the function call.
71
+ $optionsParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->functions[$functionNameLc]);
72
+ if ($optionsParam === false) {
73
+ return;
74
+ }
75
+
76
+ $stringToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $optionsParam['start'], $optionsParam['end'] + 1);
77
+ if ($stringToken === false) {
78
+ // No string token found in the options parameter, so skip it (e.g. variable passed in).
79
+ return;
80
+ }
81
+
82
+ /**
83
+ * Get the content of any string tokens in the options parameter and remove the quotes.
84
+ */
85
+ $options = $this->stripQuotes($tokens[$stringToken]['content']);
86
+ if ($stringToken !== $optionsParam['end']) {
87
+ while ($stringToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stringToken + 1, $optionsParam['end'] + 1)) {
88
+ if ($tokens[$stringToken]['code'] === T_CONSTANT_ENCAPSED_STRING) {
89
+ $options .= $this->stripQuotes($tokens[$stringToken]['content']);
90
+ }
91
+ }
92
+ }
93
+
94
+ if (strpos($options, 'e') !== false) {
95
+ $error = 'The Mbstring regex "e" modifier is deprecated since PHP 7.1.';
96
+
97
+ // The alternative mb_ereg_replace_callback() function is only available since 5.4.1
98
+ if ($this->supportsBelow('5.4.1') === false) {
99
+ $error .= ' Use mb_ereg_replace_callback() instead (PHP 5.4.1+).';
100
+ }
101
+
102
+ $phpcsFile->addError($error, $stackPtr, 'Found');
103
+ }
104
+
105
+ }//end process()
106
+
107
+ }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/NewAnonymousClassesSniff.php CHANGED
@@ -46,17 +46,18 @@ class PHPCompatibility_Sniffs_PHP_NewAnonymousClassesSniff extends PHPCompatibil
46
  */
47
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
48
  {
 
 
 
 
49
  $whitespace = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, $stackPtr + 2);
50
  $class = $phpcsFile->findNext(T_ANON_CLASS, $stackPtr + 2, $stackPtr + 3);
51
  if ($whitespace === false || $class === false) {
52
  return;
53
  }
54
 
55
- if ($this->supportsAbove('7.0')) {
56
- return;
57
- } else {
58
- $phpcsFile->addError('Anonymous classes are not supported in PHP 5.6 or earlier', $stackPtr);
59
- }
60
  }//end process()
61
 
62
 
46
  */
47
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
48
  {
49
+ if ($this->supportsBelow('5.6') === false) {
50
+ return;
51
+ }
52
+
53
  $whitespace = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, $stackPtr + 2);
54
  $class = $phpcsFile->findNext(T_ANON_CLASS, $stackPtr + 2, $stackPtr + 3);
55
  if ($whitespace === false || $class === false) {
56
  return;
57
  }
58
 
59
+ $phpcsFile->addError('Anonymous classes are not supported in PHP 5.6 or earlier', $stackPtr);
60
+
 
 
 
61
  }//end process()
62
 
63
 
vendor/wimg/php-compatibility/Sniffs/PHP/NewClassesSniff.php CHANGED
@@ -193,6 +193,11 @@ class PHPCompatibility_Sniffs_PHP_NewClassesSniff extends PHPCompatibility_Sniff
193
  */
194
  public function register()
195
  {
 
 
 
 
 
196
  return array(
197
  T_NEW,
198
  T_CLASS,
@@ -234,9 +239,10 @@ class PHPCompatibility_Sniffs_PHP_NewClassesSniff extends PHPCompatibility_Sniff
234
  return;
235
  }
236
 
237
- $className = substr($FQClassName, 1); // Remove global namespace indicator.
 
238
 
239
- if (array_key_exists($className, $this->newClasses) === false) {
240
  return;
241
  }
242
 
@@ -252,20 +258,16 @@ class PHPCompatibility_Sniffs_PHP_NewClassesSniff extends PHPCompatibility_Sniff
252
  * @param int $stackPtr The position of the function
253
  * in the token array.
254
  * @param string $className The name of the class.
255
- * @param string $pattern The pattern used for the match.
256
  *
257
  * @return void
258
  */
259
- protected function addError($phpcsFile, $stackPtr, $className, $pattern=null)
260
  {
261
- if ($pattern === null) {
262
- $pattern = $className;
263
- }
264
-
265
- $error = '';
266
 
267
- $isError = false;
268
- foreach ($this->newClasses[$pattern] as $version => $present) {
269
  if ($this->supportsBelow($version)) {
270
  if ($present === false) {
271
  $isError = true;
193
  */
194
  public function register()
195
  {
196
+ // Handle case-insensitivity of class names.
197
+ $keys = array_keys( $this->newClasses );
198
+ $keys = array_map( 'strtolower', $keys );
199
+ $this->newClasses = array_combine( $keys, $this->newClasses );
200
+
201
  return array(
202
  T_NEW,
203
  T_CLASS,
239
  return;
240
  }
241
 
242
+ $className = substr($FQClassName, 1); // Remove global namespace indicator.
243
+ $classNameLc = strtolower($className);
244
 
245
+ if (isset($this->newClasses[$classNameLc]) === false) {
246
  return;
247
  }
248
 
258
  * @param int $stackPtr The position of the function
259
  * in the token array.
260
  * @param string $className The name of the class.
 
261
  *
262
  * @return void
263
  */
264
+ protected function addError($phpcsFile, $stackPtr, $className)
265
  {
266
+ $error = '';
267
+ $isError = false;
268
+ $classNameLc = strtolower($className);
 
 
269
 
270
+ foreach ($this->newClasses[$classNameLc] as $version => $present) {
 
271
  if ($this->supportsBelow($version)) {
272
  if ($present === false) {
273
  $isError = true;
vendor/wimg/php-compatibility/Sniffs/PHP/NewExecutionDirectivesSniff.php CHANGED
@@ -123,7 +123,7 @@ class PHPCompatibility_Sniffs_PHP_NewExecutionDirectivesSniff extends PHPCompati
123
  return;
124
  }
125
 
126
- $this->addErrorOnInvalidValue($phpcsFile, $valuePtr, $directiveContent);
127
  }
128
 
129
  }//end process()
@@ -193,13 +193,13 @@ class PHPCompatibility_Sniffs_PHP_NewExecutionDirectivesSniff extends PHPCompati
193
  *
194
  * @return void
195
  */
196
- protected function addErrorOnInvalidValue($phpcsFile, $stackPtr, $directive)
197
  {
198
  $tokens = $phpcsFile->getTokens();
199
 
200
  $value = $tokens[$stackPtr]['content'];
201
  if ($tokens[$stackPtr]['code'] === T_CONSTANT_ENCAPSED_STRING) {
202
- $value = trim($value, '\'"');
203
  }
204
 
205
  $isError = false;
@@ -221,7 +221,7 @@ class PHPCompatibility_Sniffs_PHP_NewExecutionDirectivesSniff extends PHPCompati
221
  $directive,
222
  $value,
223
  );
224
- $phpcsFile->addError($error, $stackPtr, 'InvalidDirectiveValueFound', $data);
225
  }
226
  }// addErrorOnInvalidValue()
227
 
123
  return;
124
  }
125
 
126
+ $this->addWarningOnInvalidValue($phpcsFile, $valuePtr, $directiveContent);
127
  }
128
 
129
  }//end process()
193
  *
194
  * @return void
195
  */
196
+ protected function addWarningOnInvalidValue($phpcsFile, $stackPtr, $directive)
197
  {
198
  $tokens = $phpcsFile->getTokens();
199
 
200
  $value = $tokens[$stackPtr]['content'];
201
  if ($tokens[$stackPtr]['code'] === T_CONSTANT_ENCAPSED_STRING) {
202
+ $value = $this->stripQuotes($value);
203
  }
204
 
205
  $isError = false;
221
  $directive,
222
  $value,
223
  );
224
+ $phpcsFile->addWarning($error, $stackPtr, 'InvalidDirectiveValueFound', $data);
225
  }
226
  }// addErrorOnInvalidValue()
227
 
vendor/wimg/php-compatibility/Sniffs/PHP/NewFunctionArrayDereferencingSniff.php CHANGED
@@ -37,28 +37,46 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionArrayDereferencingSniff extends PHP
37
  */
38
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
39
  {
 
 
 
 
40
  $tokens = $phpcsFile->getTokens();
41
 
42
- $ignore = array(
43
- T_DOUBLE_COLON,
44
- T_OBJECT_OPERATOR,
45
- T_FUNCTION,
46
- T_CONST,
47
- );
48
 
49
- $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
50
- if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
51
- // Not a call to a PHP function.
52
  return;
53
  }
54
 
55
- if (isset($tokens[$stackPtr + 1]) && $tokens[$stackPtr + 1]['type'] == 'T_OPEN_PARENTHESIS') {
56
- $closeParenthesis = $tokens[$stackPtr + 1]['parenthesis_closer'];
57
- if ($tokens[$closeParenthesis + 1]['type'] == 'T_OPEN_SQUARE_BRACKET') {
58
- if ($this->supportsBelow('5.3')) {
59
- $phpcsFile->addError('Function array dereferencing is not present in PHP version 5.3 or earlier', $stackPtr + 3);
60
- }
 
 
 
 
 
 
 
 
 
61
  }
62
  }
 
 
 
 
 
 
 
63
  }//end process()
64
  }//end class
37
  */
38
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
39
  {
40
+ if ($this->supportsBelow('5.3') === false) {
41
+ return;
42
+ }
43
+
44
  $tokens = $phpcsFile->getTokens();
45
 
46
+ // Next non-empty token should be the open parenthesis.
47
+ $openParenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true);
48
+ if ($openParenthesis === false || $tokens[$openParenthesis]['code'] !== T_OPEN_PARENTHESIS) {
49
+ return;
50
+ }
 
51
 
52
+ // Don't throw errors during live coding.
53
+ if (isset($tokens[$openParenthesis]['parenthesis_closer']) === false) {
 
54
  return;
55
  }
56
 
57
+ // Is this T_STRING really a function or method call ?
58
+ $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
59
+ if($prevToken !== false && in_array($tokens[$prevToken]['code'], array(T_DOUBLE_COLON, T_OBJECT_OPERATOR), true) === false) {
60
+ $ignore = array(
61
+ T_FUNCTION,
62
+ T_CONST,
63
+ T_USE,
64
+ T_NEW,
65
+ T_CLASS,
66
+ T_INTERFACE,
67
+ );
68
+
69
+ if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
70
+ // Not a call to a PHP function or method.
71
+ return;
72
  }
73
  }
74
+
75
+ $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
76
+ $nextNonEmpty = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($closeParenthesis + 1), null, true, null, true);
77
+ if ($nextNonEmpty !== false && $tokens[$nextNonEmpty]['type'] === 'T_OPEN_SQUARE_BRACKET') {
78
+ $phpcsFile->addError('Function array dereferencing is not present in PHP version 5.3 or earlier', $nextNonEmpty);
79
+ }
80
+
81
  }//end process()
82
  }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/NewFunctionParametersSniff.php CHANGED
@@ -16,14 +16,6 @@
16
  */
17
  class PHPCompatibility_Sniffs_PHP_NewFunctionParametersSniff extends PHPCompatibility_Sniff
18
  {
19
-
20
- /**
21
- * If true, forbidden functions will be considered regular expressions.
22
- *
23
- * @var bool
24
- */
25
- protected $patternMatch = false;
26
-
27
  /**
28
  * A list of new functions, not present in older versions.
29
  *
@@ -731,12 +723,6 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionParametersSniff extends PHPCompatib
731
  // they want to check for, so now we can cache out the list.
732
  $this->newFunctionParametersNames = array_keys($this->newFunctionParameters);
733
 
734
- if ($this->patternMatch === true) {
735
- foreach ($this->newFunctionParametersNames as $i => $name) {
736
- $this->newFunctionParametersNames[$i] = '/'.$name.'/i';
737
- }
738
- }
739
-
740
  return array(T_STRING);
741
  }//end register()
742
 
16
  */
17
  class PHPCompatibility_Sniffs_PHP_NewFunctionParametersSniff extends PHPCompatibility_Sniff
18
  {
 
 
 
 
 
 
 
 
19
  /**
20
  * A list of new functions, not present in older versions.
21
  *
723
  // they want to check for, so now we can cache out the list.
724
  $this->newFunctionParametersNames = array_keys($this->newFunctionParameters);
725
 
 
 
 
 
 
 
726
  return array(T_STRING);
727
  }//end register()
728
 
vendor/wimg/php-compatibility/Sniffs/PHP/NewFunctionsSniff.php CHANGED
@@ -16,14 +16,6 @@
16
  */
17
  class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sniff
18
  {
19
-
20
- /**
21
- * If true, forbidden functions will be considered regular expressions.
22
- *
23
- * @var bool
24
- */
25
- protected $patternMatch = false;
26
-
27
  /**
28
  * A list of new functions, not present in older versions.
29
  *
@@ -1236,12 +1228,6 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
1236
  $this->forbiddenFunctionNames = array_map('strtolower', $this->forbiddenFunctionNames);
1237
  $this->forbiddenFunctions = array_combine($this->forbiddenFunctionNames, $this->forbiddenFunctions);
1238
 
1239
- if ($this->patternMatch === true) {
1240
- foreach ($this->forbiddenFunctionNames as $i => $name) {
1241
- $this->forbiddenFunctionNames[$i] = '/'.$name.'/i';
1242
- }
1243
- }
1244
-
1245
  return array(T_STRING);
1246
 
1247
  }//end register()
@@ -1277,31 +1263,12 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
1277
  }
1278
 
1279
  $function = strtolower($tokens[$stackPtr]['content']);
1280
- $pattern = null;
1281
 
1282
- if ($this->patternMatch === true) {
1283
- $count = 0;
1284
- $pattern = preg_replace(
1285
- $this->forbiddenFunctionNames,
1286
- $this->forbiddenFunctionNames,
1287
- $function,
1288
- 1,
1289
- $count
1290
- );
1291
-
1292
- if ($count === 0) {
1293
- return;
1294
- }
1295
-
1296
- // Remove the pattern delimiters and modifier.
1297
- $pattern = substr($pattern, 1, -2);
1298
- } else {
1299
- if (in_array($function, $this->forbiddenFunctionNames) === false) {
1300
- return;
1301
- }
1302
  }
1303
 
1304
- $this->addError($phpcsFile, $stackPtr, $tokens[$stackPtr]['content'], $pattern);
1305
 
1306
  }//end process()
1307
 
@@ -1313,20 +1280,16 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
1313
  * @param int $stackPtr The position of the function
1314
  * in the token array.
1315
  * @param string $function The name of the function.
1316
- * @param string $pattern The pattern used for the match.
1317
  *
1318
  * @return void
1319
  */
1320
- protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
1321
  {
1322
- if ($pattern === null) {
1323
- $pattern = strtolower($function);
1324
- }
1325
-
1326
- $error = '';
1327
 
1328
  $isError = false;
1329
- foreach ($this->forbiddenFunctions[$pattern] as $version => $present) {
1330
  if ($this->supportsBelow($version)) {
1331
  if ($present === false) {
1332
  $isError = true;
16
  */
17
  class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sniff
18
  {
 
 
 
 
 
 
 
 
19
  /**
20
  * A list of new functions, not present in older versions.
21
  *
1228
  $this->forbiddenFunctionNames = array_map('strtolower', $this->forbiddenFunctionNames);
1229
  $this->forbiddenFunctions = array_combine($this->forbiddenFunctionNames, $this->forbiddenFunctions);
1230
 
 
 
 
 
 
 
1231
  return array(T_STRING);
1232
 
1233
  }//end register()
1263
  }
1264
 
1265
  $function = strtolower($tokens[$stackPtr]['content']);
 
1266
 
1267
+ if (in_array($function, $this->forbiddenFunctionNames) === false) {
1268
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1269
  }
1270
 
1271
+ $this->addError($phpcsFile, $stackPtr, $tokens[$stackPtr]['content']);
1272
 
1273
  }//end process()
1274
 
1280
  * @param int $stackPtr The position of the function
1281
  * in the token array.
1282
  * @param string $function The name of the function.
 
1283
  *
1284
  * @return void
1285
  */
1286
+ protected function addError($phpcsFile, $stackPtr, $function)
1287
  {
1288
+ $functionLc = strtolower($function);
1289
+ $error = '';
 
 
 
1290
 
1291
  $isError = false;
1292
+ foreach ($this->forbiddenFunctions[$functionLc] as $version => $present) {
1293
  if ($this->supportsBelow($version)) {
1294
  if ($present === false) {
1295
  $isError = true;
vendor/wimg/php-compatibility/Sniffs/PHP/NewGroupUseDeclarationsSniff.php CHANGED
@@ -44,7 +44,7 @@ class PHPCompatibility_Sniffs_PHP_NewGroupUseDeclarationsSniff extends PHPCompat
44
  */
45
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
  {
47
- if (!$this->supportsAbove('7.0')) {
48
  $phpcsFile->addError('Group use declarations are not allowed in PHP 5.6 or earlier', $stackPtr);
49
  }
50
  }//end process()
44
  */
45
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
  {
47
+ if ($this->supportsBelow('5.6')) {
48
  $phpcsFile->addError('Group use declarations are not allowed in PHP 5.6 or earlier', $stackPtr);
49
  }
50
  }//end process()
vendor/wimg/php-compatibility/Sniffs/PHP/NewHashAlgorithmsSniff.php ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * PHPCompatibility_Sniffs_PHP_NewHashAlgorithmsSniff.
4
+ *
5
+ * @category PHP
6
+ * @package PHPCompatibility
7
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
8
+ */
9
+
10
+ /**
11
+ * PHPCompatibility_Sniffs_PHP_NewHashAlgorithmsSniff.
12
+ *
13
+ * @category PHP
14
+ * @package PHPCompatibility
15
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
16
+ */
17
+ class PHPCompatibility_Sniffs_PHP_NewHashAlgorithmsSniff extends PHPCompatibility_Sniff
18
+ {
19
+ /**
20
+ * A list of new hash algorithms, not present in older versions.
21
+ *
22
+ * The array lists : version number with false (not present) or true (present).
23
+ * If's sufficient to list the first version where the hash algorithm appears.
24
+ *
25
+ * @var array(string => array(string => bool))
26
+ */
27
+ protected $newAlgorithms = array(
28
+ 'md2' => array(
29
+ '5.2' => false,
30
+ '5.3' => true,
31
+ ),
32
+ 'ripemd256' => array(
33
+ '5.2' => false,
34
+ '5.3' => true,
35
+ ),
36
+ 'ripemd320' => array(
37
+ '5.2' => false,
38
+ '5.3' => true,
39
+ ),
40
+ 'salsa10' => array(
41
+ '5.2' => false,
42
+ '5.3' => true,
43
+ ),
44
+ 'salsa20' => array(
45
+ '5.2' => false,
46
+ '5.3' => true,
47
+ ),
48
+ 'snefru256' => array(
49
+ '5.2' => false,
50
+ '5.3' => true,
51
+ ),
52
+ 'sha224' => array(
53
+ '5.2' => false,
54
+ '5.3' => true,
55
+ ),
56
+ 'joaat' => array(
57
+ '5.3' => false,
58
+ '5.4' => true,
59
+ ),
60
+ 'fnv132' => array(
61
+ '5.3' => false,
62
+ '5.4' => true,
63
+ ),
64
+ 'fnv164' => array(
65
+ '5.3' => false,
66
+ '5.4' => true,
67
+ ),
68
+ 'gost-crypto' => array(
69
+ '5.5' => false,
70
+ '5.6' => true,
71
+ ),
72
+ );
73
+
74
+
75
+ /**
76
+ * Returns an array of tokens this test wants to listen for.
77
+ *
78
+ * @return array
79
+ */
80
+ public function register()
81
+ {
82
+ return array(T_STRING);
83
+
84
+ }//end register()
85
+
86
+
87
+ /**
88
+ * Processes this test, when one of its tokens is encountered.
89
+ *
90
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
91
+ * @param int $stackPtr The position of the current token in the
92
+ * stack passed in $tokens.
93
+ *
94
+ * @return void
95
+ */
96
+ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
97
+ {
98
+ $algo = $this->getHashAlgorithmParameter($phpcsFile, $stackPtr);
99
+ if (empty($algo) || is_string($algo) === false) {
100
+ return;
101
+ }
102
+
103
+ // Bow out if not one of the algorithms we're targetting.
104
+ if (isset($this->newAlgorithms[$algo]) === false) {
105
+ return;
106
+ }
107
+
108
+ // Check if the algorithm used is new.
109
+ $errorInfo = $this->getErrorInfo($algo);
110
+
111
+ if ($errorInfo['not_in_version'] !== '') {
112
+ $this->addError($phpcsFile, $stackPtr, $algo, $errorInfo);
113
+ }
114
+
115
+ }//end process()
116
+
117
+
118
+ /**
119
+ * Retrieve the relevant (version) information for the error message.
120
+ *
121
+ * @param string $algorithm The name of the algorithm.
122
+ *
123
+ * @return array
124
+ */
125
+ protected function getErrorInfo($algorithm)
126
+ {
127
+ $errorInfo = array(
128
+ 'not_in_version' => '',
129
+ );
130
+
131
+ foreach ($this->newAlgorithms[$algorithm] as $version => $present) {
132
+ if ($present === false && $this->supportsBelow($version)) {
133
+ $errorInfo['not_in_version'] = $version;
134
+ }
135
+ }
136
+
137
+ return $errorInfo;
138
+
139
+ }//end getErrorInfo()
140
+
141
+
142
+ /**
143
+ * Generates the error or warning for this sniff.
144
+ *
145
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
146
+ * @param int $stackPtr The position of the function
147
+ * in the token array.
148
+ * @param string $algorithm The name of the algorithm.
149
+ * @param array $errorInfo Array with details about the versions
150
+ * in which the algorithm was deprecated
151
+ * and/or removed.
152
+ *
153
+ * @return void
154
+ */
155
+ protected function addError($phpcsFile, $stackPtr, $algorithm, $errorInfo)
156
+ {
157
+ $error = 'The %s hash algorithm is not present in PHP version %s or earlier ';
158
+ $errorCode = $algorithm . 'Found';
159
+ $data = array(
160
+ $algorithm,
161
+ $errorInfo['not_in_version'],
162
+ );
163
+
164
+ $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
165
+
166
+ }//end addError()
167
+
168
+ }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/NewIniDirectivesSniff.php CHANGED
@@ -156,35 +156,29 @@ class PHPCompatibility_Sniffs_PHP_NewIniDirectivesSniff extends PHPCompatibility
156
  ),
157
 
158
  'mbstring.strict_detection' => array(
159
- '5.0' => false,
160
- '5.1' => false,
161
  '5.1.2' => true,
162
  ),
163
  'mssql.charset' => array(
164
- '5.0' => false,
165
- '5.1' => false,
166
  '5.1.2' => true,
167
  ),
168
 
169
  'gd.jpeg_ignore_warning' => array(
170
- '5.0' => false,
171
- '5.1' => false,
172
  '5.1.3' => true,
173
  ),
174
 
175
  'fbsql.show_timestamp_decimals' => array(
176
- '5.0' => false,
177
- '5.1' => false,
178
  '5.1.5' => true,
179
  ),
180
  'soap.wsdl_cache' => array(
181
- '5.0' => false,
182
- '5.1' => false,
183
  '5.1.5' => true,
184
  ),
185
  'soap.wsdl_cache_limit' => array(
186
- '5.0' => false,
187
- '5.1' => false,
188
  '5.1.5' => true,
189
  ),
190
 
@@ -214,26 +208,22 @@ class PHPCompatibility_Sniffs_PHP_NewIniDirectivesSniff extends PHPCompatibility
214
  ),
215
 
216
  'cgi.check_shebang_line' => array(
217
- '5.1' => false,
218
- '5.2' => false,
219
  '5.2.1' => true
220
  ),
221
 
222
  'max_input_nesting_level' => array(
223
- '5.1' => false,
224
- '5.2' => false,
225
  '5.2.3' => true
226
  ),
227
 
228
  'mysqli.allow_local_infile' => array(
229
- '5.1' => false,
230
- '5.2' => false,
231
  '5.2.4' => true,
232
  ),
233
 
234
  'max_file_uploads' => array(
235
- '5.1' => false,
236
- '5.2' => false,
237
  '5.2.12' => true,
238
  ),
239
 
@@ -315,20 +305,17 @@ class PHPCompatibility_Sniffs_PHP_NewIniDirectivesSniff extends PHPCompatibility
315
  ),
316
 
317
  'curl.cainfo' => array(
318
- '5.2' => false,
319
- '5.3' => false,
320
  '5.3.7' => true,
321
  ),
322
 
323
  'max_input_vars' => array(
324
- '5.2' => false,
325
- '5.3' => false,
326
  '5.3.9' => true,
327
  ),
328
 
329
  'sqlite3.extension_dir' => array(
330
- '5.2' => false,
331
- '5.3' => false,
332
  '5.3.11' => true,
333
  ),
334
 
@@ -436,8 +423,7 @@ class PHPCompatibility_Sniffs_PHP_NewIniDirectivesSniff extends PHPCompatibility
436
  ),
437
 
438
  'session.use_strict_mode' => array(
439
- '5.4' => false,
440
- '5.5' => false,
441
  '5.5.2' => true,
442
  ),
443
 
@@ -506,31 +492,40 @@ class PHPCompatibility_Sniffs_PHP_NewIniDirectivesSniff extends PHPCompatibility
506
  return;
507
  }
508
 
509
- $iniToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr, null);
510
- $filteredToken = trim($tokens[$iniToken]['content'], '\'"');
511
- if (isset($this->newIniDirectives[$filteredToken]) === false) {
512
  return;
513
  }
514
 
515
- $error = '';
 
 
 
516
 
 
517
  foreach ($this->newIniDirectives[$filteredToken] as $version => $present) {
518
- if ($version !== 'alternative') {
519
- if ($this->supportsBelow($version)) {
520
- if ($present === true) {
521
- $error .= " not available before version " . $version;
522
- }
523
- }
524
  }
525
  }
526
 
527
- if (strlen($error) > 0) {
528
- $error = "INI directive '" . $filteredToken . "' is" . $error;
 
 
 
 
 
529
  if (isset($this->newIniDirectives[$filteredToken]['alternative'])) {
530
- $error .= ". This directive was previously called '" . $this->newIniDirectives[$filteredToken]['alternative'] . "'.";
 
531
  }
532
 
533
- $phpcsFile->addWarning($error, $stackPtr);
 
 
 
 
534
  }
535
 
536
  }//end process()
156
  ),
157
 
158
  'mbstring.strict_detection' => array(
159
+ '5.1.1' => false,
 
160
  '5.1.2' => true,
161
  ),
162
  'mssql.charset' => array(
163
+ '5.1.1' => false,
 
164
  '5.1.2' => true,
165
  ),
166
 
167
  'gd.jpeg_ignore_warning' => array(
168
+ '5.1.2' => false,
 
169
  '5.1.3' => true,
170
  ),
171
 
172
  'fbsql.show_timestamp_decimals' => array(
173
+ '5.1.4' => false,
 
174
  '5.1.5' => true,
175
  ),
176
  'soap.wsdl_cache' => array(
177
+ '5.1.4' => false,
 
178
  '5.1.5' => true,
179
  ),
180
  'soap.wsdl_cache_limit' => array(
181
+ '5.1.4' => false,
 
182
  '5.1.5' => true,
183
  ),
184
 
208
  ),
209
 
210
  'cgi.check_shebang_line' => array(
211
+ '5.2.0' => false,
 
212
  '5.2.1' => true
213
  ),
214
 
215
  'max_input_nesting_level' => array(
216
+ '5.2.2' => false,
 
217
  '5.2.3' => true
218
  ),
219
 
220
  'mysqli.allow_local_infile' => array(
221
+ '5.2.3' => false,
 
222
  '5.2.4' => true,
223
  ),
224
 
225
  'max_file_uploads' => array(
226
+ '5.2.11' => false,
 
227
  '5.2.12' => true,
228
  ),
229
 
305
  ),
306
 
307
  'curl.cainfo' => array(
308
+ '5.3.6' => false,
 
309
  '5.3.7' => true,
310
  ),
311
 
312
  'max_input_vars' => array(
313
+ '5.3.8' => false,
 
314
  '5.3.9' => true,
315
  ),
316
 
317
  'sqlite3.extension_dir' => array(
318
+ '5.3.10' => false,
 
319
  '5.3.11' => true,
320
  ),
321
 
423
  ),
424
 
425
  'session.use_strict_mode' => array(
426
+ '5.5.1' => false,
 
427
  '5.5.2' => true,
428
  ),
429
 
492
  return;
493
  }
494
 
495
+ $iniToken = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 1);
496
+ if ($iniToken === false) {
 
497
  return;
498
  }
499
 
500
+ $filteredToken = $this->stripQuotes($iniToken['raw']);
501
+ if (isset($this->newIniDirectives[$filteredToken]) === false) {
502
+ return;
503
+ }
504
 
505
+ $notInVersion = '';
506
  foreach ($this->newIniDirectives[$filteredToken] as $version => $present) {
507
+ if ($version !== 'alternative' && $present === false && $this->supportsBelow($version)) {
508
+ $notInVersion = $version;
 
 
 
 
509
  }
510
  }
511
 
512
+ if ($notInVersion !== '') {
513
+ $error = "INI directive '%s' is not present in PHP version %s or earlier";
514
+ $isError = ($function !== 'ini_get') ? true : false;
515
+ $data = array(
516
+ $filteredToken,
517
+ $notInVersion
518
+ );
519
  if (isset($this->newIniDirectives[$filteredToken]['alternative'])) {
520
+ $error .= ". This directive was previously called '%s'.";
521
+ $data[] = $this->newIniDirectives[$filteredToken]['alternative'];
522
  }
523
 
524
+ if ($isError === true) {
525
+ $phpcsFile->addError($error, $iniToken['end'], 'Found', $data);
526
+ } else {
527
+ $phpcsFile->addWarning($error, $iniToken['end'], 'Found', $data);
528
+ }
529
  }
530
 
531
  }//end process()
vendor/wimg/php-compatibility/Sniffs/PHP/NewInterfacesSniff.php CHANGED
@@ -135,17 +135,19 @@ class PHPCompatibility_Sniffs_PHP_NewInterfacesSniff extends PHPCompatibility_Sn
135
  if ($checkMethods === true && isset($this->unsupportedMethods[$lcInterface]) === true) {
136
  $nextFunc = $stackPtr;
137
  while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) {
138
- $funcNamePos = $phpcsFile->findNext(T_STRING, $nextFunc);
139
- $funcName = strtolower($tokens[$funcNamePos]['content']);
 
 
140
 
141
  if (isset($this->unsupportedMethods[$lcInterface][$funcName]) === true) {
142
  $error = 'Classes that implement interface %s do not support the method %s(). See %s';
143
  $data = array(
144
  $interface,
145
- $tokens[$funcNamePos]['content'],
146
  $this->unsupportedMethods[$lcInterface][$funcName],
147
  );
148
- $phpcsFile->addError($error, $funcNamePos, 'UnsupportedMethod', $data);
149
  }
150
  }
151
  }
@@ -161,20 +163,16 @@ class PHPCompatibility_Sniffs_PHP_NewInterfacesSniff extends PHPCompatibility_Sn
161
  * @param int $stackPtr The position of the function
162
  * in the token array.
163
  * @param string $interface The name of the interface.
164
- * @param string $pattern The pattern used for the match.
165
  *
166
  * @return void
167
  */
168
- protected function addError($phpcsFile, $stackPtr, $interface, $pattern=null)
169
  {
170
- if ($pattern === null) {
171
- $pattern = strtolower($interface);
172
- }
173
-
174
- $error = '';
175
 
176
  $isError = false;
177
- foreach ($this->newInterfaces[$pattern] as $version => $present) {
178
  if ($this->supportsBelow($version)) {
179
  if ($present === false) {
180
  $isError = true;
135
  if ($checkMethods === true && isset($this->unsupportedMethods[$lcInterface]) === true) {
136
  $nextFunc = $stackPtr;
137
  while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) {
138
+ $funcName = strtolower($phpcsFile->getDeclarationName($nextFunc));
139
+ if ($funcName === '') {
140
+ continue;
141
+ }
142
 
143
  if (isset($this->unsupportedMethods[$lcInterface][$funcName]) === true) {
144
  $error = 'Classes that implement interface %s do not support the method %s(). See %s';
145
  $data = array(
146
  $interface,
147
+ $funcName,
148
  $this->unsupportedMethods[$lcInterface][$funcName],
149
  );
150
+ $phpcsFile->addError($error, $nextFunc, 'UnsupportedMethod', $data);
151
  }
152
  }
153
  }
163
  * @param int $stackPtr The position of the function
164
  * in the token array.
165
  * @param string $interface The name of the interface.
 
166
  *
167
  * @return void
168
  */
169
+ protected function addError($phpcsFile, $stackPtr, $interface)
170
  {
171
+ $interfaceLc = strtolower($interface);
172
+ $error = '';
 
 
 
173
 
174
  $isError = false;
175
+ foreach ($this->newInterfaces[$interfaceLc] as $version => $present) {
176
  if ($this->supportsBelow($version)) {
177
  if ($present === false) {
178
  $isError = true;
vendor/wimg/php-compatibility/Sniffs/PHP/NewKeywordsSniff.php CHANGED
@@ -26,10 +26,12 @@ class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Snif
26
  * A list of new keywords, not present in older versions.
27
  *
28
  * The array lists : version number with false (not present) or true (present).
29
- * If's sufficient to list the first version where the keyword appears.
30
  *
31
- * If you add a condition, make sure to add the appropriate logic for it as well as
32
- * this will not resolve itself automatically.
 
 
33
  *
34
  * @var array(string => array(string => int|string|null))
35
  */
@@ -43,37 +45,43 @@ class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Snif
43
  '5.2' => false,
44
  '5.3' => true,
45
  'description' => '"const" keyword',
46
- 'condition' => 'T_CLASS', // Keyword is only new when not in class context.
47
  ),
48
  'T_CALLABLE' => array(
49
  '5.3' => false,
50
  '5.4' => true,
51
- 'description' => '"callable" keyword'
 
52
  ),
53
  'T_DIR' => array(
54
  '5.2' => false,
55
  '5.3' => true,
56
- 'description' => '__DIR__ magic constant'
 
57
  ),
58
  'T_GOTO' => array(
59
  '5.2' => false,
60
  '5.3' => true,
61
- 'description' => '"goto" keyword'
 
62
  ),
63
  'T_INSTEADOF' => array(
64
  '5.3' => false,
65
  '5.4' => true,
66
- 'description' => '"insteadof" keyword (for traits)'
 
67
  ),
68
  'T_NAMESPACE' => array(
69
  '5.2' => false,
70
  '5.3' => true,
71
- 'description' => '"namespace" keyword'
 
72
  ),
73
  'T_NS_C' => array(
74
  '5.2' => false,
75
  '5.3' => true,
76
- 'description' => '__NAMESPACE__ magic constant'
 
77
  ),
78
  'T_USE' => array(
79
  '5.2' => false,
@@ -83,35 +91,48 @@ class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Snif
83
  'T_TRAIT' => array(
84
  '5.3' => false,
85
  '5.4' => true,
86
- 'description' => '"trait" keyword'
 
87
  ),
88
  'T_TRAIT_C' => array(
89
  '5.3' => false,
90
  '5.4' => true,
91
- 'description' => '__TRAIT__ magic constant'
 
92
  ),
93
  'T_YIELD' => array(
94
  '5.4' => false,
95
  '5.5' => true,
96
- 'description' => '"yield" keyword (for generators)'
 
97
  ),
98
  'T_FINALLY' => array(
99
  '5.4' => false,
100
  '5.5' => true,
101
- 'description' => '"finally" keyword (in exception handling)'
 
102
  ),
103
  'T_START_NOWDOC' => array(
104
  '5.2' => false,
105
  '5.3' => true,
106
- 'description' => 'nowdoc functionality'
107
  ),
108
  'T_END_NOWDOC' => array(
109
  '5.2' => false,
110
  '5.3' => true,
111
- 'description' => 'nowdoc functionality'
112
  ),
113
  );
114
 
 
 
 
 
 
 
 
 
 
115
 
116
  /**
117
  * Returns an array of tokens this test wants to listen for.
@@ -120,12 +141,26 @@ class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Snif
120
  */
121
  public function register()
122
  {
123
- $tokens = array();
 
124
  foreach ($this->newKeywords as $token => $versions) {
125
  if (defined($token)) {
126
  $tokens[] = constant($token);
127
  }
 
 
 
 
 
 
 
 
 
 
 
 
128
  }
 
129
  return $tokens;
130
 
131
  }//end register()
@@ -142,38 +177,44 @@ class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Snif
142
  */
143
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
144
  {
145
- $tokens = $phpcsFile->getTokens();
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
  $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
148
  $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
149
 
 
150
  // Skip attempts to use keywords as functions or class names - the former
151
- // will be reported by FrobiddenNamesAsInvokedFunctionsSniff, whilst the
152
- // latter doesn't yet have an appropriate sniff.
153
  // Either type will result in false-positives when targetting lower versions
154
  // of PHP where the name was not reserved, unless we explicitly check for
155
  // them.
156
  if (
157
- $tokens[$nextToken]['type'] != 'T_OPEN_PARENTHESIS'
158
  &&
159
- $tokens[$prevToken]['type'] != 'T_CLASS'
160
  ) {
161
- // Skip based on special conditions.
162
- if (
163
- isset($this->newKeywords[$tokens[$stackPtr]['type']]['condition'])
164
- &&
165
- (empty($tokens[$stackPtr]['conditions']) === false
166
- &&
167
- is_array($tokens[$stackPtr]['conditions']))
168
- ) {
169
- foreach ($tokens[$stackPtr]['conditions'] as $condPtr => $condType) {
170
- if ($condType === constant($this->newKeywords[$tokens[$stackPtr]['type']]['condition'])) {
171
- return;
172
- }
173
  }
174
  }
175
 
176
- $this->addError($phpcsFile, $stackPtr, $tokens[$stackPtr]['type']);
177
  }
178
  }//end process()
179
 
@@ -185,40 +226,31 @@ class PHPCompatibility_Sniffs_PHP_NewKeywordsSniff extends PHPCompatibility_Snif
185
  * @param int $stackPtr The position of the function
186
  * in the token array.
187
  * @param string $keywordName The name of the keyword.
188
- * @param string $pattern The pattern used for the match.
189
  *
190
  * @return void
191
  */
192
- protected function addError($phpcsFile, $stackPtr, $keywordName, $pattern=null)
193
  {
194
- if ($pattern === null) {
195
- $pattern = $keywordName;
196
- }
197
-
198
- $error = '';
199
-
200
- $isError = false;
201
- foreach ($this->newKeywords[$pattern] as $version => $present) {
202
- if (in_array($version, array('condition', 'description'), true)) {
203
  continue;
204
  }
205
 
206
- if ($this->supportsBelow($version)) {
207
- if ($present === false) {
208
- $isError = true;
209
- $error .= 'not present in PHP version ' . $version . ' or earlier';
210
- }
211
  }
212
  }
213
- if (strlen($error) > 0) {
214
- $error = $this->newKeywords[$keywordName]['description'] . ' is ' . $error;
215
 
216
- if ($isError === true) {
217
- $phpcsFile->addError($error, $stackPtr);
218
- } else {
219
- $phpcsFile->addWarning($error, $stackPtr);
220
- }
 
 
221
  }
 
222
  }//end addError()
223
 
224
  }//end class
26
  * A list of new keywords, not present in older versions.
27
  *
28
  * The array lists : version number with false (not present) or true (present).
29
+ * If's sufficient to list the last version which did not contain the keyword.
30
  *
31
+ * Description will be used as part of the error message.
32
+ * Condition is an array of valid scope conditions to check for.
33
+ * If you need a condition of a different type, make sure to add the appropriate
34
+ * logic for it as well as this will not resolve itself automatically.
35
  *
36
  * @var array(string => array(string => int|string|null))
37
  */
45
  '5.2' => false,
46
  '5.3' => true,
47
  'description' => '"const" keyword',
48
+ 'condition' => array(T_CLASS), // Keyword is only new when not in class context.
49
  ),
50
  'T_CALLABLE' => array(
51
  '5.3' => false,
52
  '5.4' => true,
53
+ 'description' => '"callable" keyword',
54
+ 'content' => 'callable',
55
  ),
56
  'T_DIR' => array(
57
  '5.2' => false,
58
  '5.3' => true,
59
+ 'description' => '__DIR__ magic constant',
60
+ 'content' => '__DIR__',
61
  ),
62
  'T_GOTO' => array(
63
  '5.2' => false,
64
  '5.3' => true,
65
+ 'description' => '"goto" keyword',
66
+ 'content' => 'goto',
67
  ),
68
  'T_INSTEADOF' => array(
69
  '5.3' => false,
70
  '5.4' => true,
71
+ 'description' => '"insteadof" keyword (for traits)',
72
+ 'content' => 'insteadof',
73
  ),
74
  'T_NAMESPACE' => array(
75
  '5.2' => false,
76
  '5.3' => true,
77
+ 'description' => '"namespace" keyword',
78
+ 'content' => 'namespace',
79
  ),
80
  'T_NS_C' => array(
81
  '5.2' => false,
82
  '5.3' => true,
83
+ 'description' => '__NAMESPACE__ magic constant',
84
+ 'content' => '__NAMESPACE__',
85
  ),
86
  'T_USE' => array(
87
  '5.2' => false,
91
  'T_TRAIT' => array(
92
  '5.3' => false,
93
  '5.4' => true,
94
+ 'description' => '"trait" keyword',
95
+ 'content' => 'trait',
96
  ),
97
  'T_TRAIT_C' => array(
98
  '5.3' => false,
99
  '5.4' => true,
100
+ 'description' => '__TRAIT__ magic constant',
101
+ 'content' => '__TRAIT__',
102
  ),
103
  'T_YIELD' => array(
104
  '5.4' => false,
105
  '5.5' => true,
106
+ 'description' => '"yield" keyword (for generators)',
107
+ 'content' => 'yield',
108
  ),
109
  'T_FINALLY' => array(
110
  '5.4' => false,
111
  '5.5' => true,
112
+ 'description' => '"finally" keyword (in exception handling)',
113
+ 'content' => 'finally',
114
  ),
115
  'T_START_NOWDOC' => array(
116
  '5.2' => false,
117
  '5.3' => true,
118
+ 'description' => 'nowdoc functionality',
119
  ),
120
  'T_END_NOWDOC' => array(
121
  '5.2' => false,
122
  '5.3' => true,
123
+ 'description' => 'nowdoc functionality',
124
  ),
125
  );
126
 
127
+ /**
128
+ * Translation table for T_STRING tokens.
129
+ *
130
+ * Will be set up from the register() method.
131
+ *
132
+ * @var array(string => string)
133
+ */
134
+ protected $translateContentToToken = array();
135
+
136
 
137
  /**
138
  * Returns an array of tokens this test wants to listen for.
141
  */
142
  public function register()
143
  {
144
+ $tokens = array();
145
+ $translate = array();
146
  foreach ($this->newKeywords as $token => $versions) {
147
  if (defined($token)) {
148
  $tokens[] = constant($token);
149
  }
150
+ if (isset($versions['content'])) {
151
+ $translate[$versions['content']] = $token;
152
+ }
153
+ }
154
+
155
+ /*
156
+ * Deal with tokens not recognized by the PHP version the sniffer is run
157
+ * under and (not correctly) compensated for by PHPCS.
158
+ */
159
+ if (empty($translate) === false) {
160
+ $this->translateContentToToken = $translate;
161
+ $tokens[] = T_STRING;
162
  }
163
+
164
  return $tokens;
165
 
166
  }//end register()
177
  */
178
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
179
  {
180
+ $tokens = $phpcsFile->getTokens();
181
+ $tokenType = $tokens[$stackPtr]['type'];
182
+
183
+ // Translate T_STRING token if necessary.
184
+ if ($tokens[$stackPtr]['type'] === 'T_STRING') {
185
+ $content = $tokens[$stackPtr]['content'];
186
+ if (isset($this->translateContentToToken[$content]) === false) {
187
+ // Not one of the tokens we're looking for.
188
+ return;
189
+ }
190
+
191
+ $tokenType = $this->translateContentToToken[$content];
192
+ }
193
 
194
  $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
195
  $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
196
 
197
+
198
  // Skip attempts to use keywords as functions or class names - the former
199
+ // will be reported by ForbiddenNamesAsInvokedFunctionsSniff, whilst the
200
+ // latter will be (partially) reported by the ForbiddenNames sniff.
201
  // Either type will result in false-positives when targetting lower versions
202
  // of PHP where the name was not reserved, unless we explicitly check for
203
  // them.
204
  if (
205
+ ($nextToken === false || $tokens[$nextToken]['type'] !== 'T_OPEN_PARENTHESIS')
206
  &&
207
+ ($prevToken === false || $tokens[$prevToken]['type'] !== 'T_CLASS' || $tokens[$prevToken]['type'] !== 'T_INTERFACE')
208
  ) {
209
+ // Skip based on token scope condition.
210
+ if (isset($this->newKeywords[$tokenType]['condition'])) {
211
+ $condition = $this->newKeywords[$tokenType]['condition'];
212
+ if ($this->tokenHasScope($phpcsFile, $stackPtr, $condition) === true) {
213
+ return;
 
 
 
 
 
 
 
214
  }
215
  }
216
 
217
+ $this->addError($phpcsFile, $stackPtr, $tokenType);
218
  }
219
  }//end process()
220
 
226
  * @param int $stackPtr The position of the function
227
  * in the token array.
228
  * @param string $keywordName The name of the keyword.
 
229
  *
230
  * @return void
231
  */
232
+ protected function addError($phpcsFile, $stackPtr, $keywordName)
233
  {
234
+ $notInVersion = '';
235
+ foreach ($this->newKeywords[$keywordName] as $version => $present) {
236
+ if (in_array($version, array('condition', 'description', 'content'), true)) {
 
 
 
 
 
 
237
  continue;
238
  }
239
 
240
+ if ($present === false && $this->supportsBelow($version)) {
241
+ $notInVersion = $version;
 
 
 
242
  }
243
  }
 
 
244
 
245
+ if ($notInVersion !== '') {
246
+ $error = '%s is not present in PHP version %s or earlier';
247
+ $data = array(
248
+ $this->newKeywords[$keywordName]['description'],
249
+ $notInVersion,
250
+ );
251
+ $phpcsFile->addError($error, $stackPtr, 'Found', $data);
252
  }
253
+
254
  }//end addError()
255
 
256
  }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/NewScalarReturnTypeDeclarationsSniff.php CHANGED
@@ -89,20 +89,15 @@ class PHPCompatibility_Sniffs_PHP_NewScalarReturnTypeDeclarationsSniff extends P
89
  * @param int $stackPtr The position of the function
90
  * in the token array.
91
  * @param string $typeName The type.
92
- * @param string $pattern The pattern used for the match.
93
  *
94
  * @return void
95
  */
96
- protected function addError($phpcsFile, $stackPtr, $typeName, $pattern=null)
97
  {
98
- if ($pattern === null) {
99
- $pattern = $typeName;
100
- }
101
-
102
  $error = '';
103
 
104
  $isError = false;
105
- foreach ($this->newTypes[$pattern] as $version => $present) {
106
  if ($this->supportsBelow($version)) {
107
  if ($present === false) {
108
  $isError = true;
89
  * @param int $stackPtr The position of the function
90
  * in the token array.
91
  * @param string $typeName The type.
 
92
  *
93
  * @return void
94
  */
95
+ protected function addError($phpcsFile, $stackPtr, $typeName)
96
  {
 
 
 
 
97
  $error = '';
98
 
99
  $isError = false;
100
+ foreach ($this->newTypes[$typeName] as $version => $present) {
101
  if ($this->supportsBelow($version)) {
102
  if ($present === false) {
103
  $isError = true;
vendor/wimg/php-compatibility/Sniffs/PHP/NewScalarTypeDeclarationsSniff.php CHANGED
@@ -92,6 +92,10 @@ class PHPCompatibility_Sniffs_PHP_NewScalarTypeDeclarationsSniff extends PHPComp
92
  {
93
  // Get all parameters from method signature.
94
  $paramNames = $this->getMethodParameters($phpcsFile, $stackPtr);
 
 
 
 
95
  $supportsPHP4 = $this->supportsBelow('4.4');
96
 
97
  foreach ($paramNames as $param) {
@@ -131,20 +135,15 @@ class PHPCompatibility_Sniffs_PHP_NewScalarTypeDeclarationsSniff extends PHPComp
131
  * @param int $stackPtr The position of the function
132
  * in the token array.
133
  * @param string $typeName The type.
134
- * @param string $pattern The pattern used for the match.
135
  *
136
  * @return void
137
  */
138
- protected function addError($phpcsFile, $stackPtr, $typeName, $pattern=null)
139
  {
140
- if ($pattern === null) {
141
- $pattern = $typeName;
142
- }
143
-
144
  $error = '';
145
 
146
  $isError = false;
147
- foreach ($this->newTypes[$pattern] as $version => $present) {
148
  if ($this->supportsBelow($version)) {
149
  if ($present === false) {
150
  $isError = true;
92
  {
93
  // Get all parameters from method signature.
94
  $paramNames = $this->getMethodParameters($phpcsFile, $stackPtr);
95
+ if (empty($paramNames)) {
96
+ return;
97
+ }
98
+
99
  $supportsPHP4 = $this->supportsBelow('4.4');
100
 
101
  foreach ($paramNames as $param) {
135
  * @param int $stackPtr The position of the function
136
  * in the token array.
137
  * @param string $typeName The type.
 
138
  *
139
  * @return void
140
  */
141
+ protected function addError($phpcsFile, $stackPtr, $typeName)
142
  {
 
 
 
 
143
  $error = '';
144
 
145
  $isError = false;
146
+ foreach ($this->newTypes[$typeName] as $version => $present) {
147
  if ($this->supportsBelow($version)) {
148
  if ($present === false) {
149
  $isError = true;
vendor/wimg/php-compatibility/Sniffs/PHP/ParameterShadowSuperGlobalsSniff.php CHANGED
@@ -36,9 +36,6 @@ class PHPCompatibility_Sniffs_PHP_ParameterShadowSuperGlobalsSniff extends PHPCo
36
  * @return array
37
  */
38
  public function register() {
39
- // Prepare for case-insensitive compare.
40
- $this->superglobals = array_map('strtolower', $this->superglobals);
41
-
42
  return array(T_FUNCTION);
43
  }
44
 
@@ -62,9 +59,7 @@ class PHPCompatibility_Sniffs_PHP_ParameterShadowSuperGlobalsSniff extends PHPCo
62
  }
63
 
64
  foreach ($parameters as $param) {
65
- $paramNameLc = strtolower($param['name']);
66
-
67
- if (in_array($paramNameLc, $this->superglobals, true)) {
68
  $error = 'Parameter shadowing super global (%s) causes fatal error since PHP 5.4';
69
  $data = array($param['name']);
70
  $phpcsFile->addError($error, $stackPtr, 'Found', $data);
36
  * @return array
37
  */
38
  public function register() {
 
 
 
39
  return array(T_FUNCTION);
40
  }
41
 
59
  }
60
 
61
  foreach ($parameters as $param) {
62
+ if (in_array($param['name'], $this->superglobals, true)) {
 
 
63
  $error = 'Parameter shadowing super global (%s) causes fatal error since PHP 5.4';
64
  $data = array($param['name']);
65
  $phpcsFile->addError($error, $stackPtr, 'Found', $data);
vendor/wimg/php-compatibility/Sniffs/PHP/PregReplaceEModifierSniff.php CHANGED
@@ -32,6 +32,18 @@ class PHPCompatibility_Sniffs_PHP_PregReplaceEModifierSniff extends PHPCompatibi
32
  'preg_filter' => true,
33
  );
34
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  /**
36
  * Returns an array of tokens this test wants to listen for.
37
  *
@@ -53,69 +65,61 @@ class PHPCompatibility_Sniffs_PHP_PregReplaceEModifierSniff extends PHPCompatibi
53
  */
54
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
55
  {
56
- if ($this->supportsAbove('5.5')) {
57
- $tokens = $phpcsFile->getTokens();
58
-
59
- if ( isset($this->functions[$tokens[$stackPtr]['content']]) === false ) {
60
- return;
61
- } else {
62
-
63
- $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
64
-
65
- if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
66
- return;
67
- }
68
-
69
- $firstParam = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true);
70
 
71
- /**
72
- * If argument is not a string, then skip test (e.g. if variable passed in).
73
- */
74
- if ($tokens[$firstParam]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
75
- return;
76
- }
77
 
78
- /**
79
- * Regex is a T_CONSTANT_ENCAPSED_STRING, so we need to remove the quotes
80
- */
81
- $regex = "";
82
- while (isset($tokens[$firstParam]) && $tokens[$firstParam]['code'] != T_COMMA) {
83
- if ($tokens[$firstParam]['code'] == T_CONSTANT_ENCAPSED_STRING) {
84
- $regex .= $tokens[$firstParam]['content'];
85
- }
86
- $firstParam++;
87
- }
88
 
89
- $doublesSeparators = array(
90
- '{' => '}',
91
- '[' => ']',
92
- '(' => ')',
93
- '<' => '>',
94
- );
95
 
96
- $regex = substr($regex, 1, -1);
 
 
 
 
97
 
98
- $regexFirstChar = substr($regex, 0, 1);
99
- $regexEndPos = (array_key_exists($regexFirstChar, $doublesSeparators)) ?
100
- strrpos($regex, $doublesSeparators[$regexFirstChar])
101
- : strrpos($regex, $regexFirstChar);
 
 
 
 
 
 
 
 
 
 
 
102
 
103
- if($regexEndPos) {
104
- $modifiers = substr($regex, $regexEndPos + 1);
105
 
106
- if (strpos($modifiers, "e") !== false) {
107
- if ($this->supportsAbove('7.0')) {
108
- $error = 'preg_replace() - /e modifier is forbidden in PHP 7.0';
109
- } else {
110
- $error = 'preg_replace() - /e modifier is deprecated in PHP 5.5';
111
- }
112
- $phpcsFile->addError($error, $stackPtr);
113
- }
114
  }
 
 
115
  }
116
  }
117
 
118
-
119
  }//end process()
120
 
121
  }//end class
32
  'preg_filter' => true,
33
  );
34
 
35
+ /**
36
+ * Regex bracket delimiters.
37
+ *
38
+ * @var array
39
+ */
40
+ protected $doublesSeparators = array(
41
+ '{' => '}',
42
+ '[' => ']',
43
+ '(' => ')',
44
+ '<' => '>',
45
+ );
46
+
47
  /**
48
  * Returns an array of tokens this test wants to listen for.
49
  *
65
  */
66
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
67
  {
68
+ if ($this->supportsAbove('5.5') === false) {
69
+ return;
70
+ }
 
 
 
 
 
 
 
 
 
 
 
71
 
72
+ $tokens = $phpcsFile->getTokens();
73
+ $functionName = $tokens[$stackPtr]['content'];
74
+ $functionNameLc = strtolower($functionName);
 
 
 
75
 
76
+ // Bow out if not one of the functions we're targetting.
77
+ if ( isset($this->functions[$functionNameLc]) === false ) {
78
+ return;
79
+ }
 
 
 
 
 
 
80
 
81
+ // Get the first parameter in the function call as that should contain the regex.
82
+ $firstParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 1);
83
+ if ($firstParam === false) {
84
+ return;
85
+ }
 
86
 
87
+ $stringToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $firstParam['start'], $firstParam['end'] + 1);
88
+ if ($stringToken === false) {
89
+ // No string token found in the first parameter, so skip it (e.g. if variable passed in).
90
+ return;
91
+ }
92
 
93
+ /*
94
+ * The first parameter might be build up of a combination of strings,
95
+ * variables and function calls, but in that case, generally the start
96
+ * and end will still be strings. And as that's all we're concerned with,
97
+ * just use the raw content of the first parameter for further processing.
98
+ */
99
+ $regex = $this->stripQuotes($firstParam['raw']);
100
+
101
+ $regexFirstChar = substr($regex, 0, 1);
102
+ if (isset($this->doublesSeparators[$regexFirstChar])) {
103
+ $regexEndPos = strrpos($regex, $this->doublesSeparators[$regexFirstChar]);
104
+ }
105
+ else {
106
+ $regexEndPos = strrpos($regex, $regexFirstChar);
107
+ }
108
 
109
+ if($regexEndPos) {
110
+ $modifiers = substr($regex, $regexEndPos + 1);
111
 
112
+ if (strpos($modifiers, 'e') !== false) {
113
+ if ($this->supportsAbove('7.0')) {
114
+ $error = '%s() - /e modifier is forbidden since PHP 7.0';
115
+ } else {
116
+ $error = '%s() - /e modifier is deprecated since PHP 5.5';
 
 
 
117
  }
118
+ $data = array($functionName);
119
+ $phpcsFile->addError($error, $stackPtr, 'Found', $data);
120
  }
121
  }
122
 
 
123
  }//end process()
124
 
125
  }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/RemovedAlternativePHPTagsSniff.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * PHPCompatibility_Sniffs_PHP_RemovedAlternativePHPTags.
4
+ *
5
+ * @category PHP
6
+ * @package PHPCompatibility
7
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
8
+ */
9
+
10
+ /**
11
+ * PHPCompatibility_Sniffs_PHP_RemovedAlternativePHPTags.
12
+ *
13
+ * Check for usage of alternative PHP tags - removed in PHP 7.0.
14
+ *
15
+ * @category PHP
16
+ * @package PHPCompatibility
17
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
18
+ *
19
+ * Based on `Generic_Sniffs_PHP_DisallowAlternativePHPTags` by Juliette Reinders Folmer
20
+ * which was merged into PHPCS 2.7.0.
21
+ */
22
+ class PHPCompatibility_Sniffs_PHP_RemovedAlternativePHPTagsSniff extends PHPCompatibility_Sniff
23
+ {
24
+
25
+ /**
26
+ * Whether ASP tags are enabled or not.
27
+ *
28
+ * @var bool
29
+ */
30
+ private $_aspTags = false;
31
+
32
+ /**
33
+ * Returns an array of tokens this test wants to listen for.
34
+ *
35
+ * @return array
36
+ */
37
+ public function register()
38
+ {
39
+ if (version_compare(phpversion(), '7.0', '<') === true) {
40
+ $this->_aspTags = (boolean) ini_get('asp_tags');
41
+ }
42
+
43
+ return array(
44
+ T_OPEN_TAG,
45
+ T_OPEN_TAG_WITH_ECHO,
46
+ T_INLINE_HTML,
47
+ );
48
+
49
+ }//end register()
50
+
51
+
52
+ /**
53
+ * Processes this test, when one of its tokens is encountered.
54
+ *
55
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
56
+ * @param int $stackPtr The position of the current token
57
+ * in the stack passed in $tokens.
58
+ *
59
+ * @return void
60
+ */
61
+ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
62
+ {
63
+ if ($this->supportsAbove('7.0') === false) {
64
+ return;
65
+ }
66
+
67
+ $tokens = $phpcsFile->getTokens();
68
+ $openTag = $tokens[$stackPtr];
69
+ $content = trim($openTag['content']);
70
+
71
+ if ($content === '' || $content === '<?php') {
72
+ return;
73
+ }
74
+
75
+ if ($openTag['code'] === T_OPEN_TAG || $openTag['code'] === T_OPEN_TAG_WITH_ECHO) {
76
+
77
+ if ($content === '<%' || $content === '<%=') {
78
+ $data = array(
79
+ 'ASP',
80
+ $content,
81
+ );
82
+ $errorCode = 'ASPOpenTagFound';
83
+ }
84
+ else if (strpos($content, '<script ') !== false) {
85
+ $data = array(
86
+ 'Script',
87
+ $content,
88
+ );
89
+ $errorCode = 'ScriptOpenTagFound';
90
+ }
91
+ else {
92
+ return;
93
+ }
94
+ }
95
+ // Account for incorrect script open tags.
96
+ // The "(?:<s)?" in the regex is to work-around a bug in the tokenizer in PHP 5.2.
97
+ else if ($openTag['code'] === T_INLINE_HTML
98
+ && preg_match('`((?:<s)?cript (?:[^>]+)?language=[\'"]?php[\'"]?(?:[^>]+)?>)`i', $content, $match) === 1
99
+ ) {
100
+ $found = $match[1];
101
+ if (version_compare(phpversion(), '5.3', '<')) {
102
+ // Add the missing '<s' at the start of the match for PHP 5.2.
103
+ $found = '<s' . $match[1];
104
+ }
105
+
106
+ $data = array(
107
+ 'Script',
108
+ $found,
109
+ );
110
+ $errorCode = 'ScriptOpenTagFound';
111
+ }
112
+
113
+ if (isset($errorCode, $data)) {
114
+ $error = '%s style opening tags have been removed in PHP 7.0. Found "%s"';
115
+ $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
116
+ return;
117
+ }
118
+
119
+
120
+ // If we're still here, we can't be sure if what we find was really intended as ASP open tags.
121
+ if ($openTag['code'] === T_INLINE_HTML && $this->_aspTags === false) {
122
+ if (strpos($content, '<%') !== false) {
123
+ $error = 'Possible use of ASP style opening tags detected. ASP style opening tags have been removed in PHP 7.0. Found: %s';
124
+ $snippet = $this->getSnippet($content, '<%');
125
+ $data = array('<%'.$snippet);
126
+
127
+ $phpcsFile->addWarning($error, $stackPtr, 'MaybeASPOpenTagFound', $data);
128
+ }
129
+ }
130
+
131
+ }//end process()
132
+
133
+
134
+ /**
135
+ * Get a snippet from a HTML token.
136
+ *
137
+ * @param string $content The content of the HTML token.
138
+ * @param string $start_at Partial string to use as a starting point for the snippet.
139
+ * @param int $length The target length of the snippet to get. Defaults to 25.
140
+ *
141
+ * @return string
142
+ */
143
+ protected function getSnippet($content, $start_at = '', $length = 25)
144
+ {
145
+ $start_pos = 0;
146
+
147
+ if ($start_at !== '') {
148
+ $start_pos = strpos($content, $start_at);
149
+ if ($start_pos !== false) {
150
+ $start_pos += strlen($start_at);
151
+ }
152
+ }
153
+
154
+ $snippet = substr($content, $start_pos, $length);
155
+ if ((strlen($content) - $start_pos) > $length) {
156
+ $snippet .= '...';
157
+ }
158
+
159
+ return $snippet;
160
+
161
+ }//end getSnippet()
162
+
163
+ }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/RemovedFunctionParametersSniff.php CHANGED
@@ -16,18 +16,10 @@
16
  */
17
  class PHPCompatibility_Sniffs_PHP_RemovedFunctionParametersSniff extends PHPCompatibility_Sniff
18
  {
19
-
20
- /**
21
- * If true, forbidden functions will be considered regular expressions.
22
- *
23
- * @var bool
24
- */
25
- protected $patternMatch = false;
26
-
27
  /**
28
  * A list of removed function parameters, which were present in older versions.
29
  *
30
- * The array lists : version number with true (deprecated and false (removed).
31
  * The index is the location of the parameter in the parameter list, starting at 0 !
32
  * If's sufficient to list the first version where the function was deprecated/removed.
33
  *
@@ -81,12 +73,6 @@ class PHPCompatibility_Sniffs_PHP_RemovedFunctionParametersSniff extends PHPComp
81
  // they want to check for, so now we can cache out the list.
82
  $this->removedFunctionParametersNames = array_keys($this->removedFunctionParameters);
83
 
84
- if ($this->patternMatch === true) {
85
- foreach ($this->removedFunctionParametersNames as $i => $name) {
86
- $this->removedFunctionParametersNames[$i] = '/'.$name.'/i';
87
- }
88
- }
89
-
90
  return array(T_STRING);
91
  }//end register()
92
 
16
  */
17
  class PHPCompatibility_Sniffs_PHP_RemovedFunctionParametersSniff extends PHPCompatibility_Sniff
18
  {
 
 
 
 
 
 
 
 
19
  /**
20
  * A list of removed function parameters, which were present in older versions.
21
  *
22
+ * The array lists : version number with true (deprecated) and false (removed).
23
  * The index is the location of the parameter in the parameter list, starting at 0 !
24
  * If's sufficient to list the first version where the function was deprecated/removed.
25
  *
73
  // they want to check for, so now we can cache out the list.
74
  $this->removedFunctionParametersNames = array_keys($this->removedFunctionParameters);
75
 
 
 
 
 
 
 
76
  return array(T_STRING);
77
  }//end register()
78
 
vendor/wimg/php-compatibility/Sniffs/PHP/RemovedGlobalVariablesSniff.php CHANGED
@@ -56,14 +56,14 @@ class PHPCompatibility_Sniffs_PHP_RemovedGlobalVariablesSniff extends PHPCompati
56
  */
57
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
58
  {
59
- $tokens = $phpcsFile->getTokens();
60
- $varNameUc = strtoupper(substr($tokens[$stackPtr]['content'], 1));
61
 
62
- if (isset($this->removedGlobalVariables[$varNameUc]) === false) {
63
  return;
64
  }
65
 
66
- $versionList = $this->removedGlobalVariables[$varNameUc];
67
 
68
  $error = '';
69
  $isError = false;
56
  */
57
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
58
  {
59
+ $tokens = $phpcsFile->getTokens();
60
+ $varName = substr($tokens[$stackPtr]['content'], 1);
61
 
62
+ if (isset($this->removedGlobalVariables[$varName]) === false) {
63
  return;
64
  }
65
 
66
+ $versionList = $this->removedGlobalVariables[$varName];
67
 
68
  $error = '';
69
  $isError = false;
vendor/wimg/php-compatibility/Sniffs/PHP/RemovedHashAlgorithmsSniff.php CHANGED
@@ -13,7 +13,7 @@
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff.
15
  *
16
- * Discourages the use of deprecated and removed hash algorithms
17
  *
18
  * PHP version 5.4
19
  *
@@ -26,16 +26,20 @@ class PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff extends PHPCompatib
26
  {
27
 
28
  /**
29
- * List of functions using the algorithm as parameter (always the first parameter)
30
  *
31
- * @var array
 
 
 
32
  */
33
- protected $algoFunctions = array(
34
- 'hash_file',
35
- 'hash_hmac_file',
36
- 'hash_hmac',
37
- 'hash_init',
38
- 'hash'
 
39
  );
40
 
41
  /**
@@ -61,36 +65,94 @@ class PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff extends PHPCompatib
61
  */
62
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
63
  {
64
- if ($this->supportsAbove('5.4')) {
65
- $tokens = $phpcsFile->getTokens();
 
 
66
 
67
- if (in_array($tokens[$stackPtr]['content'], $this->algoFunctions) === true) {
68
- $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
 
 
69
 
70
- if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
71
- return;
72
- }
 
 
 
 
 
73
 
74
- $firstParam = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true);
75
-
76
- /**
77
- * Algorithm is a T_CONSTANT_ENCAPSED_STRING, so we need to remove the quotes
78
- */
79
- $algo = strtolower($tokens[$firstParam]['content']);
80
- $algo = substr($algo, 1, strlen($algo) - 2);
81
- switch ($algo) {
82
- case 'salsa10':
83
- case 'salsa20':
84
- $error = 'The Salsa10 and Salsa20 hash algorithms have been removed since PHP 5.4';
85
- $phpcsFile->addError($error, $stackPtr);
86
- break;
87
- }
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  }
90
  }
91
 
 
92
 
93
- }//end process()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
 
95
 
96
  }//end class
13
  /**
14
  * PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff.
15
  *
16
+ * Discourages the use of deprecated and removed hash algorithms.
17
  *
18
  * PHP version 5.4
19
  *
26
  {
27
 
28
  /**
29
+ * A list of removed hash algorithms, which were present in older versions.
30
  *
31
+ * The array lists : version number with false (deprecated) and true (removed).
32
+ * If's sufficient to list the first version where the hash algorithm was deprecated/removed.
33
+ *
34
+ * @var array(string => array(string => bool))
35
  */
36
+ protected $removedAlgorithms = array(
37
+ 'salsa10' => array(
38
+ '5.4' => true,
39
+ ),
40
+ 'salsa20' => array(
41
+ '5.4' => true,
42
+ ),
43
  );
44
 
45
  /**
65
  */
66
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
67
  {
68
+ $algo = $this->getHashAlgorithmParameter($phpcsFile, $stackPtr);
69
+ if (empty($algo) || is_string($algo) === false) {
70
+ return;
71
+ }
72
 
73
+ // Bow out if not one of the algorithms we're targetting.
74
+ if (isset($this->removedAlgorithms[$algo]) === false) {
75
+ return;
76
+ }
77
 
78
+ // Check if the algorithm used is deprecated or removed.
79
+ $errorInfo = $this->getErrorInfo($algo);
80
+
81
+ if ($errorInfo['deprecated'] !== '' || $errorInfo['removed'] !== '') {
82
+ $this->addError($phpcsFile, $stackPtr, $algo, $errorInfo);
83
+ }
84
+
85
+ }//end process()
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
+ /**
89
+ * Retrieve the relevant (version) information for the error message.
90
+ *
91
+ * @param string $algorithm The name of the algorithm.
92
+ *
93
+ * @return array
94
+ */
95
+ protected function getErrorInfo($algorithm)
96
+ {
97
+ $errorInfo = array(
98
+ 'deprecated' => '',
99
+ 'removed' => '',
100
+ 'error' => false,
101
+ );
102
+
103
+ foreach ($this->removedAlgorithms[$algorithm] as $version => $removed) {
104
+ if ($this->supportsAbove($version)) {
105
+ if ($removed === true && $errorInfo['removed'] === '') {
106
+ $errorInfo['removed'] = $version;
107
+ $errorInfo['error'] = true;
108
+ } elseif ($errorInfo['deprecated'] === '') {
109
+ $errorInfo['deprecated'] = $version;
110
+ }
111
  }
112
  }
113
 
114
+ return $errorInfo;
115
 
116
+ }//end getErrorInfo()
117
+
118
+
119
+ /**
120
+ * Generates the error or warning for this sniff.
121
+ *
122
+ * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
123
+ * @param int $stackPtr The position of the function
124
+ * in the token array.
125
+ * @param string $algorithm The name of the algorithm.
126
+ * @param array $errorInfo Array with details about the versions
127
+ * in which the algorithm was deprecated
128
+ * and/or removed.
129
+ *
130
+ * @return void
131
+ */
132
+ protected function addError($phpcsFile, $stackPtr, $algorithm, $errorInfo)
133
+ {
134
+ $error = 'The %s hash algorithm is ';
135
+ $errorCode = $algorithm . 'Found';
136
+ $data = array($algorithm);
137
+
138
+ if ($errorInfo['deprecated'] !== '') {
139
+ $error .= 'deprecated since PHP version %s and ';
140
+ $data[] = $errorInfo['deprecated'];
141
+ }
142
+ if ($errorInfo['removed'] !== '') {
143
+ $error .= 'removed since PHP version %s and ';
144
+ $data[] = $errorInfo['removed'];
145
+ }
146
+
147
+ // Remove the last 'and' from the message.
148
+ $error = substr($error, 0, strlen($error) - 5);
149
+
150
+ if ($errorInfo['error'] === true) {
151
+ $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
152
+ } else {
153
+ $phpcsFile->addWarning($error, $stackPtr, $errorCode, $data);
154
+ }
155
 
156
+ }//end addError()
157
 
158
  }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/RequiredOptionalFunctionParametersSniff.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @category PHP
6
  * @package PHPCompatibility
7
- * @author Wim Godden <wim.godden@cu.be>
8
  */
9
 
10
  /**
@@ -12,7 +12,7 @@
12
  *
13
  * @category PHP
14
  * @package PHPCompatibility
15
- * @author Wim Godden <wim.godden@cu.be>
16
  */
17
  class PHPCompatibility_Sniffs_PHP_RequiredOptionalFunctionParametersSniff extends PHPCompatibility_Sniff
18
  {
4
  *
5
  * @category PHP
6
  * @package PHPCompatibility
7
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
8
  */
9
 
10
  /**
12
  *
13
  * @category PHP
14
  * @package PHPCompatibility
15
+ * @author Juliette Reinders Folmer <phpcompatibility_nospam@adviesenzo.nl>
16
  */
17
  class PHPCompatibility_Sniffs_PHP_RequiredOptionalFunctionParametersSniff extends PHPCompatibility_Sniff
18
  {
vendor/wimg/php-compatibility/Sniffs/PHP/ShortArraySniff.php CHANGED
@@ -2,17 +2,6 @@
2
 
3
  class PHPCompatibility_Sniffs_PHP_ShortArraySniff extends PHPCompatibility_Sniff
4
  {
5
- /** @var array */
6
- protected $supportByVersion = array(
7
- '5.3' => false,
8
- '5.4' => true
9
- );
10
-
11
- /** @var array */
12
- protected $errorByForbiddenTokens = array(
13
- 'T_OPEN_SHORT_ARRAY' => 'Short array syntax (open)',
14
- 'T_CLOSE_SHORT_ARRAY' => 'Short array syntax (close)'
15
- );
16
 
17
  /**
18
  * Returns an array of tokens this test wants to listen for.
@@ -21,7 +10,10 @@ class PHPCompatibility_Sniffs_PHP_ShortArraySniff extends PHPCompatibility_Sniff
21
  */
22
  public function register()
23
  {
24
- return array(T_OPEN_TAG);
 
 
 
25
  }//end register()
26
 
27
 
@@ -36,24 +28,24 @@ class PHPCompatibility_Sniffs_PHP_ShortArraySniff extends PHPCompatibility_Sniff
36
  */
37
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
38
  {
 
 
 
 
39
  $tokens = $phpcsFile->getTokens();
 
 
 
 
40
 
41
- foreach ($tokens as $currentToken) {
42
- if (!isset($this->errorByForbiddenTokens[$currentToken['type']])) {
43
- continue;
44
- }
45
-
46
- foreach ($this->supportByVersion as $version => $support) {
47
- if ($this->supportsBelow($version)) {
48
- if ($support) {
49
- continue;
50
- }
51
-
52
- $error = $this->errorByForbiddenTokens[$currentToken['type']] . ' is available since 5.4';
53
- $phpcsFile->addError($error, $stackPtr);
54
- }
55
- }
56
  }
 
 
 
57
  }//end process()
58
 
59
  }//end class
2
 
3
  class PHPCompatibility_Sniffs_PHP_ShortArraySniff extends PHPCompatibility_Sniff
4
  {
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  /**
7
  * Returns an array of tokens this test wants to listen for.
10
  */
11
  public function register()
12
  {
13
+ return array(
14
+ T_OPEN_SHORT_ARRAY,
15
+ T_CLOSE_SHORT_ARRAY,
16
+ );
17
  }//end register()
18
 
19
 
28
  */
29
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
30
  {
31
+ if ($this->supportsBelow('5.3') === false) {
32
+ return;
33
+ }
34
+
35
  $tokens = $phpcsFile->getTokens();
36
+ $token = $tokens[$stackPtr];
37
+
38
+ $error = '%s is available since 5.4';
39
+ $data = array();
40
 
41
+ if ($token['type'] === 'T_OPEN_SHORT_ARRAY' ) {
42
+ $data[] = 'Short array syntax (open)';
43
+ } elseif ($token['type'] === 'T_CLOSE_SHORT_ARRAY' ) {
44
+ $data[] = 'Short array syntax (close)';
 
 
 
 
 
 
 
 
 
 
 
45
  }
46
+
47
+ $phpcsFile->addError($error, $stackPtr, 'Found', $data);
48
+
49
  }//end process()
50
 
51
  }//end class
vendor/wimg/php-compatibility/Sniffs/PHP/TernaryOperatorsSniff.php CHANGED
@@ -47,20 +47,20 @@ class PHPCompatibility_Sniffs_PHP_TernaryOperatorsSniff extends PHPCompatibility
47
  */
48
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
49
  {
50
- if (!$this->supportsAbove('5.3')) {
51
- $tokens = $phpcsFile->getTokens();
 
 
 
52
 
53
- // Get next non-whitespace token, and check it isn't the related inline else
54
- // symbol, which is not allowed prior to PHP 5.3.
55
- $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens,
56
- ($stackPtr + 1), null, true);
57
 
58
- if ($tokens[$next]['code'] == T_INLINE_ELSE) {
59
- $error = sprintf(
60
- "Middle may not be omitted from ternary operators in PHP < 5.3"
61
- );
62
- $phpcsFile->addWarning($error, $stackPtr);
63
- }
64
  }
65
  }
66
  }
47
  */
48
  public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
49
  {
50
+ if ($this->supportsBelow('5.2') === false) {
51
+ return;
52
+ }
53
+
54
+ $tokens = $phpcsFile->getTokens();
55
 
56
+ // Get next non-whitespace token, and check it isn't the related inline else
57
+ // symbol, which is not allowed prior to PHP 5.3.
58
+ $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens,
59
+ ($stackPtr + 1), null, true);
60
 
61
+ if ($next !== false && $tokens[$next]['code'] === T_INLINE_ELSE) {
62
+ $error = 'Middle may not be omitted from ternary operators in PHP < 5.3';
63
+ $phpcsFile->addWarning($error, $stackPtr);
 
 
 
64
  }
65
  }
66
  }
vendor/wimg/php-compatibility/Sniffs/PHP/ValidIntegersSniff.php CHANGED
@@ -101,7 +101,7 @@ class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sn
101
  /**
102
  * Could the current token an potentially be a binary integer ?
103
  *
104
- * @param array $token Token stack.
105
  * @param int $stackPtr The current position in the token stack.
106
  *
107
  * @return bool
@@ -126,7 +126,7 @@ class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sn
126
  /**
127
  * Is the current token an invalid binary integer ?
128
  *
129
- * @param array $token Token stack.
130
  * @param int $stackPtr The current position in the token stack.
131
  *
132
  * @return bool
@@ -149,7 +149,7 @@ class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sn
149
  * Retrieve the content of the tokens which together look like a binary integer.
150
  *
151
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
152
- * @param array $token Token stack.
153
  * @param int $stackPtr The position of the current token in
154
  * the stack.
155
  *
@@ -172,7 +172,7 @@ class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sn
172
  /**
173
  * Is the current token an invalid octal integer ?
174
  *
175
- * @param array $token Token stack.
176
  * @param int $stackPtr The current position in the token stack.
177
  *
178
  * @return bool
@@ -190,7 +190,7 @@ class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sn
190
  /**
191
  * Is the current token a hexidecimal numeric string ?
192
  *
193
- * @param array $token Token stack.
194
  * @param int $stackPtr The current position in the token stack.
195
  *
196
  * @return bool
@@ -198,7 +198,7 @@ class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sn
198
  private function isHexidecimalNumericString($tokens, $stackPtr) {
199
  $token = $tokens[$stackPtr];
200
 
201
- if ($token['code'] === T_CONSTANT_ENCAPSED_STRING && preg_match('`^([\'"])0x[a-f0-9]+\1$`iD', $token['content']) === 1) {
202
  return true;
203
  }
204
 
101
  /**
102
  * Could the current token an potentially be a binary integer ?
103
  *
104
+ * @param array $tokens Token stack.
105
  * @param int $stackPtr The current position in the token stack.
106
  *
107
  * @return bool
126
  /**
127
  * Is the current token an invalid binary integer ?
128
  *
129
+ * @param array $tokens Token stack.
130
  * @param int $stackPtr The current position in the token stack.
131
  *
132
  * @return bool
149
  * Retrieve the content of the tokens which together look like a binary integer.
150
  *
151
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
152
+ * @param array $tokens Token stack.
153
  * @param int $stackPtr The position of the current token in
154
  * the stack.
155
  *
172
  /**
173
  * Is the current token an invalid octal integer ?
174
  *
175
+ * @param array $tokens Token stack.
176
  * @param int $stackPtr The current position in the token stack.
177
  *
178
  * @return bool
190
  /**
191
  * Is the current token a hexidecimal numeric string ?
192
  *
193
+ * @param array $tokens Token stack.
194
  * @param int $stackPtr The current position in the token stack.
195
  *
196
  * @return bool
198
  private function isHexidecimalNumericString($tokens, $stackPtr) {
199
  $token = $tokens[$stackPtr];
200
 
201
+ if ($token['code'] === T_CONSTANT_ENCAPSED_STRING && preg_match('`^0x[a-f0-9]+$`iD', $this->stripQuotes($token['content'])) === 1) {
202
  return true;
203
  }
204
 
wpengine-phpcompat.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: PHP Compatibility Checker
4
  Plugin URI: https://wpengine.com
5
  Description: Make sure your plugins and themes are compatible with newer PHP versions.
6
  Author: WP Engine
7
- Version: 1.2.0
8
  Author URI: https://wpengine.com
9
  Text Domain: php-compatibility-checker
10
  */
@@ -220,7 +220,7 @@ class WPEngine_PHPCompat {
220
  */
221
  function create_menu() {
222
  // Create Tools sub-menu.
223
- $this->page = add_submenu_page( 'tools.php', __( 'PHP Compatibility', 'php-compatibility-checker' ), __( 'PHP Compatibility', 'php-compatibility-checker' ), 'manage_options', __FILE__, array( self::instance(), 'settings_page' ) );
224
  }
225
 
226
  /**
4
  Plugin URI: https://wpengine.com
5
  Description: Make sure your plugins and themes are compatible with newer PHP versions.
6
  Author: WP Engine
7
+ Version: 1.2.1
8
  Author URI: https://wpengine.com
9
  Text Domain: php-compatibility-checker
10
  */
220
  */
221
  function create_menu() {
222
  // Create Tools sub-menu.
223
+ $this->page = add_submenu_page( 'tools.php', __( 'PHP Compatibility', 'php-compatibility-checker' ), __( 'PHP Compatibility', 'php-compatibility-checker' ), 'manage_options', 'php-compatibility-checker', array( self::instance(), 'settings_page' ) );
224
  }
225
 
226
  /**