Slight code formatting issue

I am seeing an issue with code formatting under specific circumstances and would like to know if this is a bug or an issue with my set up.

In a standard PHP file, the following code formats the second 'if block' in line with the first, rather than indenting it, as expected.

<div class="test">
<?php
if ($foo == 1) {
if ($bar > 0) { ?>
<p></p>
<?php
} ?>
<script></script>
<?php
} ?>
</div>

If you remove the HTML content (p tags in this case) from within this second, OR you remove the script tags, the code formats as expected. The problem also only seems to occur if the PHP code is wrapped in a HTML element.

I am running the latest EAP:

PhpStorm 2016.2.1
Build #PS-162.1628.23, built on August 10, 2016
JRE: 1.8.0_77-b03 amd64
JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation

5 comments
Avatar
Vladimir Luchansky
Comment actions Permalink

Hello,

Looks like we already have a related request submitted to our tracker here: <https://youtrack.jetbrains.com/issue/WI-11090>. Please vote for it in order to move it up in the queue and receive notifications regarding the progress of the feature. See more information on working with tracker at <https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications>.

0
Comment actions Permalink

I'm pretty sure this is a different issue.

The request you link to is a request for '<?php' tags to wrap to a new line when used within HTML. That is not expected behaviour and I would not want that.

My issue is the indenting of the second 'if' block. This works perfectly most of the time. The only time I have seen it behave as above, is under these exact conditions.

<div class="test1">
<?php
if ($foo == 1) {
if ($bar > 0) { ?>
<p>With HTML tags</p>
<?php
} ?>
<script></script>
<?php
} ?>
</div>

<div class="test2">
<?php
if ($foo == 1) {
if ($bar > 0) { ?>
No HTML tags
<?php
} ?>
<script></script>
<?php
} ?>
</div>

<div class="test3">
<?php
if ($foo == 1) {
if ($bar > 0) { ?>
<p>With HTML tags</p>
<?php
} ?>
Script tags removed
<?php
} ?>
</div>

The above code is exactly as formatted by PHPStorm. The second and third divs show expected behaviour by indenting the second 'if' block. The first div (with both the p and script tags) keeps the second 'if' statement directly under the first, which is not expected behaviour.

0
Comment actions Permalink

Thank you for the detailed explanation, it looks like a bug.
Please submit it, something like "If interrupted by an HTML tag is not being indented", and attach the latter code snippet: https://youtrack.jetbrains.com/issues#newissue

0
Comment actions Permalink

Thanks. I have submitted the report as requested: https://youtrack.jetbrains.com/issue/WI-32908 

Please let me know if you require any further information

0
Comment actions Permalink

All the further communication will be in a bug report thread, thanks.

0

Please sign in to leave a comment.