Skip to content

Commit

Permalink
Merge 76adc8b into 1e30f75
Browse files Browse the repository at this point in the history
  • Loading branch information
chadicus committed Mar 7, 2018
2 parents 1e30f75 + 76adc8b commit ccb0fa9
Show file tree
Hide file tree
Showing 40 changed files with 632 additions and 4,709 deletions.
1 change: 0 additions & 1 deletion .coveralls.yml
@@ -1,4 +1,3 @@
service_name: travis-ci
src_dir: .
coverage_clover: clover.xml
json_path: coveralls-upload.json
13 changes: 13 additions & 0 deletions .gitattributes
@@ -0,0 +1,13 @@
# Enforce Unix newlines
* text=lf

# Exclude unused files
# see: https://redd.it/2jzp6k
/tests export-ignore
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.*.yml export-ignore
/phpcs.xml export-ignore
/phpunit.xml.dist export-ignore
/README.md export-ignore
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
@@ -0,0 +1 @@
* @traderinteractive/opensource
24 changes: 24 additions & 0 deletions .github/CONTRIBUTING.md
@@ -0,0 +1,24 @@
# Contribution Guidelines
We welcome you to report [issues](/../../issues) or submit [pull requests](/../../pulls). While the below guidelines are necessary to get code merged, you can
submit pull requests that do not adhere to them and we will try to take care of them in our spare time. We are a smallish group of developers,
though, so if you can make sure the build is passing 100%, that would be very useful.

We recommend including details of your particular usecase(s) with any issues or pull requests. We love to hear how our libraries are being used
and we can get things merged in quicker when we understand its expected usage.

## Pull Requests
Code changes should be sent through [GitHub Pull Requests](/../../pulls). Before submitting the pull request, make sure that phpunit reports success
by running:
```sh
./vendor/bin/phpunit
```
And there are not coding standard violations by running
```sh
./vendor/bin/phpcs
```

