Get the Last Curl Bracket of a class

@param $domainClass
@param $matches
@return mixed

@throws
513572
public function getLastCurlBracketPositionFromClass($domainClass)
    {
        $matches = [];

        $lastClassCurlBracketPattern = "/\}[ \r\n]*[^{}]\$/";
        preg_match($lastClassCurlBracketPattern, $domainClass . " ", $matches, PREG_OFFSET_CAPTURE);
        $lastClassBracketIdx = $matches[0][1];

        if ($lastClassBracketIdx == 0) {
            throw new \Exception("Can't append function");
        }

        return $lastClassBracketIdx;
    }
115008
private function restoreProtectedHtml($matches): string
    {
        \preg_match('/.*"(?<id>\d*)"/', $matches['attributes'], $matchesInner);

        $html = '';
        if (isset($this->protectedChildNodes[$matchesInner['id']])) {
            $html .= $this->protectedChildNodes[$matchesInner['id']];
        }

        return $html;
    }
518801
public function _callback($matches)
    {
        list(, $tag, $firstcar) = $matches;

        // check the first character
        if (!preg_match('/^\$|@|=|[a-zA-Z\/]$/', $firstcar)) {
            $this->doError1('errors.tpl.tag.syntax.invalid', $tag);
        }

        $this->_currentTag = $tag;
        if ($firstcar == '=') {
            return  '<?php echo '.$this->_parseVariable(substr($tag, 1)).'; ?>';
        } elseif ($firstcar == '$' || $firstcar == '@') {
            return  '<?php echo '.$this->_parseVariable($tag).'; ?>';
        } else {
            if (!preg_match('/^(\/?[a-zA-Z0-9_]+)(?:(?:\s+(.*))|(?:\((.*)\)))?$/ms', $tag, $m)) {
                $this->doError1('errors.tpl.tag.function.invalid', $tag);
            }
            if (count($m) == 4) {
                $m[2] = $m[3];
            }
            if (!isset($m[2])) {
                $m[2] = '';
            }
            if ($m[1] == 'ldelim') {
                return '{';
            }
            if ($m[1] == 'rdelim') {
                return '}';
            }

            return '<?php '.$this->_parseFunction($m[1], $m[2]).'?>';
        }
    }
1000770
public function resolve($matches = [])
    {
        if (!isset($this->route['controller'])) {
            return false;
        }

        list($controller,) = explode('@', $this->route['controller']);

        $fileName = (new ReflectionClass($controller))->getFileName();
        $rootPath = substr($fileName, 0, strrpos($fileName, 'src'));
        $composerFilePath = $rootPath . 'composer.json';

        if($rootPath === '' || ! file_exists($composerFilePath)) {
            return false;
        }

        $this->package = $this->extensionFactory->getComposerPackage($composerFilePath);
        $this->name = $this->package->getName();

        return $this->name;
    }
581318
private function computeUrlRegex(array $matches)
    {
        $this->names[] = $matches[1];

        if (isset($this->conditions[$matches[1]])) {
            return '(?P<' . $matches[1] . '>' . $this->conditions[$matches[1]] . ')';
        }

        if (substr($matches[0], -1) === '+') {

            $this->namesPath[$matches[1]] = 1;

            return '(?P<' . $matches[1] . '>.+)';
        }

        return '(?P<' . $matches[1] . '>[^/]+)';
    }
491354
private function encryptMailText(array $matches): string
    {
        $email = $matches[1];

        return $this->getSecuredName($email).
            $this->mailAtText[array_rand($this->mailAtText)].
            $this->getSecuredName($email, true);
    }
171556
public static function getFormatClass($format)
    {
        // Return a namespace in a given format
        $class = sprintf('%s\Format\%sFormat', __NAMESPACE__, ucfirst(strtolower($format)));

        if (!class_exists($class)) {
            throw new \DomainException(
                sprintf(
                    'Structure format: %s not supported. Class: %s not found.',
                    $format,
                    $class
                )
            );
        }

        return $class;
    }
1188101
public static function getByClassFlags(int $classFlags)
    {
        $operators = [];

        if (($classFlags & Operator::CLASS_COMPARABLE) !== 0) {
            $operators = array_merge(
                $operators,
                Operator::getEqualityOperators()
            );
        }

        if (($classFlags & Operator::CLASS_ORDERABLE) !== 0) {
            $operators = array_merge(
                $operators,
                Operator::getOrderableOperators()
            );
        }

        if (($classFlags & Operator::CLASS_NULLABLE) !== 0) {
            $operators = array_merge(
                $operators,
                Operator::getNullableOperators()
            );
        }

        if (($classFlags & Operator::CLASS_LIKE) !== 0) {
            $operators = array_merge(
                $operators,
                Operator::getLikeOperators()
            );
        }

        if (($classFlags & Operator::CLASS_IN) !== 0) {
            $operators = array_merge(
                $operators,
                Operator::getInOperators()
            );
        }

        if (($classFlags & Operator::CLASS_IN_ARRAY) !== 0) {
            $operators = array_merge(
                $operators,
                Operator::getInArrayOperators()
            );
        }

        if (empty($operators) && ($classFlags & Operator::CLASS_JSONOBJECT) === 0) {
            throw new \DomainException('Invalid operator class flags');
        }

        return array_unique($operators);
    }
