Skip to content

Commit

Permalink
Troy Credit Card Class(#8)
Browse files Browse the repository at this point in the history
Added regex class to detect Troy Credit Cards.
  • Loading branch information
yordadev authored Aug 25, 2022
1 parent 0143769 commit e7a8cb3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
23 changes: 23 additions & 0 deletions src/RegexCollection/TroyCreditCard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace YorCreative\Scrubber\RegexCollection;

use YorCreative\Scrubber\Interfaces\RegexCollectionInterface;

class TroyCreditCard implements RegexCollectionInterface
{
public function getPattern(): string
{
return '9792\d{12}';
}

public function getTestableString(): string
{
return '9792020000300001';
}

public function isSecret(): bool
{
return false;
}
}
38 changes: 19 additions & 19 deletions src/Repositories/RegexRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ public function __construct()
$this->loadRegexClasses();
}

/**
* @return Collection
*/
public function getRegexCollection(): Collection
{
return $this->regexCollection;
}

protected function loadRegexClasses(): void
{
/**
Expand Down Expand Up @@ -69,17 +61,6 @@ protected function loadRegexClasses(): void
}
}

/**
* @param string $regex
* @param string $content
* @param int $hits
* @return string
*/
public static function checkAndSanitize(string $regex, string $content, int &$hits = 0): string
{
return preg_replace("~$regex~i", config('scrubber.redaction'), $content, -1, $hits);
}

protected static function generateRegexClassForSecret(Secret $secret)
{
$class = new class implements RegexCollectionInterface
Expand Down Expand Up @@ -111,4 +92,23 @@ public function setPattern(string $encryptedSecret)

return $class;
}

/**
* @param string $regex
* @param string $content
* @param int $hits
* @return string
*/
public static function checkAndSanitize(string $regex, string $content, int &$hits = 0): string
{
return preg_replace("~$regex~i", config('scrubber.redaction'), $content, -1, $hits);
}

/**
* @return Collection
*/
public function getRegexCollection(): Collection
{
return $this->regexCollection;
}
}

0 comments on commit e7a8cb3

Please sign in to comment.