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 @@ -507,6 +507,7 @@ public static int findStartTokenOfExpression(TokenSequence ts) {
Token token;
int balance = 0;
int curlyBalance = 0;
boolean isInQuotes = false; // GH-6731 for checking a variable in string
do {
token = ts.token();
if (token.id() == PHPTokenId.PHP_TOKEN) {
Expand All @@ -520,6 +521,14 @@ public static int findStartTokenOfExpression(TokenSequence ts) {
default:
//no-op
}
} else if (token.id() == PHPTokenId.PHP_CONSTANT_ENCAPSED_STRING) {
// GH-6731 for checking a variable in string
// e.g. "example {$example}"
if ((token.text().length() == 1 && TokenUtilities.textEquals(token.text(), "\"")) // NOI18N
|| (!TokenUtilities.startsWith(token.text(), "\"") && TokenUtilities.endsWith(token.text(), "\"")) // NOI18N
|| (TokenUtilities.startsWith(token.text(), "\"") && !TokenUtilities.endsWith(token.text(), "\""))) { // NOI18N
isInQuotes = !isInQuotes;
}
} else if ((token.id() == PHPTokenId.PHP_SEMICOLON || token.id() == PHPTokenId.PHP_OPENTAG)
&& ts.moveNext()) {
// we found previous end of expression => find begin of the current.
Expand Down Expand Up @@ -584,7 +593,7 @@ public static int findStartTokenOfExpression(TokenSequence ts) {
break;
} else if (token.id() == PHPTokenId.PHP_CURLY_CLOSE) {
curlyBalance--;
if (curlyBalance == -1 && ts.moveNext()) {
if (!isInQuotes && curlyBalance == -1 && ts.moveNext()) {
// we are after previous blog close
LexUtilities.findNext(ts, Arrays.asList(
PHPTokenId.WHITESPACE,
Expand All @@ -600,7 +609,7 @@ public static int findStartTokenOfExpression(TokenSequence ts) {
}
} else if (token.id() == PHPTokenId.PHP_CURLY_OPEN) {
curlyBalance++;
if (curlyBalance == 1 && ts.moveNext()) {
if (!isInQuotes && curlyBalance == 1 && ts.moveNext()) {
// we are at the begining of a blog
LexUtilities.findNext(ts, Arrays.asList(
PHPTokenId.WHITESPACE,
Expand Down
23 changes: 23 additions & 0 deletions php/php.editor/test/unit/data/testfiles/indent/gh6731_01.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

$result = test(
"test {$test}"
);^
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

$result = test(
"test {$test}"
);
^
23 changes: 23 additions & 0 deletions php/php.editor/test/unit/data/testfiles/indent/gh6731_02.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

$result = test(
"test {$test} test"
);^
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

$result = test(
"test {$test} test"
);
^
21 changes: 21 additions & 0 deletions php/php.editor/test/unit/data/testfiles/indent/gh6731_03.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

$result = test("test {$test} test");^
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

$result = test("test {$test} test");
^
27 changes: 27 additions & 0 deletions php/php.editor/test/unit/data/testfiles/indent/gh6731_04.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

$result = test(
"test"
. "test"
. "test"
. "test"
. "test {$test}"
);^
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

$result = test(
"test"
. "test"
. "test"
. "test"
. "test {$test}"
);
^
28 changes: 28 additions & 0 deletions php/php.editor/test/unit/data/testfiles/indent/gh6731_05.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

class GH6731 {

public function test() {
$result = test(
"test {$test}"
);^
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

class GH6731 {

public function test() {
$result = test(
"test {$test}"
);
^
}
}
28 changes: 28 additions & 0 deletions php/php.editor/test/unit/data/testfiles/indent/gh6731_06.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

class GH6731 {

public function test() {
$result = $this->something(
"test {$test}"
);^
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

class GH6731 {

public function test() {
$result = $this->something(
"test {$test}"
);
^
}
}
28 changes: 28 additions & 0 deletions php/php.editor/test/unit/data/testfiles/indent/gh6731_07.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

class GH6731 {

public function test() {
$result = self::something(
"test {$test} test"
);^
}
}
Loading