Find `preg_match()` which does not need regular expressions.

@param string $file File name to be analyzed.
@param Node   $node AST node to be analyzed.
@return Hint[] List of hints obtained from results.
774808
public function run(string $file, Node $node): array
    {
        if ($this->isFunctionCall($node, 'preg_match')) {
            $args = $node->children['args']->children;
            if (count($args) > 2) {
                return [];
            }

            if (is_string($args[0]) && $this->isUnneededRegExp($args[0])) {
                return [new Hint(
                    self::HINT_TYPE,
                    self::HINT_MESSAGE,
                    $file,
                    $node->lineno,
                    self::HINT_LINK
                )];
            }
        }

        return [];
    }
990425
private static function parse($file, $data)
    {
        $file = file_get_contents($file, FILE_USE_INCLUDE_PATH);

        // Go through each variable and replace the values
        foreach($data as $key => $value)
        {
            $pattern = '{{{' . $key . '}}}';
            $file = preg_replace($pattern, $value, $file);
        }

        if(!!$file)
        {
            return $file;
        }

        return false;
    }
644366
protected function _processMetrics($file, $node, $coverage)
    {
        $metrics = [
            'loc'      => 0,
            'nlloc'    => 0,
            'lloc'     => 0,
            'cloc'     => 0,
            'coverage' => 0
        ];
        if (!$coverage) {
            return $metrics;
        }
        for ($index = $node->lines['start']; $index <= $node->lines['stop']; $index++) {
            $metrics['loc'] = $this->_lineMetric('loc', $index, $metrics['loc']);
            if (!isset($coverage[$index])) {
                $metrics['nlloc'] = $this->_lineMetric('nlloc', $index, $metrics['nlloc']);
                continue;
            }
            $metrics['lloc'] = $this->_lineMetric('lloc', $index, $metrics['lloc']);
            if ($coverage[$index]) {
                $metrics['cloc'] = $this->_lineMetric('cloc', $index, $metrics['cloc']);
                $metrics['coverage'] = $this->_lineMetric('coverage', $index, $metrics['coverage'], $coverage[$index]);
            }
        }
        $metrics['files'][$file] = $file;
        return $this->_methodMetrics($node, $metrics);
    }
230000
public function find(&$file)
    {
        list($package, $file) = StringHelper::explode($this->separator, $file, 2, 'array_unshift');

        if (!$package) {
            return false;
        }

        $package = $this->packageResolver->getPackage($package);

        if (!$package) {
            return false;
        }

        return $package->getDir() . '/Templates';
    }
1300294
private function detectSeparator($file)
    {
        $matches = array(';', ',', '|', "\t");
        $handle = fopen($file, 'rb');
        if ($handle) {
            $minSeparator = $matches[0];
            if (($line = fgets($handle)) !== false) {
                $this->encoding = mb_detect_encoding($line);
                $line = mb_convert_encoding($line, "UTF-8", $this->encoding);
                $minOffset = strlen($line);
                foreach ($matches as $item) {
                    $i = strpos($line, $item);
                    if ($i !== false && $i < $minOffset) {
                        $minOffset = $i;
                        $minSeparator = $item;
                    }
                }
            }
            fclose($handle);
            return $minSeparator;
        }
        return $matches[0];
    }
695151
private function getGrpSettings($file, $tmaskgrp)
    {
        $matched = false;

        foreach ($tmaskgrp as $maskgrp) {
            $preg_maskgrp = "/" . $maskgrp["mask"] . "/";
            if (preg_match($preg_maskgrp, $file)) {
                $matched = $maskgrp;
            }
            if ($matched) {
                break;
            }
        }

        return $matched;
    }
821785
protected function _replaceVueAttrLinks($file, $str)
    {
        return preg_replace_callback("#(:(?:href|src|data-src|action)=\"')([\w-/:.]+)#", function ($match) use ($file) {
            return $match[1] . $this->_completeRelativeLinks($file, $match[2]);
        }, $str);
    }
