Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion WPForms/Sniffs/PHP/ValidateDomainSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,20 @@ public function process( File $phpcsFile, $stackPtr ) {
return;
}

if ( ! $currentDomain || ! $expectedDomain ) {
if ( ! $currentDomain ) {
$phpcsFile->addError(
sprintf(
"Domain name is not set. You should be using '%s'.",
$expectedDomain
),
$stackPtr,
'InvalidDomain'
);

return;
}

if ( ! $expectedDomain ) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions WPForms/Tests/TestFiles/PHP/ValidateDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
_nx( 'Invalid', 'Invalid', 10, 'Invalid', 'wpforms' );


// Valid syntax when the text domain is not specified.
esc_html__( 'Valid' );
// Invalid syntax when the text domain is not specified.
esc_html__( 'Invalid' );

// Invalid - not a string as the last argument.
$bulk_counts['read'] = 25;
Expand Down
6 changes: 3 additions & 3 deletions WPForms/Tests/Tests/PHP/ValidateDomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testProcess() {

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

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

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

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

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

/**
Expand All @@ -46,6 +46,6 @@ public function testProcessWithRewrittenPaths() {

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

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