/** * Checks if the passed value is valid. * * @param FileDescriptor|ClassDescriptor|InterfaceDescriptor|TraitDescriptor $value The value that should * be validated. * @param Constraint $constraint The constraint for * the validation. * * @throws ConstraintDefinitionException if this is not a constraint on a PropertyDescriptor object. */ public function validate($value, Constraint $constraint) { if (!$value instanceof FileDescriptor && !$value instanceof ClassDescriptor && !$value instanceof InterfaceDescriptor && !$value instanceof TraitDescriptor) { throw new ConstraintDefinitionException('The HasPackageWithSubpackageValidator validator may only be used on files, classes, ' . 'interfaces and traits'); } if ($value->getTags()->get('subpackage', new Collection())->count() > 0 && !$value->getPackage()) { $this->context->addViolationAt('package', $constraint->message); } }