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

namespace PHPStan\Rules\Classes;

use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;

class UnusedConstructorParametersRule implements \PHPStan\Rules\Rule
{

	public function getNodeType(): string
	{
		return ClassMethod::class;
	}

	/**
	 * @param \PhpParser\Node\Stmt\ClassMethod $node
	 * @param \PHPStan\Analyser\Scope $scope
	 * @return string[]
	 */
	public function processNode(Node $node, Scope $scope): array
	{
		if ($node->name !== '__construct' || $node->stmts === null) {
			return [];
		}

		$unusedParameters = [];
		foreach ($node->params as $parameter) {
			$unusedParameters[$parameter->name] = true;
		}
		foreach ($this->getUsedVariables($node) as $variableName) {
			if (isset($unusedParameters[$variableName])) {
				unset($unusedParameters[$variableName]);
			}
		}

		$errors = [];
		if ($scope->getClass() !== null) {
			$message = sprintf('Constructor of class %s has an unused parameter $%%s.', $scope->getClass());
		} else {
			$message = 'Constructor of an anonymous class has an unused parameter $%s.';
		}
		foreach ($unusedParameters as $name => $bool) {
			$errors[] = sprintf($message, $name);
		}
<commit_msg>Unused constructors parameters - optimization for zero parameters<commit_after><?php declare(strict_types = 1);

namespace PHPStan\Rules\Classes;

use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;

class UnusedConstructorParametersRule implements \PHPStan\Rules\Rule
{

	public function getNodeType(): string
	{
		return ClassMethod::class;
	}

	/**
	 * @param \PhpParser\Node\Stmt\ClassMethod $node
	 * @param \PHPStan\Analyser\Scope $scope
	 * @return string[]
	 */
	public function processNode(Node $node, Scope $scope): array
	{
		if ($node->name !== '__construct' || $node->stmts === null) {
			return [];
		}

		if (count($node->params) === 0) {
			return [];
		}

		$unusedParameters = [];
		foreach ($node->params as $parameter) {
			$unusedParameters[$parameter->name] = true;
		}
		foreach ($this->getUsedVariables($node->stmts) as $variableName) {
			if (isset($unusedParameters[$variableName])) {
				unset($unusedParameters[$variableName]);
			}
		}

		$errors = [];
		if ($scope->getClass() !== null) {
			$message = sprintf('Constructor of class %s has an unused parameter $%%s.', $scope->getClass());
		} else {
			$message = 'Constructor of an anonymous class has an unused parameter $%s.';
		}
		foreach ($unusedParameters as $name => $bool) {
			$errors[] = sprintf($message, $name);
		}

{'fraction_non_alphanumeric': 0.16108949416342414, 'fraction_numerical': 0.0011673151750972762, 'mean_word_length': 4.236252545824847, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '6267242', 'n_tokens_mistral': 883, 'n_tokens_neox': 814, 'n_words': 192}