Skip to content

Commit 87e423b

Browse files
committed
Updating WPCS & PHPCompatibility sniffs.
1 parent 61b22fc commit 87e423b

File tree

180 files changed

+7326
-3195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+7326
-3195
lines changed

README.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ c9.ide.language.php.wordpress
33

44
__Name__ : WordPress Coding Standards Linter for Cloud9
55

6-
__Current Version__: 0.0.1 (alpha)
6+
__Current Version__: 0.0.2a
77

88
__Author__ : [EP4](https://ep4.com)
99

@@ -72,4 +72,16 @@ Ressources
7272
* PHP CodeSniffer : [GitHub repo](https://github.com/squizlabs/PHP_CodeSniffer) & [Wiki](https://github.com/squizlabs/PHP_CodeSniffer/wiki)
7373
* WordPress Coding Standards : [GitHub Repo](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards), [Wiki](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki) & [Whitelisting code which flags errors](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors)
7474
* PHPCompatibility : [GitHub Repo](https://github.com/wimg/PHPCompatibility)
75-
* Cloud9 : [SDK](https://cloud9-sdk.readme.io/) & [API](https://apidoc.c9.io)
75+
* Cloud9 : [SDK](https://cloud9-sdk.readme.io/) & [API](https://apidoc.c9.io)
76+
77+
Changelog
78+
---------
79+
80+
### 0.0.2a - 2017-02-13
81+
82+
* Updating WP Coding Standards with the latest release as of 2017-02-10.
83+
* Updading PHPCompabitity with the latest release as of 2017-02-06
84+
85+
### 0.0.1 (alpha) - 2017-02-10
86+
87+
Initial release.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "phpcs.wpcs",
33
"description": "Displays warnings in the IDE with the help of PHP CodeSniffer configured with WordPress Coding Standards and PHPCompatibility rules.",
4-
"version": "0.0.1",
4+
"version": "0.0.2",
55
"author": "EP4",
66
"contributors": [
77
{

server/phpcs/rules/PHPCompatibility/Sniffs/PHP/ForbiddenCallTimePassByReferenceSniff.php

+23
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,24 @@ protected function isCallTimePassByReferenceParam(PHP_CodeSniffer_File $phpcsFil
179179
case T_CLOSE_PARENTHESIS:
180180
break;
181181

182+
// Prevent false positive on assign by reference and compare with reference
183+
// with function call parameters.
184+
case T_EQUAL:
185+
case T_AND_EQUAL:
186+
case T_OR_EQUAL:
187+
case T_CONCAT_EQUAL:
188+
case T_DIV_EQUAL:
189+
case T_MINUS_EQUAL:
190+
case T_MOD_EQUAL:
191+
case T_MUL_EQUAL:
192+
case T_PLUS_EQUAL:
193+
case T_XOR_EQUAL:
194+
case T_SL_EQUAL:
195+
case T_SR_EQUAL:
196+
case T_IS_EQUAL:
197+
case T_IS_IDENTICAL:
198+
break;
199+
182200
// Unfortunately the tokenizer fails to recognize global constants,
183201
// class-constants and -attributes. Any of these are returned is
184202
// treated as T_STRING.
@@ -200,6 +218,11 @@ protected function isCallTimePassByReferenceParam(PHP_CodeSniffer_File $phpcsFil
200218
// If not a class constant: fall through.
201219

202220
default:
221+
// Deal with T_POW_EQUAL which doesn't exist in PHPCS 1.x
222+
if (defined('T_POW_EQUAL') && $tokens[$tokenBefore]['type'] === 'T_POW_EQUAL') {
223+
break;
224+
}
225+
203226
// The found T_BITWISE_AND represents a pass-by-reference.
204227
return true;
205228
}

server/phpcs/rules/PHPCompatibility/Sniffs/PHP/ForbiddenNamesAsDeclaredSniff.php

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public function register()
8787
*/
8888
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
8989
{
90+
if ($this->supportsAbove('7.0') === false) {
91+
return;
92+
}
93+
9094
$tokens = $phpcsFile->getTokens();
9195
$tokenCode = $tokens[$stackPtr]['code'];
9296
$tokenContentLc = strtolower($tokens[$stackPtr]['content']);

server/phpcs/rules/PHPCompatibility/Tests/BaseClass/FunctionsTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,22 @@ class BaseClass_FunctionsTest extends PHPUnit_Framework_TestCase
2727
protected $helperClass;
2828

2929

30+
/**
31+
* Set up fixtures for this unit test.
32+
*
33+
* @return void
34+
*/
3035
public static function setUpBeforeClass()
3136
{
3237
require_once dirname(__FILE__) . '/TestHelperPHPCompatibility.php';
38+
parent::setUpBeforeClass();
3339
}
3440

41+
/**
42+
* Sets up this unit test.
43+
*
44+
* @return void
45+
*/
3546
protected function setUp()
3647
{
3748
parent::setUp();

server/phpcs/rules/PHPCompatibility/Tests/BaseClass/MethodTestFrame.php

+11
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,22 @@ abstract class BaseClass_MethodTestFrame extends PHPUnit_Framework_TestCase
4545
protected $helperClass;
4646

4747

48+
/**
49+
* Set up fixtures for this unit test.
50+
*
51+
* @return void
52+
*/
4853
public static function setUpBeforeClass()
4954
{
5055
require_once dirname(__FILE__) . '/TestHelperPHPCompatibility.php';
56+
parent::setUpBeforeClass();
5157
}
5258

59+
/**
60+
* Sets up this unit test.
61+
*
62+
* @return void
63+
*/
5364
protected function setUp()
5465
{
5566
parent::setUp();

server/phpcs/rules/PHPCompatibility/Tests/BaseSniffTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class BaseSniffTest extends PHPUnit_Framework_TestCase
3939
public static function setUpBeforeClass()
4040
{
4141
self::$sniffFiles = array();
42+
parent::setUpBeforeClass();
4243
}
4344

4445
/**
@@ -59,6 +60,8 @@ protected function setUp()
5960

6061
self::$phpcs->process(array(), dirname( __FILE__ ) . '/../');
6162
self::$phpcs->setIgnorePatterns(array());
63+
64+
parent::setUp();
6265
}
6366

6467
/**

server/phpcs/rules/PHPCompatibility/Tests/Sniffs/PHP/ForbiddenBreakContinueVariableArgumentsSniffTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ class ForbiddenBreakContinueVariableArgumentsSniffTest extends BaseSniffTest
3636
protected $_sniffFile;
3737

3838
/**
39-
* setUp
39+
* Set up the test file for this unit test.
4040
*
4141
* @return void
4242
*/
43-
public function setUp()
43+
protected function setUp()
4444
{
4545
parent::setUp();
4646

server/phpcs/rules/PHPCompatibility/Tests/Sniffs/PHP/ForbiddenCallTimePassByReferenceSniffTest.php

+23-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class ForbiddenCallTimePassByReferenceSniffTest extends BaseSniffTest
3030
protected $_sniffFile;
3131

3232
/**
33-
* setUp
33+
* Set up the test file for this unit test.
3434
*
3535
* @return void
3636
*/
37-
public function setUp()
37+
protected function setUp()
3838
{
3939
parent::setUp();
4040

@@ -79,6 +79,7 @@ public function dataForbiddenCallTimePassByReference() {
7979
array(44), // Bad: call time pass by reference.
8080
array(45), // Bad: call time pass by reference.
8181
array(49), // Bad: multiple call time pass by reference.
82+
array(71), // Bad: call time pass by reference.
8283
);
8384
}
8485

@@ -122,6 +123,26 @@ public function dataNoViolation()
122123

123124
array(51), // OK: No variables.
124125
array(53), // OK: Outside scope of this sniff.
126+
127+
// Assign by reference within function call.
128+
array(56),
129+
array(57),
130+
array(58),
131+
array(59),
132+
array(60),
133+
array(61),
134+
array(62),
135+
array(63),
136+
array(64),
137+
array(65),
138+
array(66),
139+
array(67),
140+
array(68),
141+
array(69),
142+
143+
// Comparison with reference.
144+
array(74),
145+
array(75),
125146
);
126147
}
127148

server/phpcs/rules/PHPCompatibility/Tests/Sniffs/PHP/InternalInterfacesSniffTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ class InternalInterfacesSniffTest extends BaseSniffTest
2828
protected $_sniffFile;
2929

3030
/**
31-
* setUp
31+
* Set up the test file for this unit test.
3232
*
3333
* @return void
3434
*/
35-
public function setUp()
35+
protected function setUp()
3636
{
3737
parent::setUp();
3838

server/phpcs/rules/PHPCompatibility/Tests/Sniffs/PHP/NewExecutionDirectivesSniffTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class NewExecutionDirectivesSniffTest extends BaseSniffTest
3030
protected $_sniffFile;
3131

3232
/**
33-
* setUp
33+
* Set up the test file for some of these unit tests.
3434
*
3535
* @return void
3636
*/
37-
public function setUp()
37+
protected function setUp()
3838
{
3939
parent::setUp();
4040

server/phpcs/rules/PHPCompatibility/Tests/Sniffs/PHP/NewMagicMethodsSniffTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ class NewMagicMethodsSniffTest extends BaseSniffTest
3030

3131
/**
3232
* Set up skip condition.
33+
*
34+
* @return void
3335
*/
3436
public static function setUpBeforeClass()
3537
{
3638
// When using PHPCS 1.x combined with PHP 5.3 or lower, traits are not recognized.
3739
if (version_compare(PHP_CodeSniffer::VERSION, '2.0', '<') && version_compare(phpversion(), '5.4', '<')) {
3840
self::$recognizesTraits = false;
3941
}
42+
43+
parent::setUpBeforeClass();
4044
}
4145

4246

server/phpcs/rules/PHPCompatibility/Tests/Sniffs/PHP/NewScalarReturnTypeDeclarationsSniffTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class NewScalarReturnTypeDeclarationsSniffTest extends BaseSniffTest
2323
const TEST_FILE = 'sniff-examples/new_scalar_return_type_declarations.php';
2424

2525
/**
26-
* Set up: skip these tests if the PHPCS version isn't high enough.
26+
* Skip the test(s) for low PHPCS versions.
27+
*
28+
* @return void
2729
*/
2830
protected function setUp()
2931
{

server/phpcs/rules/PHPCompatibility/Tests/Sniffs/PHP/NonStaticMagicMethodsSniffTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ class NonStaticMagicMethodsSniffTest extends BaseSniffTest
3030

3131
/**
3232
* Set up skip condition.
33+
*
34+
* @return void
3335
*/
3436
public static function setUpBeforeClass()
3537
{
3638
// When using PHPCS 1.x combined with PHP 5.3 or lower, traits are not recognized.
3739
if (version_compare(PHP_CodeSniffer::VERSION, '2.0', '<') && version_compare(phpversion(), '5.4', '<')) {
3840
self::$recognizesTraits = false;
3941
}
42+
43+
parent::setUpBeforeClass();
4044
}
4145

4246

server/phpcs/rules/PHPCompatibility/Tests/Sniffs/PHP/RemovedAlternativePHPTagsUnitTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ class RemovedAlternativePHPTagsSniffTest extends BaseSniffTest
3131

3232
/**
3333
* Set up skip condition.
34+
*
35+
* @return void
3436
*/
3537
public static function setUpBeforeClass()
3638
{
3739
if (version_compare(phpversion(), '7.0', '<')) {
3840
self::$aspTags = (boolean) ini_get('asp_tags');
3941
}
42+
43+
parent::setUpBeforeClass();
4044
}
4145

4246

server/phpcs/rules/PHPCompatibility/Tests/Sniffs/PHP/RemovedExtensionsSniffTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class RemovedExtensionsSniffTest extends BaseSniffTest
3131
protected $_sniffFile;
3232

3333
/**
34-
* setUp
34+
* Set up the test file for some of these unit tests.
3535
*
3636
* @return void
3737
*/
38-
public function setUp()
38+
protected function setUp()
3939
{
4040
parent::setUp();
4141

server/phpcs/rules/PHPCompatibility/Tests/Sniffs/PHP/ValidIntegersSniffTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class ValidIntegersSniffTest extends BaseSniffTest
3030
protected $_sniffFile;
3131

3232
/**
33-
* setUp
33+
* Set up the test file for some of these unit tests.
3434
*
3535
* @return void
3636
*/
37-
public function setUp()
37+
protected function setUp()
3838
{
3939
parent::setUp();
4040

server/phpcs/rules/PHPCompatibility/Tests/sniff-examples/call_time_pass_by_reference.php

+22
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,25 @@ public function bar($arg)
5151
bcd(10, true, MYCONST); // OK: does not contain variables.
5252

5353
cde((&$abc)); // OK: outside of the scope of this sniff - will result in parse error.
54+
55+
// Issue https://github.com/wimg/PHPCompatibility/issues/68
56+
$attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3]); // OK: assign by reference.
57+
if (!is_null($done = &$this->cacheKey('autoPurgeCache'))) {} // OK: assign by reference.
58+
def( $dummy .= &$b );
59+
def( $dummy += &$b );
60+
def( $dummy -= &$b );
61+
def( $dummy *= &$b );
62+
def( $dummy /= &$b );
63+
def( $dummy %= &$b );
64+
def( $dummy **= &$b );
65+
def( $dummy &= &$b );
66+
def( $dummy |= &$b );
67+
def( $dummy ^= &$b );
68+
def( $dummy <<= &$b );
69+
def( $dummy >>= &$b );
70+
71+
def( &$dummy .= $b ); // Bad: pass by reference.
72+
73+
// Ok: Comparisons passed as function parameter.
74+
efg( true == &$b );
75+
efg( true === &$b );

0 commit comments

Comments
 (0)