Skip to content

Commit 6de22a1

Browse files
committed
Updated for LVR
0 parents  commit 6de22a1

13 files changed

+477
-0
lines changed

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
/.gitattributes export-ignore
6+
/.gitignore export-ignore
7+
/.travis.yml export-ignore
8+
/phpunit.xml export-ignore
9+
/.scrutinizer.yml export-ignore
10+
/tests export-ignore

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build
2+
composer.lock
3+
vendor
4+
run.php

.scrutinizer.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
filter:
2+
excluded_paths: [tests/*]
3+
4+
tools:
5+
external_code_coverage:
6+
timeout: '3600'
7+
runs: 3
8+
9+
checks:
10+
php:
11+
code_rating: true
12+
duplication: true
13+
remove_extra_empty_lines: true
14+
remove_php_closing_tag: true
15+
remove_trailing_whitespace: true
16+
fix_use_statements:
17+
remove_unused: true
18+
preserve_multiple: false
19+
preserve_blanklines: true
20+
order_alphabetically: true
21+
fix_php_opening_tag: true
22+
fix_linefeed: true
23+
fix_line_ending: true
24+
fix_identation_4spaces: true
25+
fix_doc_comments: true

.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
language: php
2+
3+
php:
4+
- 5.5.9
5+
- 5.6
6+
- 7.0
7+
8+
env:
9+
matrix:
10+
- COMPOSER_FLAGS="--prefer-lowest"
11+
- COMPOSER_FLAGS=""
12+
13+
before_script:
14+
- travis_retry composer self-update
15+
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
16+
17+
script:
18+
- vendor/bin/phpunit
19+
- if [ "$TRAVIS_PHP_VERSION" == "5.5.9" ] || [ "$TRAVIS_PHP_VERSION" == "5.5" ] || [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then vendor/bin/phpunit --coverage-clover build/logs/clover.xml; fi
20+
21+
after_script:
22+
- if [ "$TRAVIS_PHP_VERSION" == "5.5.9" ] || [ "$TRAVIS_PHP_VERSION" == "5.5" ] || [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
23+
- if [ "$TRAVIS_PHP_VERSION" == "5.5.9" ] || [ "$TRAVIS_PHP_VERSION" == "5.5" ] || [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
All notable changes to `laravel-validation-rules/us-phone` will be documented in this file.
4+
5+
### 1.0.0
6+
- Initial release and connected with packagist

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Zenapply
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Validate phone numbers with Laravel 5
2+
[![Latest Version](https://img.shields.io/github/release/laravel-valiation-rules/us-phone.svg?style=flat-square)](https://github.com/laravel-valiation-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-valiation-rules/us-phone.svg?branch=master)](https://travis-ci.org/laravel-valiation-rules/us-phone)
5+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/laravel-valiation-rules/us-phone/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/laravel-valiation-rules/us-phone/?branch=master)
6+
[![Code Coverage](https://scrutinizer-ci.com/g/laravel-valiation-rules/us-phone/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/laravel-valiation-rules/us-phone/?branch=master)
7+
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-valiation-rules/us-phone.svg?style=flat-square)](https://packagist.org/packages/laravel-valiation-rules/us-phone)
8+
9+
This package only checks phone number formatting and not actual number validity.
10+
11+
## Installation
12+
13+
Install via [composer](https://getcomposer.org/) - In the terminal:
14+
```bash
15+
composer require laravel-valiation-rules/us-phone
16+
```
17+
18+
Now add the following to the `providers` array in your `config/app.php`
19+
```php
20+
LVR\Phone\ServiceProvider::class
21+
```
22+
23+
## Usage
24+
25+
```php
26+
// 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
30+
31+
// Test for E164
32+
Validator::make(['test' => '+15556667777'], ['test' => 'phone:E164']); //true
33+
34+
// Test for NANP (North American Numbering Plan)
35+
Validator::make(['test' => '+1 (555) 666-7777'], ['test' => 'phone:NANP']); //true
36+
37+
// Test for digits only
38+
Validator::make(['test' => '15556667777'], ['test' => 'phone:digits']); //true
39+
```

composer.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "laravel-validation-rules/us-phone",
3+
"description": "Validate that a phone number is in the correct format",
4+
"keywords": [
5+
"laravel",
6+
"validator",
7+
"phone",
8+
"tylercd100"
9+
],
10+
"homepage": "https://github.com/laravel-validation-rules/us-phone",
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Tyler Arbon",
15+
"email": "[email protected]"
16+
}
17+
],
18+
"autoload":{
19+
"psr-4":{
20+
"LVR\\Phone\\":"src/"
21+
}
22+
},
23+
"autoload-dev": {
24+
"psr-4": {
25+
"LVR\\Phone\\Tests\\": "tests/"
26+
}
27+
},
28+
"minimum-stability": "stable",
29+
"require": {
30+
"illuminate/validation": "^5.0",
31+
"illuminate/support": "^5.0",
32+
"php": "^5.5.9|^7.0"
33+
},
34+
"require-dev": {
35+
"phpunit/phpunit": "^4.8|^5.0",
36+
"orchestra/testbench": "^3.2"
37+
},
38+
"suggest": {
39+
}
40+
}

phpunit.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Zenapply Test Suite">
14+
<directory>tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory suffix=".php">src/</directory>
20+
</whitelist>
21+
</filter>
22+
<logging>
23+
<log type="tap" target="build/report.tap"/>
24+
<log type="junit" target="build/report.junit.xml"/>
25+
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
26+
<log type="coverage-text" target="build/coverage.txt"/>
27+
<log type="coverage-clover" target="build/logs/clover.xml"/>
28+
</logging>
29+
</phpunit>

src/ServiceProvider.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace LVR\Phone;
4+
5+
use Exception;
6+
use Illuminate\Support\ServiceProvider as IlluminateProvider;
7+
use LVR\Phone\Validator;
8+
9+
class ServiceProvider extends IlluminateProvider
10+
{
11+
/**
12+
* Bootstrap the application events.
13+
*
14+
* @return void
15+
*/
16+
public function boot()
17+
{
18+
19+
}
20+
21+
/**
22+
* Register the service provider.
23+
*
24+
* @return void
25+
*/
26+
public function register()
27+
{
28+
$this->app->resolving('validator', function ($factory, $app) {
29+
30+
$x = new Validator();
31+
32+
$factory->extend('phone', function ($attribute, $value, $parameters, $validator) use ($x) {
33+
if (count($parameters) > 0) {
34+
switch ($parameters[0]) {
35+
case 'digits':
36+
return $x->isDigits($value);
37+
case 'e164':
38+
case 'E164':
39+
return $x->isE164($value);
40+
case 'nanp':
41+
case 'NANP':
42+
return $x->isNANP($value);
43+
default:
44+
throw new Exception($parameters[0]." is not a supported phone validation type.", 1);
45+
}
46+
} else {
47+
return $x->isPhone($value);
48+
}
49+
}, "Not a valid phone number");
50+
});
51+
}
52+
}

0 commit comments

Comments
 (0)