Skip to content

Commit 29ccd40

Browse files
committed
Updated for laravel 5.5
1 parent 238484d commit 29ccd40

File tree

9 files changed

+198
-203
lines changed

9 files changed

+198
-203
lines changed

README.md

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,50 @@
1-
# Validate phone numbers with Laravel 5
2-
[![Latest Version](https://img.shields.io/github/release/laravel-validation-rules/us-phone.svg?style=flat-square)](https://github.com/laravel-validation-rules/us-phone/releases)
3-
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
4-
[![Build Status](https://travis-ci.org/laravel-validation-rules/us-phone.svg?branch=master)](https://travis-ci.org/laravel-validation-rules/us-phone)
5-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/laravel-validation-rules/us-phone/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/laravel-validation-rules/us-phone/?branch=master)
6-
[![Code Coverage](https://scrutinizer-ci.com/g/laravel-validation-rules/us-phone/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/laravel-validation-rules/us-phone/?branch=master)
7-
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-validation-rules/us-phone.svg?style=flat-square)](https://packagist.org/packages/laravel-validation-rules/us-phone)
8-
9-
This package only checks phone number formatting and not actual number validity.
1+
# Phone
2+
3+
Validates phone number format.
4+
5+
<p >
6+
<a href="https://travis-ci.org/laravel-validation-rules/us-phone">
7+
<img src="https://img.shields.io/travis/laravel-validation-rules/us-phone.svg?style=flat-square">
8+
</a>
9+
<a href="https://scrutinizer-ci.com/g/laravel-validation-rules/us-phone/code-structure/master/code-coverage">
10+
<img src="https://img.shields.io/scrutinizer/coverage/g/laravel-validation-rules/us-phone.svg?style=flat-square">
11+
</a>
12+
<a href="https://scrutinizer-ci.com/g/laravel-validation-rules/us-phone">
13+
<img src="https://img.shields.io/scrutinizer/g/laravel-validation-rules/us-phone.svg?style=flat-square">
14+
</a>
15+
<a href="https://github.com/laravel-validation-rules/us-phone/blob/master/LICENSE">
16+
<img src="https://img.shields.io/github/license/laravel-validation-rules/us-phone.svg?style=flat-square">
17+
</a>
18+
<a href="https://twitter.com/clarkeash">
19+
<img src="http://img.shields.io/badge/[email protected]?style=flat-square">
20+
</a>
21+
</p>
1022

1123
## Installation
1224

13-
Install via [composer](https://getcomposer.org/) - In the terminal:
1425
```bash
1526
composer require laravel-validation-rules/us-phone
1627
```
1728

18-
Now add the following to the `providers` array in your `config/app.php`
19-
```php
20-
LVR\Phone\ServiceProvider::class
21-
```
22-
2329
## Usage
2430

2531
```php
32+
use LVR\Phone\Phone;
33+
use LVR\Phone\E164;
34+
use LVR\Phone\NANP;
35+
use LVR\Phone\Digits;
36+
2637
// Test any phone number
27-
Validator::make(['test' => '15556667777'], ['test' => 'phone']); //true
28-
Validator::make(['test' => '+15556667777'], ['test' => 'phone']); //true
29-
Validator::make(['test' => '+1 (555) 666-7777'], ['test' => 'phone']); //true
38+
$request->validate(['test' => '15556667777'], new Phone); //true
39+
$request->validate(['test' => '+15556667777'], new Phone); //true
40+
$request->validate(['test' => '+1 (555) 666-7777'], new Phone); //true
3041

3142
// Test for E164
32-
Validator::make(['test' => '+15556667777'], ['test' => 'phone:E164']); //true
43+
$request->validate(['test' => '+15556667777'], ['test' => new E164]); //true
3344

3445
// Test for NANP (North American Numbering Plan)
35-
Validator::make(['test' => '+1 (555) 666-7777'], ['test' => 'phone:NANP']); //true
46+
$request->validate(['test' => '+1 (555) 666-7777'], ['test' => new NANP); //true
3647

3748
// Test for digits only
38-
Validator::make(['test' => '15556667777'], ['test' => 'phone:digits']); //true
49+
$request->validate(['test' => '15556667777'], ['test' => new Digits]); //true
3950
```

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
},
2828
"minimum-stability": "stable",
2929
"require": {
30-
"illuminate/validation": "^5.0",
31-
"illuminate/support": "^5.0",
32-
"php": "^5.5.9|^7.0"
30+
"illuminate/validation": "^5.5",
31+
"illuminate/support": "^5.5",
32+
"php": "^7.0"
3333
},
3434
"require-dev": {
35-
"phpunit/phpunit": "^4.8|^5.0",
35+
"phpunit/phpunit": "^6.0",
3636
"orchestra/testbench": "^3.2"
3737
},
3838
"suggest": {

src/Digits.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
namespace LVR\Phone;
3+
4+
use Illuminate\Contracts\Validation\Rule;
5+
6+
class Digits extends Phone
7+
{
8+
/**
9+
* Determine if the validation rule passes.
10+
*
11+
* @param string $attribute
12+
* @param mixed $value
13+
*s
14+
* @return bool
15+
*/
16+
public function passes($attribute, $value)
17+
{
18+
return $this->isDigits($value);
19+
}
20+
21+
/**
22+
* Get the validation error message.
23+
*
24+
* @return string
25+
*/
26+
public function message()
27+
{
28+
return ':attribute must be in digits only phone format';
29+
}
30+
}

src/E164.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
namespace LVR\Phone;
3+
4+
use Illuminate\Contracts\Validation\Rule;
5+
6+
class E164 extends Phone
7+
{
8+
/**
9+
* Determine if the validation rule passes.
10+
*
11+
* @param string $attribute
12+
* @param mixed $value
13+
*
14+
* @return bool
15+
*/
16+
public function passes($attribute, $value)
17+
{
18+
return $this->isE164($value);
19+
}
20+
21+
/**
22+
* Get the validation error message.
23+
*
24+
* @return string
25+
*/
26+
public function message()
27+
{
28+
return ':attribute must be in E.164 phone format';
29+
}
30+
}

src/NANP.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
namespace LVR\Phone;
3+
4+
use Illuminate\Contracts\Validation\Rule;
5+
6+
class NANP extends Phone
7+
{
8+
/**
9+
* Determine if the validation rule passes.
10+
*
11+
* @param string $attribute
12+
* @param mixed $value
13+
*s
14+
* @return bool
15+
*/
16+
public function passes($attribute, $value)
17+
{
18+
return $this->isNANP($value);
19+
}
20+
21+
/**
22+
* Get the validation error message.
23+
*
24+
* @return string
25+
*/
26+
public function message()
27+
{
28+
return ':attribute must be in the NANP phone format';
29+
}
30+
}

src/Validator.php renamed to src/Phone.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
<?php
2-
32
namespace LVR\Phone;
43

5-
class Validator
4+
use Illuminate\Contracts\Validation\Rule;
5+
6+
class Phone implements Rule
67
{
7-
public function __call($a, $b)
8+
/**
9+
* Determine if the validation rule passes.
10+
*
11+
* @param string $attribute
12+
* @param mixed $value
13+
*
14+
* @return bool
15+
*/
16+
public function passes($attribute, $value)
17+
{
18+
return $this->isPhone($value);
19+
}
20+
21+
/**
22+
* Get the validation error message.
23+
*
24+
* @return string
25+
*/
26+
public function message()
827
{
9-
return empty($b[0]) || $this->{$a}($b[0]);
28+
return 'Incorrect phone format for :attribute.';
1029
}
1130

1231
/**
@@ -61,4 +80,4 @@ protected function isNANP($value)
6180
$conditions[] = preg_match("/^(?:\+1|1)?\s?-?\(?\d{3}\)?(\s|-)?\d{3}-\d{4}$/i", $value) > 0;
6281
return (bool) array_product($conditions);
6382
}
64-
}
83+
}

src/ServiceProvider.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

tests/TestCase.php

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,5 @@
66

77
class TestCase extends Orchestra
88
{
9-
/**
10-
* Setup the test environment.
11-
*/
12-
public function setUp()
13-
{
14-
parent::setUp();
15-
}
169

17-
public function tearDown()
18-
{
19-
parent::tearDown();
20-
}
21-
22-
/**
23-
* @param \Illuminate\Foundation\Application $app
24-
*/
25-
protected function getPackageProviders($app)
26-
{
27-
return ['LVR\Phone\ServiceProvider'];
28-
}
29-
30-
/**
31-
* @param \Illuminate\Foundation\Application $app
32-
*/
33-
protected function getPackageAliases($app)
34-
{
35-
return [];
36-
}
37-
38-
/**
39-
* Define environment setup.
40-
*
41-
* @param \Illuminate\Foundation\Application $app
42-
* @return void
43-
*/
44-
protected function getEnvironmentSetUp($app)
45-
{
46-
47-
}
48-
49-
/**
50-
* Call protected/private method of a class.
51-
*
52-
* @param object &$object Instantiated object that we will run method on.
53-
* @param string $methodName Method name to call
54-
* @param array $parameters Array of parameters to pass into method.
55-
*
56-
* @return mixed Method return.
57-
*/
58-
public function invokeMethod(&$object, $methodName, array $parameters = array())
59-
{
60-
$reflection = new \ReflectionClass(get_class($object));
61-
$method = $reflection->getMethod($methodName);
62-
$method->setAccessible(true);
63-
64-
return $method->invokeArgs($object, $parameters);
65-
}
6610
}

0 commit comments

Comments
 (0)