Skip to content

Commit ec9371f

Browse files
committed
first commit
0 parents  commit ec9371f

13 files changed

+346
-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-validator-color` 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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Validate colors with Laravel 5
2+
[![Latest Version](https://img.shields.io/github/release/tylercd100/laravel-validator-phone.svg?style=flat-square)](https://github.com/tylercd100/laravel-validator-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/tylercd100/laravel-validator-phone.svg?branch=master)](https://travis-ci.org/tylercd100/laravel-validator-phone)
5+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/tylercd100/laravel-validator-phone/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/tylercd100/laravel-validator-phone/?branch=master)
6+
[![Code Coverage](https://scrutinizer-ci.com/g/tylercd100/laravel-validator-phone/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/tylercd100/laravel-validator-phone/?branch=master)
7+
[![Dependency Status](https://www.versioneye.com/user/projects/56f3252c35630e0029db0187/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56f3252c35630e0029db0187)
8+
[![Total Downloads](https://img.shields.io/packagist/dt/tylercd100/laravel-validator-phone.svg?style=flat-square)](https://packagist.org/packages/tylercd100/laravel-validator-phone)
9+
10+
## Installation
11+
12+
Install via [composer](https://getcomposer.org/) - In the terminal:
13+
```bash
14+
composer require tylercd100/laravel-validator-phone
15+
```
16+
17+
Now add the following to the `providers` array in your `config/app.php`
18+
```php
19+
Tylercd100\Validator\Phone\ServiceProvider::class
20+
```
21+
22+
## Usage
23+
24+
```php
25+
// Test any color type
26+
Validator::make(['test' => '5556667777'], ['test' => 'phone']);
27+
28+
// Test for rgb
29+
Validator::make(['test' => 'rgb(0, 200, 150)'], ['test' => 'color_rgb']);
30+
31+
// Test for rgba
32+
Validator::make(['test' => 'rgba(0, 200, 150, 0.52)'], ['test' => 'color_rgba']);
33+
34+
// Test for hex
35+
Validator::make(['test' => '#333'], ['test' => 'color_hex']);
36+
37+
// Test for css color keyword
38+
Validator::make(['test' => 'gold'], ['test' => 'color_keyword']);

composer.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "tylercd100/laravel-validator-e164",
3+
"description": "Validate that a phone number is in E164 format",
4+
"keywords": [
5+
"laravel",
6+
"validator",
7+
"e164",
8+
"tylercd100"
9+
],
10+
"homepage": "https://github.com/tylercd100/laravel-validator-e164",
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Tyler Arbon",
15+
"email": "tylercd100@gmail.com"
16+
}
17+
],
18+
"autoload":{
19+
"psr-4":{
20+
"Tylercd100\\Validator\\E164\\":"src/"
21+
}
22+
},
23+
"autoload-dev": {
24+
"psr-4": {
25+
"Tylercd100\\Validator\\E164\\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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Tylercd100\Validator\Phone;
4+
5+
use Illuminate\Support\ServiceProvider as IlluminateProvider;
6+
use Tylercd100\Validator\Phone\Validator;
7+
8+
class ServiceProvider extends IlluminateProvider
9+
{
10+
/**
11+
* Bootstrap the application events.
12+
*
13+
* @return void
14+
*/
15+
public function boot()
16+
{
17+
18+
}
19+
20+
/**
21+
* Register the service provider.
22+
*
23+
* @return void
24+
*/
25+
public function register()
26+
{
27+
$this->app->resolving('validator', function ($factory, $app) {
28+
29+
$x = new Validator();
30+
31+
$factory->extend('phone', function ($attribute, $value, $parameters, $validator) use ($x) {
32+
var_dump([$attribute, $value, $parameters]);
33+
die();
34+
return $x->isE164($value);
35+
});
36+
});
37+
}
38+
}

src/Validator.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Tylercd100\Validator\Phone;
4+
5+
class Validator
6+
{
7+
public function isPhone()
8+
{
9+
return $this->isE164();
10+
}
11+
12+
public function isE164()
13+
{
14+
return true;
15+
}
16+
}

tests/TestCase.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Tylercd100\Validator\E164\Tests;
4+
5+
use Orchestra\Testbench\TestCase as Orchestra;
6+
7+
class TestCase extends Orchestra
8+
{
9+
/**
10+
* Setup the test environment.
11+
*/
12+
public function setUp()
13+
{
14+
parent::setUp();
15+
}
16+
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 ['Tylercd100\Validator\E164\Providers\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+
}
66+
}

tests/ValidatorTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Tylercd100\Validator\Phone\Tests;
4+
5+
use Validator;
6+
use Tylercd100\Validator\Phone\Validator as PhoneValidator;
7+
8+
class ValidatorTest extends TestCase
9+
{
10+
public function testItCreatesAnInstanceOfPhoneValidator()
11+
{
12+
$obj = new PhoneValidator();
13+
$this->assertInstanceOf(PhoneValidator::class, $obj);
14+
}
15+
16+
protected function validate($color, $rule = 'phone'){
17+
return !(Validator::make(['test' => $color], ['test' => $rule])->fails());
18+
}
19+
20+
// public function testValidatorPhone()
21+
// {
22+
// $this->assertEquals(true, $this->validate('+15556667777', 'phone'));
23+
// }
24+
25+
public function testValidatorPhoneE164()
26+
{
27+
$this->assertEquals(true, $this->validate('+15556667777', 'phone:E164'));
28+
$this->assertEquals(false, $this->validate('5556667777', 'phone:E164'));
29+
}
30+
}

0 commit comments

Comments
 (0)