## Builds
Our [Travis build](https://travis-ci.org/traderinteractive/filter-php) executes [PHPUnit](http://www.phpunit.de) and uses [Coveralls](https://coveralls.io/) to enforce code coverage.
While the build does not strictly enforce 100% code coverage, it will not allow coverage to drop below its current percentage.
[Scrutinizer](https://scrutinizer-ci.com/) is used to ensure code quality and enforce the [coding standard](http://www.php-fig.org/psr/psr-2/).

6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE.md
@@ -0,0 +1,6 @@
## Expected Behavior

## Actual Behavior

## Steps to reproduce the behavior

9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,9 @@
Fixes # .

#### What does this PR do?

#### Checklist
- [ ] Pull request contains a clear definition of changes
- [ ] Tests (either unit, integration, or acceptance) written and passing
- [ ] Relevant documentation produced and/or updated

2 changes: 2 additions & 0 deletions .gitignore
@@ -1,3 +1,5 @@
/coverage/
/vendor/
/clover.xml
phpunit.xml
composer.lock
11 changes: 4 additions & 7 deletions .scrutinizer.yml
@@ -1,7 +1,6 @@
filter:
excluded_paths:
- 'vendor/*'
- 'tests/*'
before_commands:
- 'composer install'
tools:
Expand All @@ -14,12 +13,10 @@ tools:
php_loc:
excluded_dirs:
- vendor
- tests
php_pdepend: true
php_sim: true
build_failure_conditions:
- 'elements.rating(<= D).new.exists' # No new classes/methods with a rating of D or worse allowed (useful for legacy code)
- 'issues.label("coding-style").new.exists' # No new coding style issues allowed
- 'issues.label("coding-style").new.count > 5' # More than 5 new coding style issues.
- 'issues.severity(>= MAJOR).new.exists' # New issues of major or higher severity
- 'project.metric("scrutinizer.quality", < 6)' # Code Quality Rating drops below 6
- 'elements.rating(< C).new.exists'
- 'issues.label("coding-style").new.exists'
- 'issues.severity(>= MAJOR).new.exists'
- 'project.metric("scrutinizer.quality", < 8)'
19 changes: 12 additions & 7 deletions .travis.yml
@@ -1,13 +1,18 @@
sudo: false
language: php
php:
- 5.6
- 7
- hhvm
install: composer install
script: ./vendor/bin/phpunit --coverage-clover clover.xml
after_success: sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then ./vendor/bin/coveralls -v; fi'
- 7.0
- 7.1
- 7.2
- nightly
env:
- PREFER_LOWEST="--prefer-lowest --prefer-stable"
- PREFER_LOWEST=""
matrix:
fast_finish: true
allow_failures:
- php: hhvm
- php: nightly
before_script:
- composer update $PREFER_LOWEST
script: ./vendor/bin/phpunit --coverage-clover clover.xml
after_success: ./vendor/bin/coveralls -v
15 changes: 0 additions & 15 deletions CONTRIBUTING.md

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013 Dominion Enterprises
Copyright (c) 2017 Trader Interactive

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
115 changes: 61 additions & 54 deletions README.md
@@ -1,15 +1,15 @@
#filter-php
# filter-php
A filtering implementation for verifying correct data and performing typical modifications to data.

[![Build Status](http://img.shields.io/travis/dominionenterprises/filter-php.svg?style=flat)](https://travis-ci.org/dominionenterprises/filter-php)
[![Scrutinizer Code Quality](http://img.shields.io/scrutinizer/g/dominionenterprises/filter-php.svg?style=flat)](https://scrutinizer-ci.com/g/dominionenterprises/filter-php/)
[![Code Coverage](http://img.shields.io/coveralls/dominionenterprises/filter-php.svg?style=flat)](https://coveralls.io/r/dominionenterprises/filter-php)
[![Build Status](http://img.shields.io/travis/traderinteractive/filter-php.svg?style=flat)](https://travis-ci.org/traderinteractive/filter-php)
[![Scrutinizer Code Quality](http://img.shields.io/scrutinizer/g/traderinteractive/filter-php.svg?style=flat)](https://scrutinizer-ci.com/g/traderinteractive/filter-php/)
[![Code Coverage](http://img.shields.io/coveralls/traderinteractive/filter-php.svg?style=flat)](https://coveralls.io/r/traderinteractive/filter-php)

[![Latest Stable Version](http://img.shields.io/packagist/v/dominionenterprises/filter.svg?style=flat)](https://packagist.org/packages/dominionenterprises/filter)
[![Total Downloads](http://img.shields.io/packagist/dt/dominionenterprises/filter.svg?style=flat)](https://packagist.org/packages/dominionenterprises/filter)
[![License](http://img.shields.io/packagist/l/dominionenterprises/filter.svg?style=flat)](https://packagist.org/packages/dominionenterprises/filter)
[![Latest Stable Version](http://img.shields.io/packagist/v/traderinteractive/filter.svg?style=flat)](https://packagist.org/packages/traderinteractive/filter)
[![Total Downloads](http://img.shields.io/packagist/dt/traderinteractive/filter.svg?style=flat)](https://packagist.org/packages/traderinteractive/filter)
[![License](http://img.shields.io/packagist/l/traderinteractive/filter.svg?style=flat)](https://packagist.org/packages/traderinteractive/filter)

##Features
## Features
* Compact, readable specification
* Filter with any php callable such as
* Anonymous function
Expand All @@ -21,7 +21,18 @@ A filtering implementation for verifying correct data and performing typical mod
* Optionally returns unknown fields
* Filter alias support

##Example
## Components

This package is a partial metapackage aggregating the following components:

* [traderinteractive/filter-arrays](https://github.com/traderinteractive/filter-arrays-php)
* [traderinteractive/filter-bools](https://github.com/traderinteractive/filter-bools-php)
* [traderinteractive/filter-dates](https://github.com/traderinteractive/filter-dates-php)
* [traderinteractive/filter-floats](https://github.com/traderinteractive/filter-floats-php)
* [traderinteractive/filter-ints](https://github.com/traderinteractive/filter-ints-php)
* [traderinteractive/filter-strings](https://github.com/traderinteractive/filter-strings-php)

## Example
```php
class AppendFilter
{
Expand All @@ -34,7 +45,7 @@ $appendFilter = new AppendFilter();

$trimFunc = function($val) { return trim($val); };

list($status, $result, $error, $unknowns) = DominionEnterprises\Filterer::filter(
list($status, $result, $error, $unknowns) = TraderInteractive\Filterer::filter(
[
'field one' => [[$trimFunc], ['substr', 0, 3], [[$appendFilter, 'filter'], 'boo']],
'field two' => ['required' => true, ['floatval']],
Expand Down Expand Up @@ -66,19 +77,15 @@ array(0) {
}
```

##Composer
## Composer
To add the library as a local, per-project dependency use [Composer](http://getcomposer.org)! Simply add a dependency on
`dominionenterprises/filter` to your project's `composer.json` file such as:
`traderinteractive/filter` to your project's `composer.json` file such as:

```json
{
"require": {
"dominionenterprises/filter": "~1.0"
}
}
```sh
composer require traderinteractive/filter
```

##Documentation
## Documentation
Found in the [source](src/Filterer.php) itself, take a look!

### Filterer
Expand Down Expand Up @@ -112,51 +119,51 @@ The example above should help clarify all this.
### Included Filters
Of course, any function can potentially be used as a filter, but we include some useful filters with aliases for common circumstances.

#### Arrays::in
Aliased in the filterer as `in`, this filter is a wrapper around `in_array` including support for strict equality testing.

The following does a strict check for `$value` against the 3 accepted values.
```php
\DominionEnterprises\Filter\Arrays::in($value, ['a', 'b', 'c']);
```

#### Arrays::filter
Aliased in the filterer as `array`, this filter verifies that the argument is an array and checks the length of the array against bounds. The
default bounds are 1+, so an empty array fails by default.

The following checks that the `$value` is an array with exactly 3 elements.
```php
\DominionEnterprises\Filter\Arrays::filter($value, 3, 3);
```

#### Arrays::ofScalars
#### Filterer::ofScalars
Aliased in the filterer as `ofScalars`, this filter verifies that the argument is an array (possibly empty) of scalar items that each pass the
given filters (given in the same format as used by `Filterer::filter`.

The following checks that `$value` is an array of unsigned integers.
```php
$value = \DominionEnterprises\Filter\Arrays::ofScalars($value, [['uint']]);
$value = \TraderInteractive\Filter\Filterer::ofScalars($value, [['uint']]);
```

#### Arrays::ofArrays
#### Filterer::ofArrays
Aliased in the filterer as `ofArrays`, this filter verifies that the argument is an array (possibly empty) of arrays that each pass the given
filters (given in the same format as used by `Filterer::filter`.

The following checks that `$value` is an array of items that each have an `id` key with a numeric value. No other keys would be allowed. For
example, the following is valid input: `[['id' => '1'], ['id' => '2']]`.
```php
$value = \DominionEnterprises\Filter\Arrays::ofArrays($value, ['id' => [['uint']]]);
$value = \TraderInteractive\Filter\Filterer::ofArrays($value, ['id' => [['uint']]]);
```

#### Arrays::ofArray
#### Filterer::ofArray
Aliased in the filterer as `ofArray`, this filter verifies that the argument is an array that passes the given specification. This is
essentially a flipped version of `Filterer::filter` that allows for testing nested associative arrays.

#### Arrays::in
Aliased in the filterer as `in`, this filter is a wrapper around `in_array` including support for strict equality testing.

The following does a strict check for `$value` against the 3 accepted values.
```php
\TraderInteractive\Filter\Arrays::in($value, ['a', 'b', 'c']);
```

#### Arrays::filter
Aliased in the filterer as `array`, this filter verifies that the argument is an array and checks the length of the array against bounds. The
default bounds are 1+, so an empty array fails by default.

The following checks that the `$value` is an array with exactly 3 elements.
```php
\TraderInteractive\Filter\Arrays::filter($value, 3, 3);
```

#### Arrays::flatten
Aliased in the filterer as `flatten`, this filter flattens a multi-dimensional array to a single dimension. The order of values will be
maintained, but the keys themselves will not. For example:
```php
$value = \DominionEnterprises\Filter\Arrays::flatten([[1, 2], [3, [4, 5]]]);
$value = \TraderInteractive\Filter\Arrays::flatten([[1, 2], [3, [4, 5]]]);
assert($value === [1, 2, 3, 4, 5]);
```

Expand All @@ -167,15 +174,15 @@ are lists of strings for true values and false values. By default, the strings

The following example converts `$value` to a boolean allowing the strings "on" and "of".
```php
$enabled = \DominionEnterprises\Filter\Booleans::filter($value, false, ['on'], ['off']);
$enabled = \TraderInteractive\Filter\Booleans::filter($value, false, ['on'], ['off']);
```
#### Booleans::convert
Aliased in the filterer as `bool-convert`, this filter will convert a given boolean value into the provided true or false conditions. By default the
return values are the strings 'true' and 'false'

The following converts the boolean `$value` to either 'yes' or 'no'
```php
$answer = \DominionEnterprises\Filter\Booleans::convert($value, 'yes', 'no');
$answer = \TraderInteractive\Filter\Booleans::convert($value, 'yes', 'no');
```

#### Floats/Ints/UnsignedInt::filter
Expand All @@ -191,7 +198,7 @@ validation.

The following checks that `$value` is an integer between 1 and 100 inclusive, and returns the integer (after casting it if it was a string).
```php
$value = \DominionEnterprises\Filter\UnsignedInt::filter($value, false, 1, 100);
$value = \TraderInteractive\Filter\UnsignedInt::filter($value, false, 1, 100);
```

#### Strings::filter
Expand All @@ -201,14 +208,14 @@ string. The default bounds are 1+, so an empty string fails by default.

The following checks that `$value` is a non-empty string.
```php
\DominionEnterprises\Filter\Strings::filter($value);
\TraderInteractive\Filter\Strings::filter($value);
```

#### Strings::explode
Aliased in the filterer as `explode`, this filter is essentially a wrapper around the built-in [`explode`](http://www.php.net/explode) method
with the value first in order to work with the `Filterer`. It also defaults to using `,` as a delimiter. For example:
```php
$value = \DominionEnterprises\Filter\Strings::explode('abc,def,ghi');
$value = \TraderInteractive\Filter\Strings::explode('abc,def,ghi');
assert($value === ['abc', 'def', 'ghi']);
```

Expand All @@ -219,46 +226,46 @@ null values through without an error (they will stay null and not get converted

The following checks that `$value` is a URL.
```php
\DominionEnterprises\Filter\Url::filter($value);
\TraderInteractive\Filter\Url::filter($value);
```

#### Email::filter
Aliased in the filterer as `email`, this filter verifies that the argument is an email.

The following checks that `$value` is an email.
```php
\DominionEnterprises\Filter\Email::filter($value);
\TraderInteractive\Filter\Email::filter($value);
```

#### DateTime::filter
Aliased in the filterer as `date`, this will filter the value as a `\DateTime` object. The value can be any string that conforms to [PHP's valid date/time formats](http://php.net/manual/en/datetime.formats.php)

The following checks that `$value` is a date/time.
```php
$dateTime = \DominionEnterprises\Filter\DateTime::filter('2014-02-04T11:55:00-0500');
$dateTime = \TraderInteractive\Filter\DateTime::filter('2014-02-04T11:55:00-0500');
```

#### DateTime::format
Aliased in the filterer as `date-format`, this will filter a given `\DateTime' value to a string based on the given format.

The following returns formatted string for a given `\DateTime` `$value`
```php
$formatted = \DominionEnterprises\Filter\DateTime::format($value, 'Y-m-d H:i:s');
$formatted = \TraderInteractive\Filter\DateTime::format($value, 'Y-m-d H:i:s');
```

#### DateTimeZone::filter
Aliased in the filterer as `date`, this will filter the value as a `\DateTimeZone` object. The value can be any [supported timezone name](http://php.net/manual/en/timezones.php)

The following checks that `$value` is a timezone
```php
$timezone = \DominionEnterprises\Filter\DateTimeZone::filter('America/New_York');
$timezone = \TraderInteractive\Filter\DateTimeZone::filter('America/New_York');
```

##Contact
Developers may be contacted at:

* [Pull Requests](https://github.com/dominionenterprises/filter-php/pulls)
* [Issues](https://github.com/dominionenterprises/filter-php/issues)
* [Pull Requests](https://github.com/traderinteractive/filter-php/pulls)
* [Issues](https://github.com/traderinteractive/filter-php/issues)

##Project Build
With a checkout of the code get [Composer](http://getcomposer.org) in your PATH and run:
Expand Down

0 comments on commit ccb0fa9

Please sign in to comment.