Liip\RMT\Changelog\Formatter\SemanticChangelogFormatter::findPositionToInsert PHP Method

findPositionToInsert() protected method

Return the position where to insert new lines according to the type of insertion
protected findPositionToInsert ( array $lines, string $type ) : integer
$lines array Existing lines
$type string Release type
return integer The position where to insert
    protected function findPositionToInsert($lines, $type)
    {
        // Major are always inserted at the top
        if ($type == 'major') {
            return 0;
        }
        // Minor must be inserted one line above the first major section
        if ($type == 'minor') {
            foreach ($lines as $pos => $line) {
                if (preg_match('/^=======/', $line)) {
                    return $pos + 1;
                }
            }
        }
        // Patch should go directly after the first minor
        if ($type == 'patch') {
            foreach ($lines as $pos => $line) {
                if (preg_match('/Version\\s\\d+\\.\\d+\\s\\-/', $line)) {
                    return $pos + 1;
                }
            }
        }
        throw new \Liip\RMT\Exception('Invalid changelog formatting');
    }