/**
  * Validates the provided field values.
  *
  * @param array                  $values        The field values, keyed by field constants.
  * @param AddressFormatInterface $addressFormat The address format.
  * @param Constraint             $constraint    The constraint.
  */
 protected function validateFields($values, AddressFormatInterface $addressFormat, $constraint)
 {
     // Validate the presence of required fields.
     $requiredFields = $addressFormat->getRequiredFields();
     foreach ($requiredFields as $field) {
         if (empty($values[$field]) && in_array($field, $constraint->fields)) {
             $this->addViolation($field, $constraint->notBlankMessage, $values[$field]);
         }
     }
     // Validate the absence of unused fields.
     $unusedFields = array_diff(AddressField::getAll(), $addressFormat->getUsedFields());
     foreach ($unusedFields as $field) {
         if (!empty($values[$field]) && in_array($field, $constraint->fields)) {
             $this->addViolation($field, $constraint->blankMessage, $values[$field]);
         }
     }
 }
 /**
  * Builds the view for the given address.
  *
  * @param AddressInterface       $address       The address.
  * @param AddressFormatInterface $addressFormat The address format.
  *
  * @return array The view.
  */
 protected function buildView(AddressInterface $address, AddressFormatInterface $addressFormat)
 {
     $countries = $this->countryRepository->getList($this->locale);
     $values = $this->getValues($address);
     $view = [];
     $view['country'] = ['html_tag' => 'span', 'html_attributes' => ['class' => 'country'], 'value' => $countries[$address->getCountryCode()]];
     foreach ($addressFormat->getUsedFields() as $field) {
         // The constant is more suitable as a class than the value since
         // it's snake_case and not camelCase.
         $class = str_replace('_', '-', strtolower(AddressField::getKey($field)));
         $view[$field] = ['html_tag' => 'span', 'html_attributes' => ['class' => $class], 'value' => $values[$field]];
     }
     return $view;
 }