Created migration which parses existing IP addresses, generating hashes and droping already used IPs

This commit is contained in:
Alejandro Celaya
2018-09-13 23:50:09 +02:00
parent 7808f6d182
commit a01031303f
7 changed files with 169 additions and 24 deletions

View File

@@ -27,13 +27,13 @@ final class IpAddress
* @var string
*/
private $fourthOctet;
/**
* @var bool
*/
private $isLocalhost;
private function __construct()
private function __construct(string $firstOctet, string $secondOctet, string $thirdOctet, string $fourthOctet)
{
$this->firstOctet = $firstOctet;
$this->secondOctet = $secondOctet;
$this->thirdOctet = $thirdOctet;
$this->fourthOctet = $fourthOctet;
}
/**
@@ -49,17 +49,17 @@ final class IpAddress
throw WrongIpException::fromIpAddress($address);
}
$instance = new self();
$instance->isLocalhost = $address === self::LOCALHOST;
[$instance->firstOctet, $instance->secondOctet, $instance->thirdOctet, $instance->fourthOctet] = $parts;
return $instance;
return new self(...$parts);
}
public function getObfuscatedCopy(): self
{
$copy = clone $this;
$copy->fourthOctet = $this->isLocalhost ? $this->fourthOctet : self::OBFUSCATED_OCTET;
return $copy;
return new self(
$this->firstOctet,
$this->secondOctet,
$this->thirdOctet,
self::OBFUSCATED_OCTET
);
}
public function __toString(): string