private function getUnindentedSelectedCode() { $detector = new IndentationDetector($this->selectedCode); $lines = array_map(function ($line) use($detector) { return substr($line, $detector->getMinIndentation()); }, iterator_to_array(new ToStringIterator($this->selectedCode->getIterator()))); return LineCollection::createFromArray($lines); }
public function testAppendLinesAddsGivenLines() { $lines = LineCollection::createFromArray(array('line1', 'line2')); $lines->appendLines(LineCollection::createFromArray(array('line3', 'line4'))); $this->assertEquals(array('line1', 'line2', 'line3', 'line4'), iterator_to_array(new ToStringIterator($lines->getIterator()))); }
public function testAppendLinesObeysIndentation() { $this->lines->addIndentation(); $this->lines->appendLines(LineCollection::createFromArray(array('echo "line1";', 'echo "line2";'))); $this->assertLinesMatch(array(' echo "line1";', ' echo "line2";')); }
public function testSelectedCodeIsAddedWithCorrectIndetations() { $action = new AddMethod(0, $this->createMethodSignatureWithReturnVars(array()), LineCollection::createFromArray(array(' if ($something) {', ' echo "Hello World!";', ' }'))); $this->assertGeneratedCodeMatches(array('', ' private function testMethod()', ' {', ' if ($something) {', ' echo "Hello World!";', ' }', ' }'), $action); }
/** * @param string[] $lines * * @return string */ private function getIndent(array $lines) { $detector = new IndentationDetector(LineCollection::createFromArray($lines)); return str_repeat(' ', $detector->getFirstLineIndentation()); }
private function getSelectedCode() { return LineCollection::createFromArray($this->extractRange->sliceCode($this->file->getCode())); }