Skip to content

Commit

Permalink
[TASK] Small code cleanup
Browse files Browse the repository at this point in the history
to clarify which identificator length represents what type
  • Loading branch information
einpraegsam committed Oct 25, 2024
1 parent f8aa86f commit 80ab446
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Classes/Domain/Factory/VisitorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ protected function getIpAddress(): string

protected function checkIdentificator(string $identificator): void
{
$length = [0, 32, 33];
$length = [0, Fingerprint::IDENTIFICATOR_LENGTH_FINGERPRINT, Fingerprint::IDENTIFICATOR_LENGTH_STORAGE];
if (in_array(strlen($identificator), $length) === false) {
throw new IdentificatorFormatException('Identificator is in wrong format: ' . $identificator, 1680203759);
}
if (preg_replace('/[a-z0-9]{32,33}/', '', $identificator) !== '') {
if (preg_replace('/[a-z0-9]{' . Fingerprint::IDENTIFICATOR_LENGTH_FINGERPRINT . ',' . Fingerprint::IDENTIFICATOR_LENGTH_STORAGE . '}/', '', $identificator) !== '') {
throw new IdentificatorFormatException('Identificator is in wrong format: ' . $identificator, 1680204272);
}
}
Expand Down
5 changes: 4 additions & 1 deletion Classes/Domain/Model/Fingerprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Fingerprint extends AbstractModel
public const TYPE_FINGERPRINT = 0;
public const TYPE_COOKIE = 1;
public const TYPE_STORAGE = 2;
public const IDENTIFICATOR_LENGTH_FINGERPRINT = 32;
public const IDENTIFICATOR_LENGTH_STORAGE = 33;
public const IDENTIFICATOR_LENGTH_FINGERPRINTWITHIPHASH = 64;

protected string $value = '';
protected string $domain = '';
Expand Down Expand Up @@ -50,7 +53,7 @@ public function setValue(string $value): self
if ($value === '') {
throw new FingerprintMustNotBeEmptyException('Value is empty', 1585901797);
}
if (strlen($value) === 33) {
if (strlen($value) === self::IDENTIFICATOR_LENGTH_STORAGE) {
$this->setType(self::TYPE_STORAGE);
$this->value = $value;
} else {
Expand Down

0 comments on commit 80ab446

Please sign in to comment.