@param string $functionPattern
@param string $newParam
@param string $domainClassCode

@return string

@TODO BAD CODE! MUST BE RE-WRITTEN
541318
public function addActionParameter(string $actionName, string $newParam, string $domainClassCode): string
    {
        $functionPattern = '/public function[ \t\n\r]+' . $actionName . '[ \t\n\r]*\([ \t\r\n]*.*[ \t\r\n]*\)/';

        $class = preg_replace_callback(
            $functionPattern,
            function ($match) use ($newParam) {

                $matches = [];
                $params = [];
                $actionMethod = $match[0];

                $insideBracketsPattern = '/\([ \t\r\n]*.*[ \t\r\n]*\)/';

                preg_match($insideBracketsPattern, $actionMethod, $params);
                $paramsString = preg_replace('/\s+/', '', $params[0]);

                // Define params separator (void if the paramater to be added is the first parameter else ", " if the number of the parameters is greater then 0)
                $separator = ($paramsString == "()") ? "" : ", ";

                // Check if the parameter is already present inside the function
                $splittedParam = explode(" ", $newParam);
                $paramNameVal = (count($splittedParam) == 2) ? $splittedParam[1] : $splittedParam[0];
                $parameterName = (explode("=", $paramNameVal))[0];

                // If the parameter is not present... add it to the method!
                if (strpos($paramsString, $parameterName) == false) {

                    $lastBracketPattern = "/\)[ \r\n\t]*[^()]\$/";
                    preg_match($lastBracketPattern, $actionMethod . " ", $matches, PREG_OFFSET_CAPTURE);

                    if (count($matches) == 0) {
                        return $actionMethod;
                    }

                    return substr_replace($actionMethod, "{$separator}{$newParam})", $matches[0][1]);
                }

                throw new \Exception("Parameter already exists!");
            },
            (string)($domainClassCode)
        );

        $newParam = "* @var " . $newParam . "\n     * @SET\ActionEOA(\"$actionName\")";

        return str_replace("* @SET\ActionEOA(\"$actionName\")", $newParam, $class);
    }
930749
function handleRequest( $functionName, $params )
    {
        if ( array_key_exists( $functionName, $this->FunctionList ) )
        {
            $paramsOk = false;
            foreach( $this->FunctionList[$functionName] as $paramDesc )
            {
                $paramsOk = ( ( $paramDesc === null ) || $this->validateParams( $params, $paramDesc['in'] ) );
                if ( $paramsOk )
                {
                    break;
                }
            }
            if ( $paramsOk )
            {
                // allow to use the dot as namespace separator in webservices
                $functionName = str_replace( array( '.' ), '_', $functionName );

                try
                {
                    if ( strpos( $functionName, '::' ) )
                    {
                        return call_user_func_array( explode( '::', $functionName ), $params );
                    }
                    else
                    {
                        return call_user_func_array( $functionName, $params );
                    }
                }
                catch( Exception $e )
                {
                    switch ( $this->exception_handling )
                    {
                        case 0:
                            return new ggWebservicesFault( $e->getCode(), $e->getMessage() );
                        case 1:
                            return new ggWebservicesFault( self::GENERICRESPONSEERROR, self::GENERICRESPONSESTRING );
                        case 2:
                        default: // coder did something weird if we get someting else...
                            throw $e;
                    }
                }
            }
            else
            {
                return new ggWebservicesFault( self::INVALIDPARAMSERROR, self::INVALIDPARAMSSTRING );
            }
        }
        else
        {
            return new ggWebservicesFault( self::INVALIDMETHODERROR, self::INVALIDMETHODSTRING . " '$functionName'" );
        }
    }
1159650
private function matchDefaultMethod($callbacks, $url, $classUrl)
    {
        // match a callback based on url pattern
        $methodData = false;
        $matchedParameters = false;

        // match method
        foreach ($callbacks as $pattern => $data) {
            if ($data['default'] !== false && $data['resourceNaming'] === false) {
                // for default method we need to remove the method name from the pattern
                $methodUrl = $data['method'];
                if ($this->normalize) {
                    $methodUrl = PathTransformations::methodNameToUrl($methodUrl);
                }
                $pattern = $classUrl . '/' . str_replace($methodUrl . '/', '', $pattern);

                if (($matchedParameters = $this->doesPatternMatch($pattern, $data, $url)) !== false) {
                    $methodData = $data;
                    break;
                } else {
                    $methodName = $data['method'];
                    $data['method'] = $classUrl;
                    $matchedParameters = $this->tryMatchingOptionalParams($pattern, $data, $url);
                    $data['method'] = $methodName;
                    if ($matchedParameters) {
                        $methodData = $data;
                        break;
                    }
                }
            }
        }

        return [
            'methodData'        => $methodData,
            'matchedParameters' => $matchedParameters
        ];
    }
