File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -214,6 +214,25 @@ public function getCode()
214214 return implode (PHP_EOL , $ lines ).PHP_EOL ;
215215 }
216216
217+ //--------------------------------------------------------------------------------------------------------------------
218+ /**
219+ * Returns the last line of code (without indentation applied).
220+ *
221+ * @return string
222+ *
223+ * @since 1.1.0
224+ * @api
225+ */
226+ public function getLastLine ()
227+ {
228+ if (empty ($ this ->lines ))
229+ {
230+ throw new \LogicException ('No code in code store ' );
231+ }
232+
233+ return $ this ->lines [count ($ this ->lines ) - 1 ];
234+ }
235+
217236 //--------------------------------------------------------------------------------------------------------------------
218237 /**
219238 * Returns the raw code without indentation as an array of strings.
Original file line number Diff line number Diff line change @@ -286,6 +286,32 @@ public function testTrim()
286286 $ this ->assertEquals ($ expected , $ code );
287287 }
288288
289+ //--------------------------------------------------------------------------------------------------------------------
290+ /**
291+ * Test getLastLine.
292+ */
293+ public function testGetLastLine1 ()
294+ {
295+ $ store = new ConcreteCodeStore ();
296+ $ store ->append ('begin ' );
297+ $ store ->append ('statement1 ' );
298+ $ store ->append ('statement2 ' );
299+
300+ $ this ->assertEquals ('statement2 ' , $ store ->getLastLine ());
301+ }
302+
303+ //--------------------------------------------------------------------------------------------------------------------
304+ /**
305+ * Test getLastLine with empty code store.
306+ *
307+ * @expectedException \LogicException
308+ */
309+ public function testGetLastLine2 ()
310+ {
311+ $ store = new ConcreteCodeStore ();
312+ $ store ->getLastLine ();
313+ }
314+
289315 //--------------------------------------------------------------------------------------------------------------------
290316}
291317
You can’t perform that action at this time.
0 commit comments