313604
public function parse($input, $file = null)
    {
        $this->languageSpecifierLine = null;
        $this->input = $input;
        $this->file = $file;
        $this->tags = array();

        try {
            $this->lexer->analyse($this->input, 'en');
        } catch (LexerException $e) {
            throw new ParserException(
                sprintf('Lexer exception "%s" thrown for file %s', $e->getMessage(), $file),
                0,
                $e
            );
        }

        $feature = null;
        while ('EOS' !== ($predicted = $this->predictTokenType())) {
            $node = $this->parseExpression();

            if (null === $node || "\n" === $node) {
                continue;
            }

            if (!$feature && $node instanceof FeatureNode) {
                $feature = $node;
                continue;
            }

            if ($feature && $node instanceof FeatureNode) {
                throw new ParserException(sprintf(
                    'Only one feature is allowed per feature file. But %s got multiple.',
                    $this->file
                ));
            }

            if (is_string($node)) {
                throw new ParserException(sprintf(
                    'Expected Feature, but got text: "%s"%s',
                    $node,
                    $this->file ? ' in file: ' . $this->file : ''
                ));
            }

            if (!$node instanceof FeatureNode) {
                throw new ParserException(sprintf(
                    'Expected Feature, but got %s on line: %d%s',
                    $node->getKeyword(),
                    $node->getLine(),
                    $this->file ? ' in file: ' . $this->file : ''
                ));
            }
        }

        return $feature;
    }
418946
private function getNodeTypeAndPattern($pattern)
    {
        $node_type = 'text';

        // If user set payload, default, welcome message.
        foreach (['payload', 'default', 'attachment'] as $type) {
            if (strpos($pattern, $type . ':') !== false) {
                $node_type = $type;
                $pattern = str_replace($node_type . ':', '', $pattern);
            }
        }

        if (!empty($pattern) && $pattern[0] == '@') {
            $node_type = 'intended';
            $pattern = str_replace('@', '', $pattern);
        }

        return [$node_type, $pattern];
    }
806740
static public function getFileExt($file)
    {
        $s = strrchr($file, '.');
        if ($s === false)
        {
            return false;
        }
        return strtolower(trim(substr($s, 1)));
    }
247803
protected function find_nodes_after($node) {
        $return = array();
        $nodearray = $this->nodes;
        foreach ($nodearray as $nodeelement) {
            if ($nodeelement->after === $node->name) {
                // Find all nodes that comes after this node as well.
                $return = array_merge($return, array($nodeelement->name => $nodeelement), $this->find_nodes_after($nodeelement));
            }
        }
        return $return;
    }
951390
private function parseXml($file)
    {
        $formats = [];

        // load xml file
        $xmlDoc = $this->tryLoad($file);

        $this->xpath = new \DOMXPath($xmlDoc);
        $this->xpath->registerNamespace('x', static::XML_NAMESPACE_URI);

        foreach ($this->xpath->query('/x:formats/x:format') as $formatNode) {
            $this->addFormatFromFormatNode($formatNode, $formats);
        }

        return $formats;
    }
656409
function config($file) {
		preg_match_all(
			'/(?<=^|\n)(?:'.
				'\[(?<section>.+?)\]|'.
				'(?<lval>[^\h\r\n;].*?)\h*=\h*'.
				'(?<rval>(?:\\\\\h*\r?\n|.+?)*)'.
			')(?=\r?\n|$)/',
			$this->read($file),
			$matches,PREG_SET_ORDER);
		if ($matches) {
			$sec='globals';
			foreach ($matches as $match) {
				if ($match['section']) {
					$sec=$match['section'];
					if (preg_match('/^(?!(?:global|config|route|map|redirect)s\b)'.
						'((?:\.?\w)+)/i',$sec,$msec) && !$this->exists($msec[0]))
						$this->set($msec[0],NULL);
				}
				else {
					if (preg_match('/^(config|route|map|redirect)s\b/i',
						$sec,$cmd)) {
						call_user_func_array(
							array($this,$cmd[1]),
							array_merge(array($match['lval']),
								str_getcsv($match['rval'])));
					}
					else {
						$args=array_map(
							function($val) {
								if (is_numeric($val))
									return $val+0;
								$val=ltrim($val);
								if (preg_match('/^\w+$/i',$val) &&
									defined($val))
									return constant($val);
								return trim(preg_replace(
									array('/\\\\"/','/\\\\\h*(\r?\n)/'),
									array('"','\1'),$val));
							},
							// Mark quoted strings with 0x00 whitespace
							str_getcsv(preg_replace('/(?<!\\\\)(")(.*?)\1/',
								"\\1\x00\\2\\1",$match['rval']))
						);
						preg_match('/^(?<section>[^:]+)(?:\:(?<func>.+))?/',
							$sec,$parts);
						$func=isset($parts['func'])?$parts['func']:NULL;
						$custom=(strtolower($parts['section'])!='globals');
						if ($func)
							$args=array($this->call($func,
								count($args)>1?array($args):$args));
						call_user_func_array(
							array($this,'set'),
							array_merge(
								array(
									($custom?($parts['section'].'.'):'').
									$match['lval']
								),
								count($args)>1?array($args):$args
							)
						);
					}
				}
			}
		}
		return $this;
	}