41397
private function isActionMethodAlreadyPresent(string $actionName, string $domainClassCode): bool
    {
        $functionPattern = '/public function[ \t\n\r]+' . $actionName . '[ \t\n\r]*\([ \t\r\n]*.*[ \t\r\n]*\)/';

        return preg_match($functionPattern, $domainClassCode) > 0 ? true : false;
    }
358387
public synchronized EventScope<T> register(final Class<? extends T> eventClass, final Object receiver,
			final Pattern namePattern) {

		final Method method = this.detectReceiverMethod(receiver, eventClass, namePattern);
		this.registerInternal(receiver, method, eventClass);
		return this;
	}
873800
private function assembleClassMap(TypeMap $typeMap, string $linefeed, string $indentation): string
    {
        $classMap = [];
        foreach ($typeMap->getTypes() as $type) {
            $classMap[] = sprintf(
                '%snew ClassMap(\'%s\', %s::class),',
                $indentation,
                $type->getXsdName(),
                'Type\\'.$type->getName()
            );
        }

        return implode($linefeed, $classMap);
    }
605762
public function setFtpPassword($domainName, $newPassword)
    {
        return $this->getSoapClient(array_merge(array($domainName, $newPassword), array('__method' => 'setFtpPassword')))->setFtpPassword($domainName, $newPassword);
    }
556020
private function createWithArguments(
        string $className,
        array $constructorArguments,
        &$implementationClassName = null
    ) {
        if (interface_exists($className)) {
            $className = $implementationClassName = $this->getClassForInterface($className);
        }
        if (!class_exists($className)) {
            throw ClassDoesNotExistException::exceptionWithClassName($className);
        }
        if ($constructorArguments) {
            $reflector = new ReflectionClass($className);

            return $reflector->newInstanceArgs($constructorArguments);
        }

        return new $className();
    }
1206768
public function addParameterToAction(
        string $domainName,
        string $actionName,
        string $paramName,
        string $type,
        string $defaultValue
    ): bool
    {
        $domainClassCode = $this->fileMan->loadDomainCode($domainName);

        if ($domainClassCode != null) {

            $this->addingParameterMsg($domainName, $actionName, $paramName);

            $type = strtolower($type);

            if ($defaultValue != "") {
                $this->cOut->write(sprintf(" Default value #RED#%s#DEF#", $defaultValue));

                if ($type == "string" || $type == "") {
                    $defaultValue = sprintf("'%s'", addslashes($defaultValue));
                }

                $defaultValue = "=" . $defaultValue;
            }

            $newParam = sprintf("%s \$%s%s", $type, $paramName, $defaultValue);

            $isParameterStored = $this->checkActionAndStoreParameter(
                $domainName,
                $actionName,
                $domainClassCode,
                $newParam
            );

            if ($isParameterStored) {
                $this->parameterAddedMsg($domainName);
                return true;
            }

            $this->actionNotFoundMsg($domainName, $actionName);
            return false;
        }

        $this->domainNotFoundMsg($domainName);
        return false;
    }
402697
public ResultSet getFunctions(String catalog, String schemaPattern,
                                  String functionNamePattern) throws SQLException {
        ResultSet rset;

        try {
            rset = mDataImpl.getFunctions(catalog, schemaPattern, functionNamePattern);
        } catch (SQLException sqlX) {
            FFDCFilter.processException(
                                        sqlX, getClass().getName() + ".getFunctions", "759", this);
            throw WSJdbcUtil.mapException(this, sqlX);
        } catch (NullPointerException nullX) {
            // No FFDC code needed; we might be closed.
            throw runtimeXIfNotClosed(nullX);
        } catch (AbstractMethodError methError) {
            // No FFDC code needed; wrong JDBC level.
            throw AdapterUtil.notSupportedX("DatabaseMetaData.getFunctions", methError);
        } catch (RuntimeException runX) {
            FFDCFilter.processException(
                                        runX, getClass().getName() + ".getFunctions", "942", this);
            if (tc.isDebugEnabled())
                Tr.debug(this, tc, "getFunctions", runX);
            throw runX;
        } catch (Error err) {
            FFDCFilter.processException(
                                        err, getClass().getName() + ".getFunctions", "949", this);
            if (tc.isDebugEnabled())
                Tr.debug(this, tc, "getFunctions", err);
            throw err;
        }

        rset = ((WSJdbcConnection) parentWrapper).createResultSetWrapper(rset, this);
        childWrappers.add(rset);
        return rset;
    }
