Repository: Propaganistas/Laravel-Phone (language: php)

Issue:
"mobile" parameter no longer working in 5.1.0 when one of the data fields is "mobile"
In [this commit](https://github.com/Propaganistas/Laravel-Phone/commit/99f2d320a15f1a7e5d196a3e8e17b586756ab44f#diff-48e28eb93ccfcade09cdb083d128c8a87e08516d3f2b182445f1877626f8bff9), the `mobile` and `fixed-line` string parameters were removed from `Phone::setParameters()`. This breaks backwards compatibility (so should be a major release) and I don't think is intended.


Discussion / hints:
Upon further investigation, I realize that the functionality is being reproduced in the `type()` calls at the end. The issue I'm having is that because these calls have moved to the end, `$this->isDataKey($parameter)` on line 161 is returning true. I'm not sure what the function of that is, but the problem ultimately is that my form data field is "mobile", which makes it think it's a country.

Reproduction:

```
// With data ['mobile' => '01274761999']
$request->validate(
            [
                'mobile' => ['nullable', 'phone:mobile,GB'],
            ],
        );
```

Fix patch:
diff --git a/src/Rules/Phone.php b/src/Rules/Phone.php
index 7cdecd5..33b39ba 100644
--- a/src/Rules/Phone.php
+++ b/src/Rules/Phone.php
@@ -158,14 +158,14 @@ public function setParameters($parameters)
                 $this->lenient();
             } elseif (strcasecmp('international', $parameter) === 0) {
                 $this->international();
-            } elseif ($this->isDataKey($parameter)) {
-                $this->countryField = $parameter;
-            } elseif (PhoneNumberCountry::isValid($parameter)) {
-                $this->country($parameter);
             } elseif (ctype_digit($parameter) && PhoneNumberType::isValid((int) $parameter)) {
                 $this->type((int) $parameter);
             } elseif (PhoneNumberType::isValidName($parameter)) {
                 $this->type($parameter);
+            } elseif ($this->isDataKey($parameter)) {
+                $this->countryField = $parameter;
+            } elseif (PhoneNumberCountry::isValid($parameter)) {
+                $this->country($parameter);
             }
         }
 


Test patch:
diff --git a/tests/RuleTest.php b/tests/RuleTest.php
index 4467a7a..92d1133 100644
--- a/tests/RuleTest.php
+++ b/tests/RuleTest.php
@@ -183,6 +183,22 @@ public function it_converts_string_validation_parameters()
         $this->assertEquals(['mobile', 'fixed_line'], $this->getProtectedProperty($rule, 'blockedTypes'));
     }
 
+    /** @test */
+    public function it_allows_data_field_names_to_be_parameters()
+    {
+        $base = (new Phone)->setValidator(validator([
+            'mobile' => null,
+            'fixed_line' => null,
+            'lenient' => null,
+            'international' => null,
+        ]));
+
+        $rule = $base->setParameters(['mobile', 'fixed_line', 'lenient', 'international']);
+        $this->assertEquals(['mobile', 'fixed_line'], $this->getProtectedProperty($rule, 'allowedTypes'));
+        $this->assertTrue($this->getProtectedProperty($rule, 'lenient'));
+        $this->assertTrue($this->getProtectedProperty($rule, 'international'));
+    }
+
     /** @test */
     public function it_treats_string_validation_parameters_case_insensitive()
     {