src/Parser.php
protected function parseSegments(array $segments, $closingNumber, $withoutClosing)
    {
        if ($closingNumber !== count($segments) - 1) {
            if (preg_match("~" . self::DYNAMIC_REGEX . "(*SKIP)(*F)|\]~x", $withoutClosing)) {
                   throw new BadRouteException(BadRouteException::OPTIONAL_SEGMENTS_ON_MIDDLE);
            } else throw new BadRouteException(BadRouteException::UNCLOSED_OPTIONAL_SEGMENTS);
        }
    }
protected function parseSegments(array $segments, $closingNumber, $withoutClosing)
    {
        if ($closingNumber !== count($segments) - 1) {
            if (preg_match("~" . self::DYNAMIC_REGEX . "(*SKIP)(*F)|\]~x", $withoutClosing)) {
                   throw new BadRouteException(BadRouteException::OPTIONAL_SEGMENTS_ON_MIDDLE);
            } else throw new BadRouteException(BadRouteException::UNCLOSED_OPTIONAL_SEGMENTS);
        }
    }
protected function parseSegments ( array $ segments , $ closingNumber , $ withoutClosing ) { if ( $ closingNumber !== count ( $ segments ) - 1 ) { if ( preg_match ( "~" . self :: DYNAMIC_REGEX . "(*SKIP)(*F)|\]~x" , $ withoutClosing ) ) { throw new BadRouteException ( BadRouteException :: OPTIONAL_SEGMENTS_ON_MIDDLE ) ; } else throw new BadRouteException ( BadRouteException :: UNCLOSED_OPTIONAL_SEGMENTS ) ; } }
Parse all the possible patterns seeking for an incorrect or incompatible pattern.

@param string[] $segments       Segments are all the possible patterns made on top of a pattern with optional segments.
@param int      $closingNumber  The count of optional segments.
@param string   $withoutClosing The pattern without the closing token of an optional segment. aka: ]

@throws BadRouteException
Parse all the possible patterns seeking for an incorrect or incompatible pattern .