1265893
public static function withErrorCodeAndParam($errorCode, $message, $parameter, $innerException = null)
	{
		$ex = XPath2Exception::withErrorCodeAndParams( $errorCode, $message, array( $parameter ), $innerException );
		// $ex->ErrorCode = $errorCode;
		return $ex;
	}
1074770
public static function create($function_name, $parameters = NULL) {
    /** @var FunctionDeclarationNode $function */
    $function = Parser::parseSnippet("function $function_name() {}");
    if (is_array($parameters)) {
      foreach ($parameters as $parameter) {
        if (is_string($parameter)) {
          $parameter = ParameterNode::create($parameter);
        }
        $function->appendParameter($parameter);
      }
    }
    return $function;
  }
106103
function createParams(routePattern, fragment, queryString) {
            var params = routePattern.exec(fragment).slice(1);

            for (var i = 0; i < params.length; i++) {
                var current = params[i];
                params[i] = current ? decodeURIComponent(current) : null;
            }

            var queryParams = router.parseQueryString(queryString);
            if (queryParams) {
                params.push(queryParams);
            }

            return {
                params:params,
                queryParams:queryParams
            };
        }
679613
protected function parseAnnotationPattern(string &$annotationPattern, array &$annotationPropertyConstraints): void
    {
        if (strpos($annotationPattern, '(') !== false) {
            $matches = [];
            preg_match(self::PATTERN_MATCHMETHODNAMEANDARGUMENTS, $annotationPattern, $matches);

            $annotationPattern = $matches['MethodName'];
            $annotationPropertiesPattern = $matches['MethodArguments'];
            $annotationPropertyConstraints = $this->getArgumentConstraintsFromMethodArgumentsPattern($annotationPropertiesPattern);
        }
    }
1342738
public static function /*@codingStandardsIgnoreStart*/__/*@codingStandardsIgnoreEnd*/($key, array $params = [], $domain = 'messages', $locale = null)
    {
        return new self($key, $params, $domain, $locale);
    }
283765
public static boolean call(PageContext pc, String type, Object value, Object objPattern) throws PageException {
	type = type.trim();

	if (!"regex".equalsIgnoreCase(type) && !"regular_expression".equalsIgnoreCase(type))
	    throw new FunctionException(pc, "isValid", 1, "type", "wrong attribute count for type [" + type + "]");

	return regex(Caster.toString(value, null), Caster.toString(objPattern));
    }
188208
public static function prepopulate_numchildren_cache($baseClass, $idList = null)
    {
        if (!Config::inst()->get(static::class, 'prepopulate_numchildren_cache')) {
            return;
        }

        /** @var Versioned|DataObject $singleton */
        $dummyObject = DataObject::singleton($baseClass);
        $baseTable = $dummyObject->baseTable();

        $idColumn = Convert::symbol2sql("{$baseTable}.ID");

        // Get the stageChildren() result of a dummy object and break down into a generic query
        $query = $dummyObject->stageChildren(true, true)->dataQuery()->query();

        // optional ID-list filter
        if ($idList) {
            // Validate the ID list
            foreach ($idList as $id) {
                if (!is_numeric($id)) {
                    user_error(
                        "Bad ID passed to Versioned::prepopulate_numchildren_cache() in \$idList: " . $id,
                        E_USER_ERROR
                    );
                }
            }
            $query->addWhere(['"ParentID" IN (' . DB::placeholders($idList) . ')' => $idList]);
        }

        $query->setOrderBy(null);

        $query->setSelect([
            '"ParentID"',
            "COUNT(DISTINCT $idColumn) AS \"NumChildren\"",
        ]);
        $query->setGroupBy([Convert::symbol2sql("ParentID")]);

        $numChildren = $query->execute()->map();
        self::$cache_numChildren[$baseClass]['numChildren'] = $numChildren;
        if (!$idList) {
            // If all objects are being cached, mark this cache as complete
            // to avoid counting children of childless object.
            self::$cache_numChildren[$baseClass]['numChildren']['_complete'] = true;
        }
    }