/**
  * Validate metric type and default metric unit
  *
  * @param AttributeInterface|MetricInterface|ProductValueInterface $object
  * @param Constraint                                               $constraint
  */
 public function validate($object, Constraint $constraint)
 {
     if ($object instanceof AttributeInterface) {
         $familyProperty = 'metricFamily';
         $unitProperty = 'defaultMetricUnit';
     } elseif ($object instanceof MetricInterface && null !== $object->getData()) {
         $familyProperty = 'family';
         $unitProperty = 'unit';
     } elseif ($object instanceof ProductValueInterface && null !== $object->getMetric() && (null !== $object->getMetric()->getUnit() || null !== $object->getMetric()->getData())) {
         $object = $object->getMetric();
         $familyProperty = 'family';
         $unitProperty = 'unit';
     } else {
         return;
     }
     $family = $this->propertyAccessor->getValue($object, $familyProperty);
     $unit = $this->propertyAccessor->getValue($object, $unitProperty);
     if (!array_key_exists($family, $this->measures)) {
         $this->context->buildViolation($constraint->familyMessage)->atPath($familyProperty)->addViolation();
     } elseif (!array_key_exists($unit, $this->measures[$family]['units'])) {
         $this->context->buildViolation($constraint->unitMessage)->atPath($unitProperty)->addViolation();
     }
 }