<?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 DoesParamsExistsValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
if (!$value instanceof ValidationValueObject) {
throw new ConstraintDefinitionException(
'The Functions\DoesParamsExistsValidator subvalidator may only be used on '
. ' a ValidationValueObject containing a parameter key, a fqsen and an argument object'
);
}
$arguments = $value->arguments;
$parameters = $value->parameters;
if (count($arguments) > 0 && $parameters instanceof \ArrayAccess) {
foreach ($parameters as $param) {
$paramVarName = $param->getVariableName();
if (empty($paramVarName) || $arguments->offsetExists($paramVarName)) {
continue;
}
$this->context->addViolationAt(
'argument',
$constraint->message,
array($paramVarName, $value->fqsen),
null,
null,
$constraint->code
);
}
}
return null;
}
}