<commit_before><?php declare(strict_types = 1);

namespace PHPStan\Reflection;

use PhpParser\Node\Stmt\Function_;
use PHPStan\Cache\Cache;
use PHPStan\Parser\FunctionCallStatementFinder;
use PHPStan\Parser\Parser;
use PHPStan\Reflection\Php\DummyParameter;
use PHPStan\Reflection\Php\PhpParameterReflection;
use PHPStan\Type\ArrayType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\MixedType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypehintHelper;

class FunctionReflection implements ParametersAcceptor
{

	/** @var \ReflectionFunction */
	private $reflection;

	/** @var \PHPStan\Parser\Parser */
	private $parser;

	/** @var \PHPStan\Parser\FunctionCallStatementFinder */
	private $functionCallStatementFinder;

	/** @var \PHPStan\Cache\Cache */
	private $cache;

	/** @var \PHPStan\Type\Type[] */
	private $phpDocParameterTypes;

	/** @var \PHPStan\Type\Type|null */
	private $phpDocReturnType;

	/** @var \PHPStan\Reflection\ParameterReflection[] */
	private $parameters;

	/** @var \PHPStan\Type\Type */
	private $returnType;

	public function __construct(
		\ReflectionFunction $reflection,
		Parser $parser,
		FunctionCallStatementFinder $functionCallStatementFinder,
		Cache $cache,
		array $phpDocParameterTypes,
		Type $phpDocReturnType = null
	)
	{
		$this->reflection = $reflection;
		$this->parser = $parser;
		$this->functionCallStatementFinder = $functionCallStatementFinder;
		$this->cache = $cache;
		$this->phpDocParameterTypes = $phpDocParameterTypes;
		$this->phpDocReturnType = $phpDocReturnType;
	}

	public function getNativeReflection(): \ReflectionFunction
	{
		return $this->reflection;
	}

	public function getName(): string
	{
		return $this->reflection->getName();
	}

	/**
	 * @return \PHPStan\Reflection\ParameterReflection[]
	 */
	public function getParameters(): array
	{
		if ($this->parameters === null) {
			$this->parameters = array_map(function (\ReflectionParameter $reflection) {
				return new PhpParameterReflection(
					$reflection,
					isset($this->phpDocParameterTypes[$reflection->getName()]) ? $this->phpDocParameterTypes[$reflection->getName()] : null
				);
			}, $this->reflection->getParameters());
			if (
				$this->reflection->getName() === 'array_unique'
				&& count($this->parameters) === 1
			) {
				// PHP bug #70960
				$this->parameters[] = new DummyParameter(
					'sort_flags',
					new IntegerType(),
					true
				);
			}
			if (
				$this->reflection->getName() === 'fputcsv'
				&& count($this->parameters) === 4
			) {
				$this->parameters[] = new DummyParameter(
					'escape_char',
					new StringType(),
					true
				);
			}
			if (
				$this->reflection->getName() === 'unpack'
				&& PHP_VERSION_ID >= 70101
			) {
				$this->parameters[2] = new DummyParameter(
					'offset',
					new IntegerType(),
					true
				);
			}
			if (
				$this->reflection->getName() === 'imagepng'
				&& count($this->parameters) === 2
			) {
				$this->parameters[] = new DummyParameter(
					'quality',
					new IntegerType(),
					true
				);
				$this->parameters[] = new DummyParameter(
					'filters',
					new IntegerType(),
					true
				);
			}

			if (
				$this->reflection->getName() === 'session_start'
				&& count($this->parameters) === 0
			) {
				$this->parameters[] = new DummyParameter(
					'options',
					new ArrayType(new MixedType()),
					true
				);
			}

			if ($this->reflection->getName() === 'locale_get_display_language') {
				$this->parameters[1] = new DummyParameter(
					'in_locale',
					new StringType(),
					true
				);
			}

			if (
				$this->reflection->getName() === 'imagewebp'
				&& count($this->parameters) === 2
			) {
				$this->parameters[] = new DummyParameter(
					'quality',
					new IntegerType(),
					true
				);
			}
		}

		return $this->parameters;
	}

	public function isVariadic(): bool
	{
		$isNativelyVariadic = $this->reflection->isVariadic();
		if (!$isNativelyVariadic && $this->reflection->getFileName() !== false) {
			$key = sprintf('variadic-function-%s-v0', $this->reflection->getName());
			$cachedResult = $this->cache->load($key);
			if ($cachedResult === null) {
				$nodes = $this->parser->parseFile($this->reflection->getFileName());
				$result = $this->callsFuncGetArgs($nodes);
				$this->cache->save($key, $result);
				return $result;
			}

			return $cachedResult;
		}

		return $isNativelyVariadic;
	}

