Skip to content

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jul 16, 2024

extracted from #3126

factor out PrintfHelper for later re-use in a to be created PrintfArrayParametersRule

@staabm staabm marked this pull request as ready for review July 16, 2024 07:03
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

Comment on lines +21 to +29
public function getPrintfPlaceholdersCount(string $format): int
{
return $this->getPlaceholdersCount('(?:[bs%s]|l?[cdeEgfFGouxX])', $format);
}

public function getScanfPlaceholdersCount(string $format): int
{
return $this->getPlaceholdersCount('(?:[cdDeEfinosuxX%s]|\[[^\]]+\])', $format);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need this use-cases separated because I only need the getPrintfPlaceholdersCount in PrintfArrayParametersRule

}

$formatArgumentPosition = $functionsArgumentPositions[$name];
$functionReflection = $this->reflectionProvider->getFunction($node->name, $scope);
Copy link
Contributor Author

@staabm staabm Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was one of the few rules which did not validate the $node->name via ReflectionProvider.

I guess its not strictly necessary because we are handling php-src native functions - I added it for consistency.

@ondrejmirtes ondrejmirtes merged commit 14d0951 into phpstan:1.11.x Jul 16, 2024
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the printf-refac branch July 16, 2024 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants