Skip to content

Commit

Permalink
FunctionCallParametersCheck - more precise lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 18, 2020
1 parent ae458b0 commit ba119bc
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Rules/FunctionCallParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function check(
}

if ($hasNamedArguments && !$this->phpVersion->supportsNamedArguments()) {
$errors[] = RuleErrorBuilder::message('Named arguments are supported only on PHP 8.0 and later.')->nonIgnorable()->build();
$errors[] = RuleErrorBuilder::message('Named arguments are supported only on PHP 8.0 and later.')->line($funcCall->getLine())->nonIgnorable()->build();
}

if (!$hasNamedArguments) {
Expand All @@ -183,20 +183,20 @@ public function check(
$invokedParametersCount === 1 ? $messages[0] : $messages[1],
$invokedParametersCount,
$functionParametersMinCount
))->build();
))->line($funcCall->getLine())->build();
} elseif ($functionParametersMaxCount === -1 && $invokedParametersCount < $functionParametersMinCount) {
$errors[] = RuleErrorBuilder::message(sprintf(
$invokedParametersCount === 1 ? $messages[2] : $messages[3],
$invokedParametersCount,
$functionParametersMinCount
))->build();
))->line($funcCall->getLine())->build();
} elseif ($functionParametersMaxCount !== -1) {
$errors[] = RuleErrorBuilder::message(sprintf(
$invokedParametersCount === 1 ? $messages[4] : $messages[5],
$invokedParametersCount,
$functionParametersMinCount,
$functionParametersMaxCount
))->build();
))->line($funcCall->getLine())->build();
}
}
}
Expand All @@ -206,10 +206,10 @@ public function check(
&& !$scope->isInFirstLevelStatement()
&& !$funcCall instanceof \PhpParser\Node\Expr\New_
) {
$errors[] = RuleErrorBuilder::message($messages[7])->build();
$errors[] = RuleErrorBuilder::message($messages[7])->line($funcCall->getLine())->build();
}

[$addedErrors, $argumentsWithParameters] = $this->processArguments($parametersAcceptor, $isBuiltin, $arguments, $hasNamedArguments, $messages[10], $messages[11]);
[$addedErrors, $argumentsWithParameters] = $this->processArguments($parametersAcceptor, $funcCall->getLine(), $isBuiltin, $arguments, $hasNamedArguments, $messages[10], $messages[11]);
foreach ($addedErrors as $error) {
$errors[] = $error;
}
Expand Down Expand Up @@ -301,7 +301,7 @@ static function (Type $type): bool {
continue;
}

$errors[] = RuleErrorBuilder::message(sprintf($messages[9], $name))->build();
$errors[] = RuleErrorBuilder::message(sprintf($messages[9], $name))->line($funcCall->getLine())->build();
}
}

Expand All @@ -318,6 +318,7 @@ static function (Type $type): bool {
*/
private function processArguments(
ParametersAcceptor $parametersAcceptor,
int $line,
bool $isBuiltin,
array $arguments,
bool $hasNamedArguments,
Expand Down Expand Up @@ -405,7 +406,7 @@ private function processArguments(
continue;
}

$errors[] = RuleErrorBuilder::message(sprintf($missingParameterMessage, sprintf('%s (%s)', $parameter->getName(), $parameter->getType()->describe(VerbosityLevel::typeOnly()))))->build();
$errors[] = RuleErrorBuilder::message(sprintf($missingParameterMessage, sprintf('%s (%s)', $parameter->getName(), $parameter->getType()->describe(VerbosityLevel::typeOnly()))))->line($line)->build();
}
}

Expand Down

0 comments on commit ba119bc

Please sign in to comment.