@@ -16,6 +16,13 @@ class PhpCodeStore extends CodeStore
1616 */
1717 private $ defaultLevel = [];
1818
19+ /**
20+ * The heredoc identifier.
21+ *
22+ * @var string|null
23+ */
24+ private $ heredocIdentifier ;
25+
1926 //--------------------------------------------------------------------------------------------------------------------
2027 /**
2128 * Object constructor.
@@ -42,6 +49,8 @@ protected function indentationMode(string $line): int
4249 $ line = trim ($ line );
4350
4451 $ mode = 0 ;
52+
53+ $ mode |= $ this ->indentationModeHeredoc ($ line );
4554 $ mode |= $ this ->indentationModeSwitch ($ line );
4655 $ mode |= $ this ->indentationModeBLock ($ line );
4756
@@ -93,6 +102,8 @@ private function indentationModeBlock(string $line): int
93102 {
94103 $ mode = 0 ;
95104
105+ if ($ this ->heredocIdentifier !==null ) return $ mode ;
106+
96107 if (substr ($ line , -1 , 1 )=='{ ' )
97108 {
98109 $ mode |= self ::C_INDENT_INCREMENT_AFTER ;
@@ -119,6 +130,38 @@ private function indentationModeBlock(string $line): int
119130 return $ mode ;
120131 }
121132
133+ //--------------------------------------------------------------------------------------------------------------------
134+ /**
135+ *
136+ * @param string $line The line of code.
137+ *
138+ * @return int
139+ */
140+ private function indentationModeHeredoc (string $ line ): int
141+ {
142+ $ mode = 0 ;
143+
144+ if ($ this ->heredocIdentifier !==null )
145+ {
146+ $ mode |= self ::C_INDENT_HEREDOC ;
147+
148+ if ($ line ==$ this ->heredocIdentifier .'; ' )
149+ {
150+ $ this ->heredocIdentifier = null ;
151+ }
152+ }
153+ else
154+ {
155+ $ n = preg_match ('/=\s*<<<\s*([A-Z]+)$/ ' , $ line , $ parts );
156+ if ($ n ==1 )
157+ {
158+ $ this ->heredocIdentifier = $ parts [1 ];
159+ }
160+ }
161+
162+ return $ mode ;
163+ }
164+
122165 //--------------------------------------------------------------------------------------------------------------------
123166 /**
124167 * Returns the indentation mode based on a line of code for switch statements.
@@ -131,6 +174,8 @@ private function indentationModeSwitch(string $line): int
131174 {
132175 $ mode = 0 ;
133176
177+ if ($ this ->heredocIdentifier !==null ) return $ mode ;
178+
134179 if (substr ($ line , 0 , 5 )=='case ' )
135180 {
136181 $ mode |= self ::C_INDENT_INCREMENT_AFTER ;
0 commit comments