Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Commit

Permalink
Fixes for PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Waite committed Jan 26, 2022
1 parent c8243ee commit ce7fd36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A PHP API client for the SEMrush API.
## Supported actions:

* domain_ranks
* domain_domain
* domain_domains
* domain_rank
* domain_rank_history
* domain_organic
Expand Down
10 changes: 8 additions & 2 deletions src/Model/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,26 @@ protected function validateDomain($key, $domain)
* @param string $key
* @param string $domain
* @throws InvalidOptionException
*
* Validates the format <sign>|<type>|<domain>|<sign>|<type>|<domain>|...
*/
protected function validateDomains($key, $domains)
{
$parts = explode('|', $domains);

if (count($parts) > 5 * 3) { // 5 domains max, each with 3 parts
throw new InvalidOptionException("[{$key}] contains too many domains");
}

for ($i = 0; $i < count($parts); $i++) {
switch ($i % 3) {
case 0:
if (!in_array($parts[$i], ['+', '-', '/', '*'])) {
if (!in_array($parts[$i], ['+', '-', '/', '*'], true)) {
throw new InvalidOptionException("[{$key}] contains an invalid sign [{ $parts[$i]}]");
}
break;
case 1:
if (!in_array($parts[$i], ['or', 'ad'])) {
if (!in_array($parts[$i], ['or', 'ad'], true)) {
throw new InvalidOptionException("[{$key}] contains an invalid type - must be or or ad [{ $parts[$i]}]");
}
break;
Expand Down

0 comments on commit ce7fd36

Please sign in to comment.