ok, so this should become something like
  
    if ( '/' === $ancestorPath) {
        $ancestorPath = '';
    } elseif (substr...) {
         throw new PathNotFoundException("Trailing slash in $ancestorPath");
    }