/** * Main method that creates for each line of the diff file a DiffLine object * and add it to the right DiffBlock object * * @param array $lines */ public function parse($lines) { $lines = $this->unsetSummaryInformation($lines); $factory = FactoryLine::init(); foreach ($lines as $line) { $line = $factory->build($line); if ($line instanceof DiffBlockLine) { if (isset($left) && isset($right) && !$this->checkCorrectLineNumbers($left, $right)) { throw new Exception('There are differeces in the number of line of the two cloks left and right. ' . __FILE__ . ':' . __LINE__); } //echo "DiffBlock\n"; $right = new DiffBlock($line->getStartRight()); $left = new DiffBlock($line->getStartLeft()); $this->right[] = $right; $this->left[] = $left; continue; } switch ($line->getStatus()) { case DiffLine::equal: //echo "*** equal\n"; //echo "left:\n"; $left->resetEmptyLineNumber(); $left->addLine($line); //echo "right:\n"; $right->resetEmptyLineNumber(); $right->addLine($line); break; case DiffLine::left: //echo "*** left:\n"; //echo "left \n"; $left->addLine($line); //echo "right \n"; $right->getTotalLineInserted() < $left->getTotalLineInserted() ? $right->addLine(new DiffLine(null)) : null; break; case DiffLine::right: //echo "*** right:\n"; //echo "right \n"; $right->addLine($line); //echo "left \n"; $left->getTotalLineInserted() < $right->getTotalLineInserted() ? $left->addLine(new DiffLine(null)) : null; break; } } }
/** * initalize the factory class * * @return RepositoryFactory */ public static function init() { $class = __CLASS__; return self::$instance = new $class(); }