public function doEnhancement(Lead $lead)
    {
        $result        = false;
        $leadAddress1  = $lead->getAddress1();
        $leadAddress2  = $lead->getAddress2();
        $leadZipCode   = $lead->getZipcode();
        $combined      = trim($leadAddress1).'|'.trim($leadAddress2).'|'.trim($leadZipCode);
        $leadCorrected = $lead->getFieldValue('address_valid');

        if (strlen($combined) < 6) {
            $this->getLogger()->debug(
                'Correct Address: Not enough address data to enhance contact '.$lead->getId()
            );
            // ENG-871 always update the field, even with false
            $lead->addUpdatedField('address_valid', $result, $leadCorrected);

            return $result;
        }

        if (isset($this->attempts[$combined])) {
            $this->getLogger()->debug('Correct Address: Already processed address on contact '.$lead->getId());

            return $result;
        }

        // ENG-871 only try if we havent already
        if (!is_null($leadCorrected)) {
            $this->getLogger()->debug('Correct Address: Already processed or validated contact '.$lead->getId());

            return $result;
        }

        $address = implode(
            '|',
            [
                $this->sanitizeAddressData($leadAddress1),
                $this->sanitizeAddressData($leadAddress2),
                $this->sanitizeAddressData($leadZipCode),
            ]
        );

        // Run the executable to correct the address.
        $this->attempts[$combined] = true;
        $corrected                 = $this->callCorrectA($address);
        if (!$corrected) {
            // Complete failure to parse address.
            $this->getLogger()->debug('Correct Address: Failure to parse address on contact '.$lead->getId());
            // ENG-871 always update the field, even with false
            $lead->addUpdatedField('address_valid', $result, $leadCorrected);

            return $result;
        }
        $this->getLogger()->debug('Correct Address: Raw value from Experian: "'.$corrected.'"');
        list($address1, $address2, $cityStZip, $code) = explode('|', $corrected);

        if (1 <= (int) $code) {
            $cityStZip = explode(' ', trim($cityStZip));
            $zipCode   = array_pop($cityStZip);
            $state     = array_pop($cityStZip);
            $city      = implode(' ', $cityStZip);
            $address1  = trim($address1);
            $address2  = trim($address2);
            $leadCity  = $lead->getCity();
            $leadState = $lead->getState();
            if (!empty($address1) && $address1 !== $leadAddress1) {
                $lead->setAddress1($address1);
                $lead->addUpdatedField('address1', $address1, $leadAddress1);
                $this->getLogger()->debug(
                    'Correct Address: Updated address1 to '.$address1.' for contact '.$lead->getId()
                );
                $result = true;
            }
            if (!empty($address2) && $address2 !== $leadAddress2) {
                $lead->setAddress2($address2);
                $lead->addUpdatedField('address2', $address2, $leadAddress2);
                $this->getLogger()->debug(
                    'Correct Address: Updated address2 to '.$address2.' for contact '.$lead->getId()
                );
                $result = true;
            }
            if (!empty($city) && $city !== $leadCity) {
                $lead->setCity($city);
                $lead->addUpdatedField('city', $city, $leadCity);
                $this->getLogger()->debug(
                    'Correct Address: Updated city to '.$city.' for contact '.$lead->getId()
                );
                $result = true;
            }
            if (!empty($state) && $state !== $leadState) {
                $lead->setState($state);
                $lead->addUpdatedField('state', $state, $leadState);
                $this->getLogger()->debug(
                    'Correct Address: Updated state to '.$state.' for contact '.$lead->getId()
                );
                $result = true;
            }
            if (!empty($zipCode) && $zipCode !== $leadZipCode) {
                $lead->setZipcode($zipCode);
                $lead->addUpdatedField('zipcode', $zipCode, $leadZipCode);
                $this->getLogger()->debug(
                    'Correct Address: Updated zipcode to '.$zipCode.' for contact '.$lead->getId()
                );
                $result = true;
            }
        } else {
            $this->getLogger()->debug('Correct Address: Could not discern accurate address, returned code '.$code);
        }
        // ENG-871 always update the field, even with false
        $lead->addUpdatedField('address_valid', $result, $leadCorrected);

        return $result;
    }
