function Parser::parseFileDiff
1 call to Parser::parseFileDiff()
- Parser::parse in vendor/
sebastian/ diff/ src/ Parser.php
File
-
vendor/
sebastian/ diff/ src/ Parser.php, line 74
Class
- Parser
- Unified diff parser.
Namespace
SebastianBergmann\DiffCode
private function parseFileDiff(Diff $diff, array $lines) : void {
$chunks = [];
$chunk = null;
$diffLines = [];
foreach ($lines as $line) {
if (preg_match('/^@@\\s+-(?P<start>\\d+)(?:,\\s*(?P<startrange>\\d+))?\\s+\\+(?P<end>\\d+)(?:,\\s*(?P<endrange>\\d+))?\\s+@@/', $line, $match, PREG_UNMATCHED_AS_NULL)) {
$chunk = new Chunk((int) $match['start'], isset($match['startrange']) ? max(0, (int) $match['startrange']) : 1, (int) $match['end'], isset($match['endrange']) ? max(0, (int) $match['endrange']) : 1);
$chunks[] = $chunk;
$diffLines = [];
continue;
}
if (preg_match('/^(?P<type>[+ -])?(?P<line>.*)/', $line, $match)) {
$type = Line::UNCHANGED;
if ($match['type'] === '+') {
$type = Line::ADDED;
}
elseif ($match['type'] === '-') {
$type = Line::REMOVED;
}
$diffLines[] = new Line($type, $match['line']);
$chunk?->setLines($diffLines);
}
}
$diff->setChunks($chunks);
}