Skip to content

Commit d8048e2

Browse files
authored
Refactor domain validation logic in ValidateDomainSniff, fixes #76
1 parent 060b336 commit d8048e2

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

WPForms/Sniffs/PHP/ValidateDomainSniff.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,20 @@ public function process( File $phpcsFile, $stackPtr ) {
113113
return;
114114
}
115115

116-
if ( ! $currentDomain || ! $expectedDomain ) {
116+
if ( ! $currentDomain ) {
117+
$phpcsFile->addError(
118+
sprintf(
119+
"Domain name is not set. You should be using '%s'.",
120+
$expectedDomain
121+
),
122+
$stackPtr,
123+
'InvalidDomain'
124+
);
125+
126+
return;
127+
}
128+
129+
if ( ! $expectedDomain ) {
117130
return;
118131
}
119132

WPForms/Tests/TestFiles/PHP/ValidateDomain.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
_nx( 'Invalid', 'Invalid', 10, 'Invalid', 'wpforms' );
3131

3232

33-
// Valid syntax when the text domain is not specified.
34-
esc_html__( 'Valid' );
33+
// Invalid syntax when the text domain is not specified.
34+
esc_html__( 'Invalid' );
3535

3636
// Invalid - not a string as the last argument.
3737
$bulk_counts['read'] = 25;

WPForms/Tests/Tests/PHP/ValidateDomainTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testProcess() {
2121

2222
$phpcsFile = $this->process( new ValidateDomainSniff() );
2323

24-
$this->fileHasErrors( $phpcsFile, 'InvalidDomain', [ 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 41 ] );
24+
$this->fileHasErrors( $phpcsFile, 'InvalidDomain', [ 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 34, 41 ] );
2525
$this->fileHasErrors( $phpcsFile, 'NotStringDomain', [ 38 ] );
2626
}
2727

@@ -34,7 +34,7 @@ public function testProcessWithMultiDomains() {
3434

3535
$phpcsFile = $this->process( new ValidateDomainSniff(), 'MultiDomains' );
3636

37-
$this->fileHasErrors( $phpcsFile, 'InvalidDomain', [ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 21, 22, 23, 24, 25, 26 ] );
37+
$this->fileHasErrors( $phpcsFile, 'InvalidDomain', [ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 21, 22, 23, 24, 25, 26, 34 ] );
3838
}
3939

4040
/**
@@ -46,6 +46,6 @@ public function testProcessWithRewrittenPaths() {
4646

4747
$phpcsFile = $this->process( new ValidateDomainSniff(), 'ValidateDomainWithRewrites' );
4848

49-
$this->fileHasErrors( $phpcsFile, 'InvalidDomain', [ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 20, 27, 28, 29, 30, 41 ] );
49+
$this->fileHasErrors( $phpcsFile, 'InvalidDomain', [ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 20, 27, 28, 29, 30, 34, 41 ] );
5050
}
5151
}

0 commit comments

Comments
 (0)