public function doEnhancement(Lead $lead)
    {
        $result        = false;
        $leadAddress1  = $lead->getAddress1();
        $leadAddress2  = $lead->getAddress2();
        $leadZipCode   = $lead->getZipcode();
        $combined      = trim($leadAddress1).'|'.trim($leadAddress2).'|'.trim($leadZipCode);
        $leadCorrected = $lead->getFieldValue('address_valid');

        if (strlen($combined) < 6) {
            $this->getLogger()->debug(
                'Correct Address: Not enough address data to enhance contact '.$lead->getId()
            );
            // ENG-871 always update the field, even with false
            $lead->addUpdatedField('address_valid', $result, $leadCorrected);

            return $result;
        }

        if (isset($this->attempts[$combined])) {
            $this->getLogger()->debug('Correct Address: Already processed address on contact '.$lead->getId());

            return $result;
        }

        // ENG-871 only try if we havent already
        if (!is_null($leadCorrected)) {
            $this->getLogger()->debug('Correct Address: Already processed or validated contact '.$lead->getId());

            return $result;
        }

        $address = implode(
            '|',
            [
                $this->sanitizeAddressData($leadAddress1),
                $this->sanitizeAddressData($leadAddress2),
                $this->sanitizeAddressData($leadZipCode),
            ]
        );

        // Run the executable to correct the address.
        $this->attempts[$combined] = true;
        $corrected                 = $this->callCorrectA($address);
        if (!$corrected) {
            // Complete failure to parse address.
            $this->getLogger()->debug('Correct Address: Failure to parse address on contact '.$lead->getId());
            // ENG-871 always update the field, even with false
            $lead->addUpdatedField('address_valid', $result, $leadCorrected);

            return $result;
        }
        $this->getLogger()->debug('Correct Address: Raw value from Experian: "'.$corrected.'"');
        list($address1, $address2, $cityStZip, $code) = explode('|', $corrected);

        if (1 <= (int) $code) {
            $cityStZip = explode(' ', trim($cityStZip));
            $zipCode   = array_pop($cityStZip);
            $state     = array_pop($cityStZip);
            $city      = implode(' ', $cityStZip);
            $address1  = trim($address1);
            $address2  = trim($address2);
            $leadCity  = $lead->getCity();
            $leadState = $lead->getState();
            if (!empty($address1) && $address1 !== $leadAddress1) {
                $lead->setAddress1($address1);
                $lead->addUpdatedField('address1', $address1, $leadAddress1);
                $this->getLogger()->debug(
                    'Correct Address: Updated address1 to '.$address1.' for contact '.$lead->getId()
                );
                $result = true;
            }
            if (!empty($address2) && $address2 !== $leadAddress2) {
                $lead->setAddress2($address2);
                $lead->addUpdatedField('address2', $address2, $leadAddress2);
                $this->getLogger()->debug(
                    'Correct Address: Updated address2 to '.$address2.' for contact '.$lead->getId()
                );
                $result = true;
            }
            if (!empty($city) && $city !== $leadCity) {
                $lead->setCity($city);
                $lead->addUpdatedField('city', $city, $leadCity);
                $this->getLogger()->debug(
                    'Correct Address: Updated city to '.$city.' for contact '.$lead->getId()
                );
                $result = true;
            }
            if (!empty($state) && $state !== $leadState) {
                $lead->setState($state);
                $lead->addUpdatedField('state', $state, $leadState);
                $this->getLogger()->debug(
                    'Correct Address: Updated state to '.$state.' for contact '.$lead->getId()
                );
                $result = true;
            }
            if (!empty($zipCode) && $zipCode !== $leadZipCode) {
                $lead->setZipcode($zipCode);
                $lead->addUpdatedField('zipcode', $zipCode, $leadZipCode);
                $this->getLogger()->debug(
                    'Correct Address: Updated zipcode to '.$zipCode.' for contact '.$lead->getId()
                );
                $result = true;
            }
        } else {
            $this->getLogger()->debug('Correct Address: Could not discern accurate address, returned code '.$code);
        }
        // ENG-871 always update the field, even with false
        $lead->addUpdatedField('address_valid', $result, $leadCorrected);

        return $result;
    }
@param Lead $lead

@return bool