Skip to content

Commit

Permalink
Merge pull request #20 from daveearley/more-php7.4-updates
Browse files Browse the repository at this point in the history
php 7.4 updates
  • Loading branch information
daveearley authored Jun 2, 2020
2 parents 6383ec9 + 36fff39 commit 6fbc67e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/EmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getValidationResults(): ValidationResults
return $this->validationResults;
}

public function runValidation()
public function runValidation(): void
{
foreach ($this->registeredValidators as $validator) {
$this->validationResults->addResult($validator->getValidatorName(), $validator->getResultResponse());
Expand Down
2 changes: 1 addition & 1 deletion src/EmailValidatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class EmailValidatorFactory
{
/** @var Validator[] */
private static array $defaultValidators = [
protected static array $defaultValidators = [
ValidFormatValidator::class,
MxRecordsValidator::class,
MisspelledEmailValidator::class,
Expand Down
16 changes: 2 additions & 14 deletions src/Validations/MisspelledEmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@
*/
class MisspelledEmailValidator extends Validator implements ValidatorInterface
{
const MINIMUM_WORD_DISTANCE_DOMAIN = 2;
const MINIMUM_WORD_DISTANCE_TLD = 1;
private const MINIMUM_WORD_DISTANCE_DOMAIN = 2;
private const MINIMUM_WORD_DISTANCE_TLD = 1;

/**
* @return string
*/
public function getValidatorName(): string
{
return 'possible_email_correction'; // @codeCoverageIgnore
}

/**
* @return string
*/
public function getResultResponse(): string
{
if (!$this->getEmailAddress()->isValidEmailAddressFormat()) {
Expand Down Expand Up @@ -76,12 +70,6 @@ private function findDomainSuggestion()
return $domain === $possibleMatch ? null : $possibleMatch;
}

/**
* @param string $stringToCheck
* @param array $wordsToCheck
* @param int $minimumDistance
* @return string|bool
*/
private function findClosestWord(string $stringToCheck, array $wordsToCheck, int $minimumDistance): string
{
if (in_array($stringToCheck, $wordsToCheck)) {
Expand Down
28 changes: 4 additions & 24 deletions src/Validations/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,33 @@

abstract class Validator
{
/** @var EmailAddress */
private $emailAddress;
private ?EmailAddress $emailAddress;

/** @var EmailDataProvider|null */
private $emailDataProvider;
private ?EmailDataProvider $emailDataProvider;

/**
* @param EmailAddress $emailAddress
* @param EmailDataProviderInterface $emailDataProvider
*/
public function __construct(EmailAddress $emailAddress = null, EmailDataProviderInterface $emailDataProvider = null)
{
$this->emailAddress = $emailAddress;
$this->emailDataProvider = $emailDataProvider;
}

/**
* @return EmailAddress
*/
public function getEmailAddress(): EmailAddress
{
return $this->emailAddress;
}

/**
* @param EmailAddress $emailAddress
* @return $this
*/
public function setEmailAddress(EmailAddress $emailAddress)
public function setEmailAddress(EmailAddress $emailAddress): Validator
{
$this->emailAddress = $emailAddress;
return $this;
}

/**
* @return EmailDataProviderInterface
*/
public function getEmailDataProvider(): EmailDataProviderInterface
{
return $this->emailDataProvider;
}

/**
* @param EmailDataProviderInterface|null $emailDataProvider
* @return $this
*/
public function setEmailDataProvider(EmailDataProviderInterface $emailDataProvider)
public function setEmailDataProvider(EmailDataProviderInterface $emailDataProvider): Validator
{
$this->emailDataProvider = $emailDataProvider;
return $this;
Expand Down

0 comments on commit 6fbc67e

Please sign in to comment.