Preserve Manual Indentation in Concatenated Strings During Code Formatting

Hello, i'm using latest PhpStorm's version. Include PHP auto-formatter does not preserve custom indentation/alignment in multi-line string concatenation expressions, making it difficult to maintain visually structured code (e.g., SQL queries, formatted output).

Do you know a Code Style option to preserve manual indentation within string concatenation expressions, similar to how some formatters handle multi-line arrays or method chains?

Use Cases

  1. SQL Queries - Aligning SQL keywords for readability
  2. Formatted Text Output - Building ASCII tables or formatted strings
  3. Template Strings - Maintaining visual structure in concatenated markup

Steps to reproduce:

Before formatting:

<?php

function buildQuery()
{
   $query = "SELECT " .
           "id, name, email " .
       "FROM " .
           "users " .
       "WHERE " .
           "status = 'active' " .
           "AND role = 'admin'";

   return $query;
}

?>

After auto-format (Ctrl+Alt+L):

<?php

   function buildQuery()
   {
       $query = "SELECT " .
           "id, name, email " .
           "FROM " .
           "users " .
           "WHERE " .
           "status = 'active' " .
           "AND role = 'admin'";

       return $query;
   }

?>

Expected behavior:

<?php
   function buildQuery()
   {
       $query = "SELECT " .
               "id, name, email " .
           "FROM " .
               "users " .
           "WHERE " .
               "status = 'active' " .
           "AND role = 'admin'";

       return $query;
   }

?>

 

I created support ticket, but i didn't get response since 11/26/2025

0
3 comments

Adammankowski97, this is pure PHP syntax, which is neither attached to a data source nor associated with a particular SQL dialect. This is the reason SQL code style formatting is not applied to this wrapped SQL piece. As a workaround, you can try to create your own customer place template using the User Parameters. Please see here   

0

Thank you for the reply, Aleksandr Molchanov, but unfortunately User Parameters don’t apply to my case.

0
Sorry to hear this. This is just a workaround we could suggest in your particular case. As mentioned in my previous reply, we can't treat the whole piece as a SQL dialect; thus, SQL formatting settings don't apply.  
0

Please sign in to leave a comment.