Skip to content

Commit b9922c4

Browse files
committed
First commit for LVR
0 parents  commit b9922c4

File tree

14 files changed

+738
-0
lines changed

14 files changed

+738
-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-state` 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) 2017 Tyler Arbon <tylercd100@gmail.com>
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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Validate states and provinces for USA and Canada with Laravel 5
2+
[![Latest Version](https://img.shields.io/github/release/tylercd100/laravel-validator-state.svg?style=flat-square)](https://github.com/tylercd100/laravel-validator-state/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-state.svg?branch=master)](https://travis-ci.org/tylercd100/laravel-validator-state)
5+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/tylercd100/laravel-validator-state/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/tylercd100/laravel-validator-state/?branch=master)
6+
[![Code Coverage](https://scrutinizer-ci.com/g/tylercd100/laravel-validator-state/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/tylercd100/laravel-validator-state/?branch=master)
7+
[![Total Downloads](https://img.shields.io/packagist/dt/tylercd100/laravel-validator-state.svg?style=flat-square)](https://packagist.org/packages/tylercd100/laravel-validator-state)
8+
9+
## Installation
10+
11+
Install via [composer](https://getcomposer.org/) - In the terminal:
12+
```bash
13+
composer require laravel-validation-rules/state
14+
```
15+
16+
Now add the following to the `providers` array in your `config/app.php`
17+
```php
18+
LVR\State\ServiceProvider::class
19+
```
20+
21+
## Usage
22+
23+
```php
24+
# USA vs Canada
25+
Validator::make(['test' => 'UT'], ['test' => 'state']); //true
26+
Validator::make(['test' => 'UT'], ['test' => 'state:usa']); //true
27+
Validator::make(['test' => 'BC'], ['test' => 'state:canada']); //true
28+
29+
# Abbreviation vs Full
30+
Validator::make(['test' => 'Utah'], ['test' => 'state:full']); //true
31+
Validator::make(['test' => 'UT'], ['test' => 'state:abbr']); //true
32+
33+
# Mix and match
34+
Validator::make(['test' => 'UT'], ['test' => 'state:usa,abbr']); //true
35+
Validator::make(['test' => 'Alberta'], ['test' => 'state:canada,full']); //true
36+
```

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-state",
3+
"description": "Validate that a states and provinces for US and Canada",
4+
"keywords": [
5+
"laravel",
6+
"validator",
7+
"phone",
8+
"tylercd100"
9+
],
10+
"homepage": "https://github.com/tylercd100/laravel-validator-state",
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\\State\\":"src/"
21+
}
22+
},
23+
"autoload-dev": {
24+
"psr-4": {
25+
"Tylercd100\\Validator\\State\\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/Parameters.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace LVR\State;
4+
5+
class Parameters
6+
{
7+
protected $country = null;
8+
protected $case = null;
9+
protected $type = null;
10+
11+
public function __construct($params)
12+
{
13+
$params = array_map('strtolower', $params);
14+
$this->country = $this->pullCountry($params);
15+
$this->case = $this->pullCase($params);
16+
$this->type = $this->pullType($params);
17+
}
18+
19+
protected function pullCountry($params)
20+
{
21+
$z = null;
22+
$x = [
23+
"usa" => ["us", "usa"],
24+
"canada" => ["ca", "canada"],
25+
];
26+
27+
foreach ($x as $key => $possibilities) {
28+
foreach ($possibilities as $value) {
29+
$z = in_array($value, $params) ? $key : $z;
30+
}
31+
}
32+
33+
return $z;
34+
}
35+
36+
protected function pullCase($params)
37+
{
38+
$z = null;
39+
$x = ["upper", "lower", "title"];
40+
41+
foreach ($x as $value) {
42+
$z = in_array($value, $params) ? $value : $z;
43+
}
44+
45+
return $z;
46+
}
47+
48+
protected function pullType($params)
49+
{
50+
$z = null;
51+
$x = [
52+
"abbr" => ["abbr", "abbrev", "abbreviation"],
53+
"full" => ["full", "long", "whole"],
54+
];
55+
56+
foreach ($x as $key => $possibilities) {
57+
foreach ($possibilities as $value) {
58+
$z = in_array($value, $params) ? $key : $z;
59+
}
60+
}
61+
62+
return $z;
63+
}
64+
65+
public function getCountry()
66+
{
67+
return $this->country;
68+
}
69+
70+
public function getCase()
71+
{
72+
return $this->case;
73+
}
74+
75+
public function getType()
76+
{
77+
return $this->type;
78+
}
79+
}

0 commit comments

Comments
 (0)