| Total Complexity | 6 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class AnAvailableUrlExistsForTheDomain implements Rule |
||
| 9 | { |
||
| 10 | protected $errorMessage = null; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Create a new rule instance. |
||
| 14 | * |
||
| 15 | * @return void |
||
| 16 | */ |
||
| 17 | public function __construct() |
||
| 18 | { |
||
| 19 | // |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Determine if the validation rule passes. |
||
| 24 | * |
||
| 25 | * @param string $attribute |
||
| 26 | * @param mixed $value |
||
| 27 | * |
||
| 28 | * @return bool |
||
| 29 | */ |
||
| 30 | public function passes($attribute, $value) |
||
| 31 | { |
||
| 32 | |||
| 33 | // TODO: Inject mocked Guzzle\Client to getDomainURL to test these responses here. |
||
| 34 | $result = Domain::getDomainURL($value); |
||
| 35 | // Domain is available with http:// or https:// |
||
| 36 | if (is_string($result)) { |
||
| 37 | return true; |
||
| 38 | } |
||
| 39 | |||
| 40 | // Domain is only available with or without www. |
||
| 41 | elseif (isset($result) && $result->isNotEmpty()) { |
||
| 42 | $this->errorMessage = $result->get('notAvailable').' is not available. Did you mean '.$result->get('alternativeAvailable').'?'; |
||
| 43 | |||
| 44 | return false; |
||
| 45 | } |
||
| 46 | |||
| 47 | $this->errorMessage = $value.' is not available.'; |
||
| 48 | |||
| 49 | return false; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Get the validation error message. |
||
| 54 | * |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | public function message() |
||
| 60 | } |
||
| 61 | } |
||
| 62 |