<?php
namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
use phpDocumentor\Descriptor\MethodDescriptor;
use phpDocumentor\Descriptor\FunctionDescriptor;
use phpDocumentor\Descriptor\Tag\ParamDescriptor;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
use phpDocumentor\Plugin\Core\Descriptor\Validator\ValidationValueObject;
class DoesArgumentNameMatchParamValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
if (!$value instanceof ValidationValueObject) {
throw new ConstraintDefinitionException(
'The Functions\DoesArgumentNameMatchParam subvalidator may only be used on '
. ' an ValidationValueObject containing a parameter key, a fqsen and an argument object'
);
}
if (empty($value->parameter) || empty($value->argument)) {
return null;
}
$parameterName = $value->parameter->getVariableName();
$argumentName = $value->argument->getName();
if ($parameterName == $argumentName) {
return null;
}
if ($parameterName == '') {
$value->parameter->setVariableName($argumentName);
return null;
}
$violation = $this->context->addViolationAt(
'argument',
$constraint->message,
array($argumentName, $parameterName, $value->fqsen),
null,
null,
$constraint->code
);
}
}