Skip to content

Commit

Permalink
Feat: Create Mask.
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldbach07 committed Oct 25, 2021
1 parent e2faa61 commit bfe124a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
54 changes: 54 additions & 0 deletions Mask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace GoldbachAlgorithms;

class Mask
{
const CEP = '#####-###';

public function transform(
string $mask,
string $value
){
$value = $this->rewrite($mask, $value);

$maskared = '';

$k = 0;

for($i = 0; $i <= strlen($mask)-1; $i++) {
if($mask[$i] == '#') {
if(isset($value[$k])){
$maskared .= $value[$k++];
}
}
else
{
if(isset($mask[$i]))
{
$maskared .= $mask[$i];
}
}
}

return $maskared;

}

public function rewrite(
$mask,
$value
)
{
if($mask == self::CEP){
$value = str_replace('-','',$value);
return str_pad($value, 8, "0", STR_PAD_LEFT);
}
}

public function clear(
string $unmask
){
return $unmask;
}
}
18 changes: 18 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "goldbach-algorithms/mask",
"description": "Mascarador de valores PHP",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Goldbach07",
"email": "gustavoalves.a7@gmail.com"
}
],
"autoload": {
"psr-4":{
"GoldbachAlgorithms\\Mask\\": "src/"
}
},
"require": {}
}

0 comments on commit bfe124a

Please sign in to comment.