PhpSpec\CodeGenerator\Writer\TokenizedCodeWriter::insertStringAfterLine PHP Method

insertStringAfterLine() private method

private insertStringAfterLine ( string $target, string $toInsert, integer $line, boolean $leadingNewline = true ) : string
$target string
$toInsert string
$line integer
$leadingNewline boolean
return string
    private function insertStringAfterLine($target, $toInsert, $line, $leadingNewline = true)
    {
        $lines = explode("\n", $target);
        $lastLines = array_slice($lines, $line);
        $toInsert = trim($toInsert, "\n\r");
        if ($leadingNewline) {
            $toInsert = "\n" . $toInsert;
        }
        array_unshift($lastLines, $toInsert);
        array_splice($lines, $line, count($lines), $lastLines);
        return implode("\n", $lines);
    }