	/**
	 * @param mixed $nodes
	 * @return bool<commit_msg>Fixed setproctitle<commit_after><?php declare(strict_types = 1);

namespace PHPStan\Reflection;

use PhpParser\Node\Stmt\Function_;
use PHPStan\Cache\Cache;
use PHPStan\Parser\FunctionCallStatementFinder;
use PHPStan\Parser\Parser;
use PHPStan\Reflection\Php\DummyParameter;
use PHPStan\Reflection\Php\PhpParameterReflection;
use PHPStan\Type\ArrayType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\MixedType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypehintHelper;

class FunctionReflection implements ParametersAcceptor
{

	/** @var \ReflectionFunction */
	private $reflection;

	/** @var \PHPStan\Parser\Parser */
	private $parser;

	/** @var \PHPStan\Parser\FunctionCallStatementFinder */
	private $functionCallStatementFinder;

	/** @var \PHPStan\Cache\Cache */
	private $cache;

	/** @var \PHPStan\Type\Type[] */
	private $phpDocParameterTypes;

	/** @var \PHPStan\Type\Type|null */
	private $phpDocReturnType;

	/** @var \PHPStan\Reflection\ParameterReflection[] */
	private $parameters;

	/** @var \PHPStan\Type\Type */
	private $returnType;

	public function __construct(
		\ReflectionFunction $reflection,
		Parser $parser,
		FunctionCallStatementFinder $functionCallStatementFinder,
		Cache $cache,
		array $phpDocParameterTypes,
		Type $phpDocReturnType = null
	)
	{
		$this->reflection = $reflection;
		$this->parser = $parser;
		$this->functionCallStatementFinder = $functionCallStatementFinder;
		$this->cache = $cache;
		$this->phpDocParameterTypes = $phpDocParameterTypes;
		$this->phpDocReturnType = $phpDocReturnType;
	}

	public function getNativeReflection(): \ReflectionFunction
	{
		return $this->reflection;
	}

	public function getName(): string
	{
		return $this->reflection->getName();
	}

	/**
	 * @return \PHPStan\Reflection\ParameterReflection[]
	 */
	public function getParameters(): array
	{
		if ($this->parameters === null) {
			$this->parameters = array_map(function (\ReflectionParameter $reflection) {
				return new PhpParameterReflection(
					$reflection,
					isset($this->phpDocParameterTypes[$reflection->getName()]) ? $this->phpDocParameterTypes[$reflection->getName()] : null
				);
			}, $this->reflection->getParameters());
			if (
				$this->reflection->getName() === 'array_unique'
				&& count($this->parameters) === 1
			) {
				// PHP bug #70960
				$this->parameters[] = new DummyParameter(
					'sort_flags',
					new IntegerType(),
					true
				);
			}
			if (
				$this->reflection->getName() === 'fputcsv'
				&& count($this->parameters) === 4
			) {
				$this->parameters[] = new DummyParameter(
					'escape_char',
					new StringType(),
					true
				);
			}
			if (
				$this->reflection->getName() === 'unpack'
				&& PHP_VERSION_ID >= 70101
			) {
				$this->parameters[2] = new DummyParameter(
					'offset',
					new IntegerType(),
					true
				);
			}
			if (
				$this->reflection->getName() === 'imagepng'
				&& count($this->parameters) === 2
			) {
				$this->parameters[] = new DummyParameter(
					'quality',
					new IntegerType(),
					true
				);
				$this->parameters[] = new DummyParameter(
					'filters',
					new IntegerType(),
					true
				);
			}

			if (
				$this->reflection->getName() === 'session_start'
				&& count($this->parameters) === 0
			) {
				$this->parameters[] = new DummyParameter(
					'options',
					new ArrayType(new MixedType()),
					true
				);
			}

			if ($this->reflection->getName() === 'locale_get_display_language') {
				$this->parameters[1] = new DummyParameter(
					'in_locale',
					new StringType(),
					true
				);
			}

			if (
				$this->reflection->getName() === 'imagewebp'
				&& count($this->parameters) === 2
			) {
				$this->parameters[] = new DummyParameter(
					'quality',
					new IntegerType(),
					true
				);
			}

			if (
				$this->reflection->getName() === 'setproctitle'
				&& count($this->parameters) === 0
			) {
				$this->parameters[] = new DummyParameter(
					'title',
					new StringType(),
					false
				);
			}
		}

		return $this->parameters;
	}

	public function isVariadic(): bool
	{
		$isNativelyVariadic = $this->reflection->isVariadic();
		if (!$isNativelyVariadic && $this->reflection->getFileName() !== false) {
			$key = sprintf('variadic-function-%s-v0', $this->reflection->getName());
			$cachedResult = $this->cache->load($key);
			if ($cachedResult === null) {
				$nodes = $this->parser->parseFile($this->reflection->getFileName());
				$result = $this->callsFuncGetArgs($nodes);
				$this->cache->save($key, $result);
				return $result;
			}

			return $cachedResult;
		}

		return $isNativelyVariadic;
	}

	/**
	 * @param mixed $nodes
	 * @return bool
{'fraction_non_alphanumeric': 0.16060705317174365, 'fraction_numerical': 0.004258106780216181, 'mean_word_length': 3.5078740157480315, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 129, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2961988', 'n_tokens_mistral': 3600, 'n_tokens_neox': 2895, 'n_words': 528}