Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic/MultipleStatementAlignment: fix bug/list syntax before assignment operator #1924

Merged
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 @@ -116,30 +116,6 @@ public function checkAlignment($phpcsFile, $stackPtr)

for ($assign = $stackPtr; $assign < $phpcsFile->numTokens; $assign++) {
if (isset($find[$tokens[$assign]['code']]) === false) {
if ($tokens[$assign]['code'] === T_CLOSURE
|| $tokens[$assign]['code'] === T_ANON_CLASS
) {
$assign = $tokens[$assign]['scope_closer'];
$lastCode = $assign;
continue;
}

// Skip past the content of arrays.
if ($tokens[$assign]['code'] === T_OPEN_SHORT_ARRAY
&& isset($tokens[$assign]['bracket_closer']) === true
) {
$assign = $lastCode = $tokens[$assign]['bracket_closer'];
continue;
}

if ($tokens[$assign]['code'] === T_ARRAY
&& isset($tokens[$assign]['parenthesis_opener']) === true
&& isset($tokens[$tokens[$assign]['parenthesis_opener']]['parenthesis_closer']) === true
) {
$assign = $lastCode = $tokens[$tokens[$assign]['parenthesis_opener']]['parenthesis_closer'];
continue;
}

// A blank line indicates that the assignment block has ended.
if (isset(Tokens::$emptyTokens[$tokens[$assign]['code']]) === false) {
if (($tokens[$assign]['line'] - $tokens[$lastCode]['line']) > 1) {
Expand All @@ -163,10 +139,6 @@ public function checkAlignment($phpcsFile, $stackPtr)
}
}//end if

continue;
} else if ($assign !== $stackPtr && $tokens[$assign]['line'] === $lastLine) {
// Skip multiple assignments on the same line. We only need to
// try and align the first assignment.
continue;
}//end if

Expand Down Expand Up @@ -264,6 +236,10 @@ public function checkAlignment($phpcsFile, $stackPtr)

$lastLine = $tokens[$assign]['line'];
$prevAssign = $assign;

// Skip past the value assignment.
$assign = ($phpcsFile->findEndOfStatement($assign) - 1);
$lastCode = $assign;
}//end for

if (empty($assignments) === true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,19 @@ $foo = [
'a' => 'b',
];
$barbar = 'bar';

// Issue #1922 - allow for lists before the assignment operator.
public function buildForm(FormBuilderInterface $builder, array $options)
{
$transformer = new ContractTransformer($options['contracts']);
$types = ['support.contact.question' => ContactData::QUESTION];

[$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$transformer = new ContractTransformer($options['contracts']);
$types = ['support.contact.question' => ContactData::QUESTION];
[$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,19 @@ $foo = [
'a' => 'b',
];
$barbar = 'bar';

// Issue #1922 - allow for lists before the assignment operator.
public function buildForm(FormBuilderInterface $builder, array $options)
{
$transformer = new ContractTransformer($options['contracts']);
$types = ['support.contact.question' => ContactData::QUESTION];

[$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$transformer = new ContractTransformer($options['contracts']);
$types = ['support.contact.question' => ContactData::QUESTION];
[$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
}