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');
    }