291207
protected function findUseStatements(File $file)
    {
        if (array_key_exists($file->getFilename(), static::$useCache)) {
            return static::$useCache[$file->getFilename()];
        }

        $tokens = $file->getTokens();
        $usePosition = $file->findNext(T_USE, 0);
        $useStatements = [];

        while ($usePosition !== false) {
            if ($this->shouldIgnoreUse($file, $usePosition)) {
                $usePosition = $file->findNext(T_USE, $usePosition + 1);
                continue;
            }

            $fullPath = '';
            $lastString = '';
            $alias = '';

            $useEnd = $file->findNext(
                [T_SEMICOLON, T_COMMA],
                $usePosition
            );
            $useFullPathEnd = $file->findNext(
                [T_SEMICOLON, T_COMMA, T_WHITESPACE],
                $usePosition + 2
            );

            $afterUse = $file->findNext(
                [T_STRING, T_NS_SEPARATOR],
                $usePosition
            );

            while ($afterUse !== false) {
                $fullPath .= $tokens[$afterUse]['content'];

                if ($tokens[$afterUse]['code'] == T_STRING) {
                    $lastString = $tokens[$afterUse]['content'];
                }

                $afterUse = $file->findNext(
                    [T_STRING, T_NS_SEPARATOR],
                    $afterUse + 1,
                    $useFullPathEnd
                );
            }

            if ($useFullPathEnd != $useEnd) {
                if ($tokens[$useFullPathEnd + 1]['code'] !== T_AS) {
                    continue;
                }

                if ($tokens[$useFullPathEnd + 3]['code'] === T_STRING) {
                    $alias = $tokens[$useFullPathEnd + 3]['content'];
                }
            } else {
                $alias = $lastString;
            }

            $useStatements[$fullPath] = $alias;

            $usePosition = $file->findNext(T_USE, $usePosition + 1);
        }

        static::$useCache[$file->getFilename()] = $useStatements;

        return $useStatements;
    }
151928
public function load($file,$context)
	{
		$pattern='/(msgctxt\s+"(.*?(?<!\\\\))")?\s+'
			.'msgid\s+((?:".*(?<!\\\\)"\s*)+)\s+'
			.'msgstr\s+((?:".*(?<!\\\\)"\s*)+)/';
		$matches=array();
		$n=preg_match_all($pattern,file_get_contents($file),$matches);

		$messages=array();
		for($i=0; $i<$n; $i++)
		{
			if($matches[2][$i]===$context)
			{
				$id=$this->decode($matches[3][$i]);
				$message=$this->decode($matches[4][$i]);
				$messages[$id]=$message;
			}
		}
		return $messages;
	}
548674
private function matchByRegex(string $pattern, string $path): array
    {
        $isPatternMatched = (bool) \preg_match_all("~^$pattern$~", $path, $matches);

        if (!$isPatternMatched) {
            return [$isPatternMatched, []];
        }

        foreach ($matches as $k => $match) {
            $match = \array_shift($match);
            if (\is_int($k) || empty($match)) {
                unset($matches[$k]);
                continue;
            }
            $matches[$k] = $match;
        }

        return [$isPatternMatched, $matches];
    }
1221665
public function run(string $file, Node $node): array
    {
        while (count($node->children) >= 2) {
            $catch = array_shift($node->children);

            // If the class specification includes `Throwable`, doesn't allow any catch expressions after that.
            if ($this->isIncludeThrowableNode($catch)) {
                foreach ($node->children as $after_catch) {
                    if (!$this->isIncludeThrowableNode($after_catch)) {
                        return [new Hint(
                            self::HINT_TYPE,
                            self::HINT_MESSAGE,
                            $file,
                            $after_catch->lineno,
                            self::HINT_LINK
                        )];
                    }
                }
            }

            // If the class specification includes `Exception`, doesn't allow catch expressions other than `Throwable` after that.
            if ($this->isIncludeExceptionNode($catch)) {
                foreach ($node->children as $after_catch) {
                    if (!$this->isIncludeExceptionNode($after_catch)
                          && !$this->isIncludeThrowableNode($after_catch)) {
                        return [new Hint(
                            self::HINT_TYPE,
                            self::HINT_MESSAGE,
                            $file,
                            $after_catch->lineno,
                            self::HINT_LINK
                        )];
                    }
                }
            }
        }

        return [];
    }