Skip to content

Commit 44d28cf

Browse files
test: add fixture suite and expand architecture tests
1 parent ac2d2fe commit 44d28cf

13 files changed

Lines changed: 116 additions & 30 deletions

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ parameters:
66
paths:
77
- src
88
- config
9-
- database
109
tmpDir: build/phpstan

src/EmailFixer.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
use PlinCode\LaravelEmailFixer\Locale\ItalianPreset;
2020
use PlinCode\LaravelEmailFixer\Support\FixReport;
2121

22-
class EmailFixer
22+
final class EmailFixer
2323
{
2424
/** @var array<string, class-string<LocalePreset>> */
2525
private static array $presets = [
2626
'it' => ItalianPreset::class,
2727
];
2828

2929
/**
30-
* @param FixerInterface[] $fixers
31-
* @param array<string, string> $domainMap
32-
* @param array<string, mixed> $garbageConfig
33-
* @param (callable(string): bool)|null $validator
30+
* @param FixerInterface[] $fixers
31+
* @param array<string, string> $domainMap
32+
* @param array<string, mixed> $garbageConfig
33+
* @param (callable(string): bool)|null $validator
3434
*/
3535
public function __construct(
3636
private array $fixers,
@@ -112,7 +112,7 @@ public function fixMany(array $emails): array
112112
return array_map(fn (string $email) => $this->diagnose($email), $emails);
113113
}
114114

115-
public function locale(string $locale): static
115+
public function locale(string $locale): self
116116
{
117117
$presetClass = self::$presets[$locale] ?? null;
118118

@@ -144,20 +144,20 @@ public function locale(string $locale): static
144144

145145
array_splice($fixers, $insertIndex, 0, $preset->fixers());
146146

147-
return new static($fixers, $mergedMap, $this->garbageConfig, $this->validator);
147+
return new self($fixers, $mergedMap, $this->garbageConfig, $this->validator);
148148
}
149149

150150
/**
151-
* @param array<string, string> $domainMap
152-
* @param array<string, mixed> $garbageConfig
153-
* @param (callable(string): bool)|null $validator
151+
* @param array<string, string> $domainMap
152+
* @param array<string, mixed> $garbageConfig
153+
* @param (callable(string): bool)|null $validator
154154
*/
155155
public static function defaults(
156156
array $domainMap = [],
157157
array $garbageConfig = [],
158158
?callable $validator = null,
159-
): static {
160-
return new static(
159+
): self {
160+
return new self(
161161
fixers: self::defaultFixers($domainMap),
162162
domainMap: $domainMap,
163163
garbageConfig: $garbageConfig,

src/Fixers/CleanLocalPart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function fix(string $email): string
1515

1616
$local = rtrim(substr($email, 0, $atPos), '.');
1717

18-
return $local . substr($email, $atPos);
18+
return $local.substr($email, $atPos);
1919
}
2020

2121
public function name(): string

src/Fixers/CompleteDomain.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PlinCode\LaravelEmailFixer\Contracts\DomainAwareFixer;
66

7-
class CompleteDomain implements DomainAwareFixer
7+
final class CompleteDomain implements DomainAwareFixer
88
{
99
/** @param array<string, string> $domainMap */
1010
public function __construct(private array $domainMap) {}
@@ -20,7 +20,7 @@ public function fix(string $email): string
2020
$domain = substr($email, $atPos + 1);
2121

2222
if (isset($this->domainMap[$domain])) {
23-
return $local . '@' . $this->domainMap[$domain];
23+
return $local.'@'.$this->domainMap[$domain];
2424
}
2525

2626
return $email;
@@ -33,6 +33,6 @@ public function name(): string
3333

3434
public function withDomainMap(array $domainMap): static
3535
{
36-
return new static($domainMap);
36+
return new self($domainMap);
3737
}
3838
}

src/Fixers/FixDomainSeparator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PlinCode\LaravelEmailFixer\Contracts\DomainAwareFixer;
66

7-
class FixDomainSeparator implements DomainAwareFixer
7+
final class FixDomainSeparator implements DomainAwareFixer
88
{
99
/** @param array<string, string> $domainMap */
1010
public function __construct(private array $domainMap) {}
@@ -23,7 +23,7 @@ public function fix(string $email): string
2323
foreach ($this->domainMap as $fullDomain) {
2424
$normalizedKnown = str_replace(['.', '-'], '', strtolower($fullDomain));
2525
if ($normalized === $normalizedKnown) {
26-
return $local . '@' . $fullDomain;
26+
return $local.'@'.$fullDomain;
2727
}
2828
}
2929

@@ -37,6 +37,6 @@ public function name(): string
3737

3838
public function withDomainMap(array $domainMap): static
3939
{
40-
return new static($domainMap);
40+
return new self($domainMap);
4141
}
4242
}

src/Fixers/InsertMissingAt.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PlinCode\LaravelEmailFixer\Contracts\DomainAwareFixer;
66

7-
class InsertMissingAt implements DomainAwareFixer
7+
final class InsertMissingAt implements DomainAwareFixer
88
{
99
/** @param array<string, string> $domainMap */
1010
public function __construct(private array $domainMap) {}
@@ -22,8 +22,8 @@ public function fix(string $email): string
2222
foreach ($fullDomains as $domain) {
2323
if (str_ends_with($email, $domain)) {
2424
$local = substr($email, 0, -strlen($domain));
25-
if ($local !== '' && $local !== false) {
26-
return $local . '@' . $domain;
25+
if ($local !== '') {
26+
return $local.'@'.$domain;
2727
}
2828
}
2929
}
@@ -35,8 +35,8 @@ public function fix(string $email): string
3535
foreach ($keys as $key) {
3636
if (str_ends_with($email, $key)) {
3737
$local = substr($email, 0, -strlen($key));
38-
if ($local !== '' && $local !== false) {
39-
return $local . '@' . $this->domainMap[$key];
38+
if ($local !== '') {
39+
return $local.'@'.$this->domainMap[$key];
4040
}
4141
}
4242
}
@@ -51,6 +51,6 @@ public function name(): string
5151

5252
public function withDomainMap(array $domainMap): static
5353
{
54-
return new static($domainMap);
54+
return new self($domainMap);
5555
}
5656
}

src/Fixers/ItalianKeyboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function fix(string $email): string
1313
return $email;
1414
}
1515

16-
return mb_substr($email, 0, $pos) . '@' . mb_substr($email, $pos + 1);
16+
return mb_substr($email, 0, $pos).'@'.mb_substr($email, $pos + 1);
1717
}
1818

1919
public function name(): string

src/Rules/SanitizedEmail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
3030

3131
$fixed = $fixer->fix($value);
3232

33-
request()?->merge([$attribute => $fixed]);
33+
request()->merge([$attribute => $fixed]);
3434

3535
$emailRule = $this->strict ? 'email:rfc' : 'email';
3636
$validator = validator([$attribute => $fixed], [$attribute => $emailRule]);

src/Support/FixReport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class FixReport
66
{
77
/**
8-
* @param string[] $appliedFixers
8+
* @param string[] $appliedFixers
99
*/
1010
public function __construct(
1111
public readonly string $original,

tests/ArchTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,27 @@
33
arch('it will not use debugging functions')
44
->expect(['dd', 'dump', 'ray'])
55
->each->not->toBeUsed();
6+
7+
arch('core classes do not depend on Laravel')
8+
->expect('PlinCode\LaravelEmailFixer\Contracts')
9+
->not->toUse('Illuminate');
10+
11+
arch('fixers do not depend on Laravel')
12+
->expect('PlinCode\LaravelEmailFixer\Fixers')
13+
->not->toUse('Illuminate');
14+
15+
arch('support classes do not depend on Laravel')
16+
->expect('PlinCode\LaravelEmailFixer\Support')
17+
->not->toUse('Illuminate');
18+
19+
arch('locale presets do not depend on Laravel')
20+
->expect('PlinCode\LaravelEmailFixer\Locale')
21+
->not->toUse('Illuminate');
22+
23+
arch('EmailFixer core does not depend on Laravel')
24+
->expect('PlinCode\LaravelEmailFixer\EmailFixer')
25+
->not->toUse('Illuminate');
26+
27+
arch('all fixers implement FixerInterface')
28+
->expect('PlinCode\LaravelEmailFixer\Fixers')
29+
->toImplement('PlinCode\LaravelEmailFixer\Contracts\FixerInterface');

0 commit comments

Comments
 (0)