Parse the diff of one file

Parse the unified diff for one file, which may consists of a finitie
amount of diff chunks.

@param \Arbit\VCSWrapper\Diff\Collection $diff
@param array $lines
@return void
5834
protected function parseFileDiff(\Arbit\VCSWrapper\Diff\Collection $diff, array $lines)
    {
        $chunks = array();
        while (count($lines)) {
            // Skip lines until we hit a range specification
            while (!preg_match('(^@@\\s+-(?P<start>\\d+)(?:,\\s*(?P<startrange>\\d+))?\\s+\\+(?P<end>\\d+)(?:,\\s*(?P<endrange>\\d+))?\\s+@@)', $last = array_shift($lines), $match)) {
                // If we reached the end, break
                if ($last === null) {
                    break 2;
                }
            }

            $chunk = new \Arbit\VCSWrapper\Diff\Chunk(
                $match['start'],
                (isset($match['startrange']) ? max(1, $match['startrange']) : 1),
                $match['end'],
                (isset($match['endrange']) ? max(1, $match['endrange']) : 1)
            );

            // Read following diff lines
            $diffLines = array();
            $last      = null;
            while (count($lines) &&
                    (preg_match('(^(?P<type>[+ -])(?P<line>.*))', $last = array_shift($lines), $match) ||
                      (strpos($last, '\\ No newline at end of file') === 0)))
            {
                // We ignore the missing newlines for now
                if (count($match)) {
                    $diffLines[] = new \Arbit\VCSWrapper\Diff\Line(
                        ($match['type'] === '+' ? \Arbit\VCSWrapper\Diff\Line::ADDED :
                            ($match['type'] === '-' ? \Arbit\VCSWrapper\Diff\Line::REMOVED : \Arbit\VCSWrapper\Diff\Line::UNCHANGED)),
                        $match['line']
                    );
                }
            }
            $chunk->lines = $diffLines;
            $chunks[]     = $chunk;

            // Repreprend last not matching line
            if ($last !== null) {
                array_unshift($lines, $last);
            }
        }

        $diff->chunks = $chunks;
    }
1233703
private function parseMh(array $lines, $num, $start, $end)
    {
        return $this->parseSh($lines, $num, $start, $end);
    }
1018955
public function analyseUNH(array $line)
    {
        if (\count($line) < 3) {
            return;
        }

        $lineElement = $line[2];
        if (!\is_array($lineElement)) {
            $this->messageFormat = $lineElement;

            return;
        }

        $this->messageFormat = $lineElement[0];
        $this->messageDirectory = $lineElement[2];
    }
203958
protected function readLine($file, $lines = 50)
    {
        if (is_file($file) === false) {
            $this->error('tail: cannot open ‘'.$file.'’ for reading: No such file or directory');

            return;
        }

        $fp = fopen($file, 'r');
        $i = 1;
        $result = [];
        while (! feof($fp)) {
            if ($i > $lines) {
                break;
            }
            $content = fgets($fp);
            $result[] = $content;
            $i++;
        }
        fclose($fp);

        $this->line(implode('', $result));
    }
565096
public function addLine(Line $line)
    {
        $this->lines[] = $line;
        $this->end = $line->getIndex();
    }
1363070
protected function parseStringLine( Line$line ):self
	{
		return $this->openNode(new StringNode($this,$line))->appendLine($this->htmlEntities(trim($line->getContent())));
	}
1229890
public function appendToLine($originalLine, array $lines)
    {
        // Why is this one method different to the rest?
        $originalLine++;

        $this->buffer->insert($this->createLineNumber($originalLine), $lines);
    }
421045
private function isFileStart(array $diffLineList, int $currentLine): bool
    {
        return $currentLine + 1 < count($diffLineList)
            && '---' === substr($diffLineList[$currentLine], 0, 3)
            && '+++' === substr($diffLineList[$currentLine + 1], 0, 3);
    }
461131
public function removeLine(int $line): void
    {
        foreach ($this->file->getTokens() as $tagPtr => $tagToken) {
            if ($tagToken['line'] !== $line) {
                continue;
            }

            $this->fixer->replaceToken($tagPtr, '');

            if ($tagToken['line'] > $line) {
                break;
            }
        }
    }
232864
private function parseDescription( $line ) {
		while ( preg_match('/{@([^}]*)}/', $line, $matches) ) {
			switch( $matches[1] ) {
				case 'internal' : 
					$line = str_replace( $matches[0], '', $line );
				break;
				default :
					$line = str_replace( $matches[0], $matches[1], $line );
				break;
			}
		}
		$line = str_replace( array( '\@', '{@*}' ), array( '@', '*/' ), $line );
		return $line;
	}
215139
protected function parse_line($line) {
        $data = array();
        foreach ($line as $keynum => $value) {
            if (!isset($this->columns[$keynum])) {
                // This should not happen.
                continue;
            }

            $key = $this->columns[$keynum];
            $data[$key] = $value;
        }
        return $data;
    }
1100146
public static function trimEmptyLines(array $lines) : array
    {
        for ($last = count($lines) - 1; $last > -1; $last--) {
            if (!empty($lines[$last])) {
                return $lines;
            }
            unset($lines[$last]);
        }
        return $lines;
    }
963
private function isHeaderLine(string $line): bool
    {
        $matches = [];
        if (preg_match('#^diff --git [a|b|c|i|w|o]/(.*) [a|b|c|i|w|o]/(.*)#', $line, $matches)) {
            $this->appendCollectedFileAndChanges();
            $this->currentOperation = File::OP_MODIFIED;
            $this->currentFileName  = $matches[2];
            return true;
        }
        return false;
    }
456627
private function isChangeCodeLine(string $line): bool
    {
        $line = $this->parseCodeLine($line);
        $this->currentChanges[$this->currentPosition]->addLine($line);
        return true;
    }
1201876
protected function processLine($line)
    {
        if ($line === '') {
            $this->handleBlankLine();
            return;
        }

        $this->justNewEntry = false;

        $data = $this->parseLine($line);

        if ($data['key'][0] === '#') {
            $this->handleComment($data);
            return;
        }

        $this->handleOtherCases($data, $line);
    }
322786
private static function parseHeaderLine(&$headers, $line)
    {
        $parts = explode(':', $line, 2);
        if (count($parts) == 1) {
            return;
        }

        list($name, $value) = $parts;
        $headers[trim($name)] = trim($value);
    }
515178
public function delete($line, $lines)
    {
        foreach (range(0, $lines-1) as $offset) {
            $this->lines[$line+$offset-1] = null;
        }
        return $this;
    }