public static function createArray($lines)
    {
        $op = Line::UNCHANGED;
        $hunks = [];
        /** @var Hunk $current */
        $current = null;
        foreach ($lines as $line) {
            switch ($line->getType()) {
                case Line::REMOVED:
                    if ($op != Line::REMOVED) {
                        // The last line was not removed so we start a new hunk.
                        $current = new Hunk($line, Hunk::REMOVED, $line->getIndex());
                    } else {
                        // continue adding the line to the hunk.
                        $current->addLine($line);
                    }
                    break;
                case Line::ADDED:
                    switch ($op) {
                        case Line::REMOVED:
                            // The hunk is a replacement.
                            $current->setType(Hunk::REPLACED);
                            $current->addLine($line);
                            break;
                        case Line::ADDED:
                            $current->addLine($line);
                            break;
                        case Line::UNCHANGED:
                            // Add a new hunk with the added type.
                            $current = new Hunk($line, Hunk::ADDED, $line->getIndex());
                            break;
                    }
                    break;
                case Line::UNCHANGED:
                    if ($current) {
                        // The hunk exists so add it to the array.
                        $hunks[] = $current;
                        $current = null;
                    }
                    break;
            }
            $op = $line->getType();
        }
        if ($current) {
            // The last line was part of a hunk, so add it.
            $hunks[] = $current;
        }

        return $hunks;
    }
public static function createArray($lines)
    {
        $op = Line::UNCHANGED;
        $hunks = [];
        /** @var Hunk $current */
        $current = null;
        foreach ($lines as $line) {
            switch ($line->getType()) {
                case Line::REMOVED:
                    if ($op != Line::REMOVED) {
                        // The last line was not removed so we start a new hunk.
                        $current = new Hunk($line, Hunk::REMOVED, $line->getIndex());
                    } else {
                        // continue adding the line to the hunk.
                        $current->addLine($line);
                    }
                    break;
                case Line::ADDED:
                    switch ($op) {
                        case Line::REMOVED:
                            // The hunk is a replacement.
                            $current->setType(Hunk::REPLACED);
                            $current->addLine($line);
                            break;
                        case Line::ADDED:
                            $current->addLine($line);
                            break;
                        case Line::UNCHANGED:
                            // Add a new hunk with the added type.
                            $current = new Hunk($line, Hunk::ADDED, $line->getIndex());
                            break;
                    }
                    break;
                case Line::UNCHANGED:
                    if ($current) {
                        // The hunk exists so add it to the array.
                        $hunks[] = $current;
                        $current = null;
                    }
                    break;
            }
            $op = $line->getType();
        }
        if ($current) {
            // The last line was part of a hunk, so add it.
            $hunks[] = $current;
        }

        return $hunks;
    }
public static function createArray ( $ lines ) { $ op = Line :: UNCHANGED ; $ hunks = [ ] ; /** @var Hunk $current */ $ current = null ; foreach ( $ lines as $ line ) { switch ( $ line -> getType ( ) ) { case Line :: REMOVED : if ( $ op != Line :: REMOVED ) { // The last line was not removed so we start a new hunk. $ current = new Hunk ( $ line , Hunk :: REMOVED , $ line -> getIndex ( ) ) ; } else { // continue adding the line to the hunk. $ current -> addLine ( $ line ) ; } break ; case Line :: ADDED : switch ( $ op ) { case Line :: REMOVED : // The hunk is a replacement. $ current -> setType ( Hunk :: REPLACED ) ; $ current -> addLine ( $ line ) ; break ; case Line :: ADDED : $ current -> addLine ( $ line ) ; break ; case Line :: UNCHANGED : // Add a new hunk with the added type. $ current = new Hunk ( $ line , Hunk :: ADDED , $ line -> getIndex ( ) ) ; break ; } break ; case Line :: UNCHANGED : if ( $ current ) { // The hunk exists so add it to the array. $ hunks [ ] = $ current ; $ current = null ; } break ; } $ op = $ line -> getType ( ) ; } if ( $ current ) { // The last line was part of a hunk, so add it. $ hunks [ ] = $ current ; } return $ hunks ; }
Create an array of hunks out of an array of lines.

@param Line[] $lines
The lines of the diff.
@return Hunk[]
The hunks in the lines.
Create an array of hunks out of an array of lines .