Skip to content

Commit

Permalink
Don't add spaces around declare() arguments.
Browse files Browse the repository at this point in the history
PSR12 recommends `declare(strict_types=1)` not `declare(strict_types = 1)`
  • Loading branch information
markstory committed Jun 8, 2018
1 parent d6018c8 commit c585837
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CakePHP/Sniffs/WhiteSpace/OperatorSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function process(File $phpcsFile, $stackPtr)
$tokens = $phpcsFile->getTokens();

// Skip default values in function declarations.
// and declare statements
if ($tokens[$stackPtr]['code'] === T_EQUAL
|| $tokens[$stackPtr]['code'] === T_MINUS
) {
Expand All @@ -65,7 +66,9 @@ public function process(File $phpcsFile, $stackPtr)
$bracket = array_pop($parenthesis);
if (isset($tokens[$bracket]['parenthesis_owner']) === true) {
$function = $tokens[$bracket]['parenthesis_owner'];
if ($tokens[$function]['code'] === T_FUNCTION) {
if ($tokens[$function]['code'] === T_FUNCTION ||
$tokens[$function]['code'] === T_DECLARE
) {
return;
}
}
Expand Down
1 change: 1 addition & 0 deletions CakePHP/Tests/WhiteSpace/OperatorSpacingUnitTest.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
$ten =10 * 2;
$ten= -10 * 2;
$ten = 10/-2;
Expand Down
8 changes: 4 additions & 4 deletions CakePHP/Tests/WhiteSpace/OperatorSpacingUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class OperatorSpacingUnitTest extends AbstractSniffUnitTest
public function getErrorList()
{
return [
2 => 1,
3 => 1,
4 => 2,
5 => 1,
4 => 1,
5 => 2,
6 => 1,
7 => 2,
7 => 1,
8 => 2,
];
}

Expand Down
1 change: 1 addition & 0 deletions CakePHP/Tests/WhiteSpace/OperatorSpacingunitTest.inc.fixed
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
$ten = 10 * 2;
$ten = -10 * 2;
$ten = 10 / -2;
Expand Down

0 comments on commit c585837

Please sign in to comment.