505116
protected function _emoticonCallback($matches) {
        $smiley = trim($matches[0]);

        if (count($matches) === 1 || !$this->hasSmiley($smiley)) {
            return $matches[0];
        }

        return $this->render($smiley, $this->getParser()->getConfig('xhtmlOutput'));
    }
536130
private function parseClass( $data, $matches, &$openBlocks )
	{
		$data['abstract']	= (bool) $matches[1];
		$data['final']		= (bool) $matches[2];
		$data['type']		= $matches[3];
		$data['name']		= $matches[4];
		$data['extends']	= isset( $matches[5] ) ? $matches[6] : NULL;
		if( isset( $matches[7] ) )
			foreach( array_slice( $matches, 8 ) as $match )
				if( trim( $match ) && !preg_match( "@^,|{@", trim( $match ) ) )
					$data['implements'][]	= trim( $match );
		if( $openBlocks )
			$this->overwriteCodeDataWithDocData( $data, array_pop( $openBlocks ) );
		return $data;
	}
552139
protected static function __match(array $patterns)
    {
        return function (...$args) use ($patterns) {
            $parameterTypes = array_map(self::getType(), $args);

            try {
                $keysToValues = Arrays::zip(array_keys($patterns), array_values($patterns));

                list($key, $matchingPattern) = Arrays::first(
                    Pattern::patternApplies($parameterTypes, $args),
                    $keysToValues
                );
            } catch (ElementNotFoundException $e) {
                throw new IncompletePatternMatchException(
                    'Incomplete pattern match expression. (missing ' . implode(', ', $parameterTypes) . ')'
                );
            }


            /**
             * Upcoming Feature, Array DSL for matching via `x::xs` etc.
             */
//            // if key is a string, manually match
//            if (is_string($key)) {
//
//                throw new \Exception('Array DSL not available.');
//            }

            list($hasExtractable, $unwrappedArgs) = self::unwrapArgs($args);

            $value = $matchingPattern(...$args);
            $isCallable = is_callable($value);

            if ($hasExtractable && ! $isCallable) {
                throw new InvalidPatternMatchException(
                    'Invalid pattern match expression. (one of ' . implode(', ', $parameterTypes)
                    . ' requires a callback to unwrap)'
                );
            }

            /**
             * Extractable requires a callback to feed args into.
             */
            if ($hasExtractable && $isCallable) {
                return $matchingPattern(...$args)(...$unwrappedArgs);
            }

            /**
             * No extractable so we can just return the value directly.
             */
            return $value;
        };
    }
1332912
public function convertLinkName(array $matches)
    {
        $replacedEmail = $this->linkNameConverter->convert(trim($matches[2]));

        return $matches[1] . $replacedEmail;
    }
967006
protected function getVariableValue(array $matches)
    {
        $res = $matches[0];
        $variable = substr($matches[0], 1, -1);

        if (isset($this->frontmatter[$variable])) {
            $res = $this->frontmatter[$variable];
        }

        return $res;
    }
323740
public function callbackReplace($matches)
    {
        if ($matches[1] !== '') {
            return $matches[0]; // don't modify existing <a href="">links</a> and <img src="">
        }
        $url = $matches[2];
        $urlWithPrefix = $matches[2];
        if (strpos($url, '@') !== false) {
            $urlWithPrefix = 'mailto:'.$url;
        } elseif (strpos($url, 'https://') === 0) {
            $urlWithPrefix = $url;
        } elseif (strpos($url, 'http://') !== 0) {
            $urlWithPrefix = 'http://'.$url;
        }

        return '<a href="'.$urlWithPrefix.'">'.$url.'</a>';
    }
645964
private static function getFirstAnnotationMatching(array $annotations, $annotationClass)
    {
        if (\is_string($annotationClass)) {
            $annotationClass = [$annotationClass];
        }

        foreach ($annotations as $annotation) {
            foreach ($annotationClass as $class) {
                if ($annotation instanceof $class) {
                    return $annotation;
                }
            }
        }

        return false;
    }
725249
protected function pregCallback($matches)
    {
        switch (mb_strtolower($matches[1])) {
            case 'p':
                // Replace newlines with spaces.
                $para = str_replace("\n", " ", $matches[3]);

                // Trim trailing and leading whitespace within the tag.
                $para = trim($para);

                // Add trailing newlines for this para.
                return "\n" . $para . "\n";
            case 'br':
                return "\n";
            case 'b':
            case 'strong':
                return $this->toupper($matches[3]);
            case 'th':
                return $this->toupper("\t\t" . $matches[3] . "\n");
            case 'h':
                return $this->toupper("\n\n" . $matches[3] . "\n\n");
            case 'a':
                // override the link method
                $linkOverride = null;
                if (preg_match('/_html2text_link_(\w+)/', $matches[4], $linkOverrideMatch)) {
                    $linkOverride = $linkOverrideMatch[1];
                }
                // Remove spaces in URL (#1487805)
                $url = str_replace(' ', '', $matches[3]);

                return $this->buildlinkList($url, $matches[5], $linkOverride);
        }

        return '';
    }
347882
protected static function getStringTypeArray($type, $string, array &$matches)
    {
        return [
            Tokenizer::TOKEN_TYPE => $type,
            Tokenizer::TOKEN_VALUE => \substr($string, 0, \strlen($matches[1])),
        ];
    }