Skip to content

Commit ee4ed0a

Browse files
committed
Merge branch 'master' into 3.0
2 parents 132d641 + 9de93e0 commit ee4ed0a

File tree

11 files changed

+88
-38
lines changed

11 files changed

+88
-38
lines changed

package.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@ http://pear.php.net/dtd/package-2.0.xsd">
3333
- installed_paths config setting can now point directly to a standard instead of the dir above
3434
- Improved the performance of the CSS tokenizer, especially on very large CSS files (thousands of lines)
3535
-- Thanks to Klaus Purer for the patch
36-
- Defined tokens for lower PHP versions are now phpcs-specific string instead of ints
36+
- Defined tokens for lower PHP versions are now phpcs-specific strings instead of ints
3737
-- Stops conflict with other projects, like PHP_CodeCoverage
3838
- Added more guard code for syntax errors to various sniffs
39+
- Squiz ValidLogicalOperatorsSniff now ignores XOR as type casting is different when using the ^ operator (request #567)
3940
- Squiz CommentedOutCodeSniff is now better at ignoring URLs inside comments
4041
- Fixed bug #584 : Squiz.Arrays.ArrayDeclaration sniff gives incorrect NoComma error for multiline string values
42+
- Fixed bug #589 : PEAR.Functions.FunctionCallSignature sniff not checking all function calls
4143
- Fixed bug #592 : USE statement tokenising can sometimes result in mismatched scopes
4244
- Fixed bug #594 : Tokenizer issue on closure that returns by reference
45+
- Fixed bug #595 : Colons in CSS selectors within media queries throw false positives
46+
-- Thanks to Klaus Purer for the patch
4347
</notes>
4448
<contents>
4549
<dir name="/">

src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class FunctionCallSignatureSniff implements Sniff
8181
*/
8282
public function register()
8383
{
84-
return array(T_STRING);
84+
return Tokens::$functionNameTokens;
8585

8686
}//end register()
8787

src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
);
33
test();
44
test($arg, $arg2);
5-
test ();
5+
isset ();
66
test( );
77
test() ;
88
test( $arg);
9-
test( $arg );
10-
test ( $arg );
9+
empty( $arg );
10+
eval ( $arg );
1111

1212
if (is_array($arg) === true) {
1313

src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc.fixed

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
);
33
test();
44
test($arg, $arg2);
5+
isset();
56
test();
67
test();
7-
test();
8-
test($arg);
9-
test($arg);
108
test($arg);
9+
empty($arg);
10+
eval($arg);
1111

1212
if (is_array($arg) === true) {
1313

src/Standards/Squiz/Sniffs/ControlStructures/ForEachLoopDeclarationSniff.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ public function process(File $phpcsFile, $stackPtr)
149149
}//end if
150150

151151
$asToken = $phpcsFile->findNext(T_AS, $openingBracket);
152+
if ($asToken === false) {
153+
$error = 'Possible parse error: FOREACH has no AS statement';
154+
$phpcsFile->addWarning($error, $stackPtr, 'MissingAs');
155+
return;
156+
}
157+
152158
$content = $tokens[$asToken]['content'];
153159
if ($content !== strtolower($content)) {
154160
$expected = strtolower($content);

src/Standards/Squiz/Sniffs/Operators/ValidLogicalOperatorsSniff.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public function register()
4848
return array(
4949
T_LOGICAL_AND,
5050
T_LOGICAL_OR,
51-
T_LOGICAL_XOR,
5251
);
5352

5453
}//end register()
@@ -70,7 +69,6 @@ public function process(File $phpcsFile, $stackPtr)
7069
$replacements = array(
7170
'and' => '&&',
7271
'or' => '||',
73-
'xor' => '^',
7472
);
7573

7674
$operator = strtolower($tokens[$stackPtr]['content']);

src/Standards/Squiz/Tests/CSS/SemicolonSpacingUnitTest.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@
1818
.HelpWidgetType-list {
1919
list-style-image: url();
2020
}
21+
22+
@media (min-width: 320px) and (max-width: 961px) {
23+
.tooltipsrt:hover span.tltp,
24+
.tooltipstp:hover span.tltp {
25+
visibility: hidden;
26+
}
27+
}

src/Standards/Squiz/Tests/Operators/ValidLogicalOperatorsUnitTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ public function getErrorList()
5151
5 => 1,
5252
11 => 1,
5353
17 => 2,
54-
23 => 1,
55-
26 => 1,
5654
);
5755

5856
}//end getErrorList()

src/Tokenizers/CSS.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,20 +267,33 @@ public function tokenize($string)
267267
}//end for
268268

