Skip to content

Commit 4cf6c4a

Browse files
committed
remove no hash option
1 parent e5c912a commit 4cf6c4a

File tree

2 files changed

+4
-38
lines changed

2 files changed

+4
-38
lines changed

src/Hex.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@
66

77
class Hex implements Rule
88
{
9-
/**
10-
* @var bool
11-
*/
12-
protected $forceHash;
13-
149
/**
1510
* @var bool
1611
*/
1712
protected $forceFull;
1813

19-
public function __construct($forceHash = false, $forceFull = false)
14+
public function __construct($forceFull = false)
2015
{
21-
$this->forceHash = $forceHash;
2216
$this->forceFull = $forceFull;
2317
}
2418

@@ -32,13 +26,7 @@ public function __construct($forceHash = false, $forceFull = false)
3226
*/
3327
public function passes($attribute, $value)
3428
{
35-
$pattern = '/^#';
36-
37-
if (!$this->forceHash) {
38-
$pattern .= '?';
39-
}
40-
41-
$pattern .= '([a-fA-F0-9]{6}';
29+
$pattern = '/^#([a-fA-F0-9]{6}';
4230

4331
if (!$this->forceFull) {
4432
$pattern .= '|[a-fA-F0-9]{3}';

tests/Feature/HexTest.php

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,7 @@ public function six_characters_with_hash()
2626
$this->assertTrue($this->validator('#ff0080')->passes());
2727
$this->assertTrue($this->validator('#fg0080')->fails());
2828

29-
$this->assertTrue($this->validator('#ff0080', true)->passes()); // hash
30-
$this->assertTrue($this->validator('#ff0080', false, true)->passes()); // full
31-
}
32-
33-
/** @test */
34-
public function six_characters_without_hash()
35-
{
36-
$this->assertTrue($this->validator('ff0080')->passes());
37-
$this->assertTrue($this->validator('fg0080')->fails());
38-
39-
$this->assertTrue($this->validator('ff0080', true)->fails()); // hash
40-
$this->assertTrue($this->validator('ff0080', false, true)->passes()); // full
29+
$this->assertTrue($this->validator('#ff0080',true)->passes()); // full
4130
}
4231

4332
/** @test */
@@ -46,17 +35,6 @@ public function three_characters_with_hash()
4635
$this->assertTrue($this->validator('#fff')->passes());
4736
$this->assertTrue($this->validator('#ggg')->fails());
4837

49-
$this->assertTrue($this->validator('#fff', true)->passes()); // hash
50-
$this->assertTrue($this->validator('#fff', false, true)->fails()); // full
51-
}
52-
53-
/** @test */
54-
public function three_characters_without_hash()
55-
{
56-
$this->assertTrue($this->validator('fff')->passes());
57-
$this->assertTrue($this->validator('ggg')->fails());
58-
59-
$this->assertTrue($this->validator('fff', true)->fails()); // hash
60-
$this->assertTrue($this->validator('fff', false, true)->fails()); // full
38+
$this->assertTrue($this->validator('#fff', false)->passes()); // full
6139
}
6240
}

0 commit comments

Comments
 (0)