Skip to content

Commit 80456c7

Browse files
Move const to HashConfig
1 parent d5baa61 commit 80456c7

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

src/Charset.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/HashConfig.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
class HashConfig
88
{
9+
const CHARSET_UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
10+
const CHARSET_LOWERCASE = "abcdefghijklmnopqrstuvwxyz";
11+
const CHARSET_NUMERIC = "0123456789";
12+
913
protected $length;
1014

1115
protected $count = 1;
@@ -23,7 +27,7 @@ class HashConfig
2327
public function __construct($length = 16)
2428
{
2529
$this->length = $length;
26-
$this->charset = Charset::LOWERCASE->value . Charset::UPPERCASE->value . Charset::NUMERIC->value;
30+
$this->charset = self::CHARSET_LOWERCASE . self::CHARSET_UPPERCASE . self::CHARSET_NUMERIC;
2731
}
2832

2933
public static function make($length = 16)
@@ -70,21 +74,21 @@ public function charset(string $charset): self
7074

7175
public function upperCaseOnly(): self
7276
{
73-
$this->charset = Charset::UPPERCASE->value;
77+
$this->charset = self::CHARSET_UPPERCASE;
7478

7579
return $this;
7680
}
7781

7882
public function lowerCaseOnly(): self
7983
{
80-
$this->charset = Charset::LOWERCASE->value;
84+
$this->charset = self::CHARSET_LOWERCASE;
8185

8286
return $this;
8387
}
8488

8589
public function numbersOnly(): self
8690
{
87-
$this->charset = Charset::NUMERIC->value;
91+
$this->charset = self::CHARSET_NUMERIC;
8892

8993
return $this;
9094
}

tests/RandomHashTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Stfn\RandomHash\Tests;
44

55
use PHPUnit\Framework\TestCase;
6-
use Stfn\RandomHash\Charset;
76
use Stfn\RandomHash\InvalidConfigException;
87
use Stfn\RandomHash\RandomHash;
98
use Stfn\RandomHash\HashConfig;
@@ -124,7 +123,7 @@ public function test_if_it_can_generate_alphanumeric()
124123
{
125124
$config = new HashConfig();
126125
$config->length(10)
127-
->charset(Charset::UPPERCASE->value . Charset::LOWERCASE->value . Charset::NUMERIC->value);
126+
->charset(HashConfig::CHARSET_UPPERCASE . HashConfig::CHARSET_LOWERCASE . HashConfig::CHARSET_NUMERIC);
128127

129128
$instance = new RandomHash($config);
130129
$hash = $instance->generate();

0 commit comments

Comments
 (0)