Skip to content

Commit

Permalink
More formatting
Browse files Browse the repository at this point in the history
I'm not sure how phpcbf didn't fix this already??
  • Loading branch information
shish committed Feb 11, 2025
1 parent 489a040 commit 05fa55d
Showing 1 changed file with 51 additions and 54 deletions.
105 changes: 51 additions & 54 deletions src/Type/Php/PregMatchTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,68 +21,65 @@
final class PregMatchTypeSpecifyingExtension implements FunctionTypeSpecifyingExtension, TypeSpecifierAwareExtension
{

private TypeSpecifier $typeSpecifier;
private TypeSpecifier $typeSpecifier;

public function __construct(
private RegexArrayShapeMatcher $regexShapeMatcher,
)
{
}
public function __construct(
private RegexArrayShapeMatcher $regexShapeMatcher,
) {
}

public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
{
$this->typeSpecifier = $typeSpecifier;
}
public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
{
$this->typeSpecifier = $typeSpecifier;
}

public function isFunctionSupported(FunctionReflection $functionReflection, FuncCall $node, TypeSpecifierContext $context): bool
{
return in_array(strtolower($functionReflection->getName()), ['safe\preg_match', 'safe\preg_match_all'], true) && !$context->null();
}
public function isFunctionSupported(FunctionReflection $functionReflection, FuncCall $node, TypeSpecifierContext $context): bool
{
return in_array(strtolower($functionReflection->getName()), ['safe\preg_match', 'safe\preg_match_all'], true) && !$context->null();
}

public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes
{
$args = $node->getArgs();
$patternArg = $args[0] ?? null;
$matchesArg = $args[2] ?? null;
$flagsArg = $args[3] ?? null;
public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes
{
$args = $node->getArgs();
$patternArg = $args[0] ?? null;
$matchesArg = $args[2] ?? null;
$flagsArg = $args[3] ?? null;

if (
$patternArg === null || $matchesArg === null
) {
return new SpecifiedTypes();
}
if ($patternArg === null || $matchesArg === null
) {
return new SpecifiedTypes();
}

$flagsType = null;
if ($flagsArg !== null) {
$flagsType = $scope->getType($flagsArg->value);
}
$flagsType = null;
if ($flagsArg !== null) {
$flagsType = $scope->getType($flagsArg->value);
}

if ($functionReflection->getName() === 'Safe\preg_match') {
$matchedType = $this->regexShapeMatcher->matchExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope);
} else {
$matchedType = $this->regexShapeMatcher->matchAllExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope);
}
if ($matchedType === null) {
return new SpecifiedTypes();
}
if ($functionReflection->getName() === 'Safe\preg_match') {
$matchedType = $this->regexShapeMatcher->matchExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope);
} else {
$matchedType = $this->regexShapeMatcher->matchAllExpr($patternArg->value, $flagsType, TrinaryLogic::createFromBoolean($context->true()), $scope);
}
if ($matchedType === null) {
return new SpecifiedTypes();
}

$overwrite = false;
if ($context->false()) {
$overwrite = true;
$context = $context->negate();
}
$overwrite = false;
if ($context->false()) {
$overwrite = true;
$context = $context->negate();
}

$types = $this->typeSpecifier->create(
$matchesArg->value,
$matchedType,
$context,
$scope,
)->setRootExpr($node);
if ($overwrite) {
$types = $types->setAlwaysOverwriteTypes();
}

return $types;
}
$types = $this->typeSpecifier->create(
$matchesArg->value,
$matchedType,
$context,
$scope,
)->setRootExpr($node);
if ($overwrite) {
$types = $types->setAlwaysOverwriteTypes();
}

return $types;
}
}

0 comments on commit 05fa55d

Please sign in to comment.