269269
// A flag to indicate if we are inside a style definition,
270-
// which is defined using curly braces. I'm assuming you can't
271-
// have nested curly brackets.
270+
// which is defined using curly braces.
272271
$inStyleDef = false;
273272

273+
// A flag to indicate if an At-rule like "@media" is used, which will result
274+
// in nested curly brackets.
275+
$asperandStart = false;
276+
274277
$numTokens = count($finalTokens);
275278
for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) {
276279
$token = $finalTokens[$stackPtr];
277280

278281
switch ($token['code']) {
279282
case T_OPEN_CURLY_BRACKET:
280-
$inStyleDef = true;
283+
// Opening curly brackets for an At-rule do not start a style
284+
// definition. We also reset the asperand flag here because the next
285+
// opening curly bracket could be indeed the start of a style
286+
// definition.
287+
if ($asperandStart === true) {
288+
$inStyleDef = false;
289+
$asperandStart = false;
290+
} else {
291+
$inStyleDef = true;
292+
}
281293
break;
282294
case T_CLOSE_CURLY_BRACKET:
283-
$inStyleDef = false;
295+
$inStyleDef = false;
296+
$asperandStart = false;
284297
break;
285298
case T_MINUS:
286299
// Minus signs are often used instead of spaces inside
@@ -372,6 +385,9 @@ public function tokenize($string)
372385
}
373386
}//end if
374387

388+
break;
389+
case T_ASPERAND:
390+
$asperandStart = true;
375391
break;
376392
default:
377393
// Nothing special to be done with this token.

src/Tokenizers/Tokenizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ private function createLevelMap()
10511051
echo "* token $badToken:$type removed from conditions array *".PHP_EOL;
10521052
}
10531053

1054-
unset ($openers[$lastOpener]);
1054+
unset($openers[$lastOpener]);
10551055

10561056
$level--;
10571057
if (PHP_CODESNIFFER_VERBOSITY > 1) {

src/Util/Tokens.php

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ final class Tokens
157157
/**
158158
* The token weightings.
159159
*
160-
* @var array(int => int)
160+
* @var array<int, int>
161161
*/
162162
public static $weightings = array(
163163
T_CLASS => 1000,
@@ -235,7 +235,7 @@ final class Tokens
235235
/**
236236
* Tokens that represent assignments.
237237
*
238-
* @var array(int)
238+
* @var array<int, int>
239239
*/
240240
public static $assignmentTokens = array(
241241
T_EQUAL => T_EQUAL,
@@ -255,7 +255,7 @@ final class Tokens
255255
/**
256256
* Tokens that represent equality comparisons.
257257
*
258-
* @var array(int)
258+
* @var array<int, int>
259259
*/
260260
public static $equalityTokens = array(
261261
T_IS_EQUAL => T_IS_EQUAL,
@@ -269,7 +269,7 @@ final class Tokens
269269
/**
270270
* Tokens that represent comparison operator.
271271
*
272-
* @var array(int)
272+
* @var array<int, int>
273273
*/
274274
public static $comparisonTokens = array(
275275
T_IS_EQUAL => T_IS_EQUAL,
@@ -285,7 +285,7 @@ final class Tokens
285285
/**
286286
* Tokens that represent arithmetic operators.
287287
*
288-
* @var array(int)
288+
* @var array<int, int>
289289
*/
290290
public static $arithmeticTokens = array(
291291
T_PLUS => T_PLUS,
@@ -298,7 +298,7 @@ final class Tokens
298298
/**
299299
* Tokens that represent casting.
300300
*
301-
* @var array(int)
301+
* @var array<int, int>
302302
*/
303303
public static $castTokens = array(
304304
T_INT_CAST => T_INT_CAST,
@@ -314,7 +314,7 @@ final class Tokens
314314
/**
315315
* Token types that open parenthesis.
316316
*
317-
* @var array(int)
317+
* @var array<int, int>
318318
*/
319319
public static $parenthesisOpeners = array(
320320
T_ARRAY => T_ARRAY,
@@ -332,7 +332,7 @@ final class Tokens
332332
/**
333333
* Tokens that are allowed to open scopes.
334334
*
335-
* @var array(int)
335+
* @var array<int, int>
336336
*/
337337
public static $scopeOpeners = array(
338338
T_CLASS => T_CLASS,
@@ -362,7 +362,7 @@ final class Tokens
362362
/**
363363
* Tokens that represent scope modifiers.
364364
*
365-
* @var array(int)
365+
* @var array<int, int>
366366
*/
367367
public static $scopeModifiers = array(
368368
T_PRIVATE => T_PRIVATE,
@@ -373,7 +373,7 @@ final class Tokens
373373
/**
374374
* Tokens that can prefix a method name
375375
*
376-
* @var array(int)
376+
* @var array<int, int>
377377
*/
378378
public static $methodPrefixes = array(
379379
T_PRIVATE => T_PRIVATE,
@@ -387,7 +387,7 @@ final class Tokens
387387
/**
388388
* Tokens that perform operations.
389389
*
390-
* @var array(int)
390+
* @var array<int, int>
391391
*/
392392
public static $operators = array(
393393
T_MINUS => T_MINUS,
@@ -405,7 +405,7 @@ final class Tokens
405405
/**
406406
* Tokens that perform boolean operations.
407407
*
408-
* @var array(int)
408+
* @var array<int, int>
409409
*/
410410
public static $booleanOperators = array(
411411
T_BOOLEAN_AND => T_BOOLEAN_AND,
@@ -418,7 +418,7 @@ final class Tokens
418418
/**
419419
* Tokens that open code blocks.
420420
*
421-
* @var array(int)
421+
* @var array<int, int>
422422
*/
423423
public static $blockOpeners = array(
424424
T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET,
@@ -430,7 +430,7 @@ final class Tokens
430430
/**
431431
* Tokens that don't represent code.
432432
*
433-
* @var array(int)
433+
* @var array<int, int>
434434
*/
435435
public static $emptyTokens = array(
436436
T_WHITESPACE => T_WHITESPACE,
@@ -447,7 +447,7 @@ final class Tokens
447447
/**
448448
* Tokens that are comments.
449449
*
450-
* @var array(int)
450+
* @var array<int, int>
451451
*/
452452
public static $commentTokens = array(
453453
T_COMMENT => T_COMMENT,
@@ -465,7 +465,7 @@ final class Tokens
465465
*
466466
* Note that T_STRINGS are NOT represented in this list.
467467
*
468-
* @var array(int)
468+
* @var array<int, int>
469469
*/
470470
public static $stringTokens = array(
471471
T_CONSTANT_ENCAPSED_STRING => T_CONSTANT_ENCAPSED_STRING,
@@ -475,7 +475,7 @@ final class Tokens
475475
/**
476476
* Tokens that represent brackets and parenthesis.
477477
*
478-
* @var array(int)
478+
* @var array<int, int>
479479
*/
480480
public static $bracketTokens = array(
481481
T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET,
@@ -489,7 +489,7 @@ final class Tokens
489489
/**
490490
* Tokens that include files.
491491
*
492-
* @var array(int)
492+
* @var array<int, int>
493493
*/
494494
public static $includeTokens = array(
495495
T_REQUIRE_ONCE => T_REQUIRE_ONCE,
@@ -501,7 +501,7 @@ final class Tokens
501501
/**
502502
* Tokens that make up a heredoc string.
503503
*
504-
* @var array(int)
504+
* @var array<int, int>
505505
*/
506506
public static $heredocTokens = array(
507507
T_START_HEREDOC => T_START_HEREDOC,
@@ -512,6 +512,27 @@ final class Tokens
512512
T_NOWDOC => T_NOWDOC,
513513
);
514514

515+
/**
516+
* Tokens that represent the names of called functions.
517+
*
518+
* Mostly, these are just strings. But PHP tokeizes some language
519+
* constructs and functions using their own tokens.
520+
*
521+
* @var array<int, int>
522+
*/
523+
public static $functionNameTokens = array(
524+
T_STRING => T_STRING,
525+
T_EVAL => T_EVAL,
526+
T_EXIT => T_EXIT,
527+
T_INCLUDE => T_INCLUDE,
528+
T_INCLUDE_ONCE => T_INCLUDE_ONCE,
529+
T_REQUIRE => T_REQUIRE,
530+
T_REQUIRE_ONCE => T_REQUIRE_ONCE,
531+
T_ISSET => T_ISSET,
532+
T_UNSET => T_UNSET,
533+
T_EMPTY => T_EMPTY,
534+
);
535+
515536

516537
/**
517538
* Returns the highest weighted token type.
@@ -523,8 +544,8 @@ final class Tokens
523544
*
524545
* Returns false if there are no weightings for any of the specified tokens.
525546
*
526-
* @param array(int) $tokens The token types to get the highest weighted
527-
* type for.
547+
* @param array<int, int> $tokens The token types to get the highest weighted
548+
* type for.
528549
*
529550
* @return int The highest weighted token.
530551
*/

0 commit comments

Comments
 (0)