private static function parsePossibleLengthStringToSet($possibleLengthString)
    {
        if (strlen($possibleLengthString) === 0) {
            throw new \RuntimeException('Empty possibleLength string found.');
        }

        $lengths = explode(',', $possibleLengthString);
        $lengthSet = array();


        $lengthLength = count($lengths);
        for ($i = 0; $i < $lengthLength; $i++) {
            $lengthSubstring = $lengths[$i];
            if (strlen($lengthSubstring) === 0) {
                throw new \RuntimeException('Leading, trailing or adjacent commas in possible '
                    . "length string {$possibleLengthString}, these should only separate numbers or ranges.");
            }

            if (substr($lengthSubstring, 0, 1) === '[') {
                if (substr($lengthSubstring, -1) !== ']') {
                    throw new \RuntimeException("Missing end of range character in possible length string {$possibleLengthString}.");
                }

                // Strip the leading and trailing [], and split on the -.
                $minMax = explode('-', substr($lengthSubstring, 1, -1));
                if (count($minMax) !== 2) {
                    throw new \RuntimeException("Ranges must have exactly one - character: missing for {$possibleLengthString}.");
                }
                $min = (int)$minMax[0];
                $max = (int)$minMax[1];
                // We don't even accept [6-7] since we prefer the shorter 6,7 variant; for a range to be in
                // use the hyphen needs to replace at least one digit.
                if ($max - $min < 2) {
                    throw new \RuntimeException("The first number in a range should be two or more digits lower than the second. Culprit possibleLength string: {$possibleLengthString}.");
                }
                for ($j = $min; $j <= $max; $j++) {
                    if (in_array($j, $lengthSet)) {
                        throw new \RuntimeException("Duplicate length element found ({$j}) in possibleLength string {$possibleLengthString}.");
                    }
                    $lengthSet[] = $j;
                }
            } else {
                $length = $lengthSubstring;
                if (in_array($length, $lengthSet)) {
                    throw new \RuntimeException("Duplicate length element found ({$length}) in possibleLength string {$possibleLengthString}.");
                }
                if (!is_numeric($length)) {
                    throw new \RuntimeException("For input string \"{$length}\"");
                }
                $lengthSet[] = (int)$length;
            }
        }
        return $lengthSet;
    }