Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public function process(File $phpcsFile, $stackPtr)

$error = 'Short array syntax must be used to define arrays';

if (isset($tokens[$stackPtr]['parenthesis_opener']) === false
|| isset($tokens[$stackPtr]['parenthesis_closer']) === false
) {
if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) {
// Live coding/parse error, just show the error, don't try and fix it.
$phpcsFile->addError($error, $stackPtr, 'Found');
return;
Expand All @@ -61,13 +59,9 @@ public function process(File $phpcsFile, $stackPtr)

$phpcsFile->fixer->beginChangeset();

if ($opener === null) {
$phpcsFile->fixer->replaceToken($stackPtr, '[]');
} else {
$phpcsFile->fixer->replaceToken($stackPtr, '');
$phpcsFile->fixer->replaceToken($opener, '[');
$phpcsFile->fixer->replaceToken($closer, ']');
}
$phpcsFile->fixer->replaceToken($stackPtr, '');
$phpcsFile->fixer->replaceToken($opener, '[');
$phpcsFile->fixer->replaceToken($closer, ']');

$phpcsFile->fixer->endChangeset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ $var = array();
$var = [1,2,3];
$var = array(1,2,3);
echo $var[1];
$foo = array($var[1],$var[2]);
$foo = ARRAY($var[1],$var[2]);
$foo = array(
1,
2,
3
);
$var = array/*comment*/(1,2,3);
$var = array;

function foo(array $array) {}

Expand All @@ -26,3 +25,9 @@ array_map(
static fn (array $value): array => array_filter($value),
[]
);

class Foo {
function array() {}
}

$obj->array( 1, 2, 3 );
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ $foo = [
3
];
$var = /*comment*/[1,2,3];
$var = array;

function foo(array $array) {}

Expand All @@ -26,3 +25,9 @@ array_map(
static fn (array $value): array => array_filter($value),
[]
);

class Foo {
function array() {}
}

$obj->array( 1, 2, 3 );
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error (long array syntax missing parentheses).
// This should be the only test in this file.
// Testing that the sniff is *not* triggered.

$var = array
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function getErrorList($testFile='')
2 => 1,
9 => 1,
];
case 'DisallowLongArraySyntaxUnitTest.3.inc':
return [
7 => 1,
];
default:
return [];
}//end switch
Expand Down