From 808256aeedc0726eb4aaeb8eca7a9267b06abc23 Mon Sep 17 00:00:00 2001 From: chadicus Date: Fri, 15 Nov 2024 09:18:36 -0500 Subject: [PATCH 1/6] Update requirement for traderinteractive/filter-strings --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4d558db..05c9742 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "traderinteractive/filter-dates": "^3.1", "traderinteractive/filter-floats": "^3.0", "traderinteractive/filter-ints": "^3.0", - "traderinteractive/filter-strings": "^3.5" + "traderinteractive/filter-strings": "^3.6" }, "require-dev": { "php-coveralls/php-coveralls": "^2.0", From 7aeb6092fa6ce35f7b3d2aa0de52d8a8d01112ce Mon Sep 17 00:00:00 2001 From: chadicus Date: Fri, 15 Nov 2024 09:20:23 -0500 Subject: [PATCH 2/6] Add UUID Filter alias --- README.md | 9 +++++++++ src/Filterer.php | 2 ++ tests/FiltererTest.php | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/README.md b/README.md index b99fbf4..38e89ce 100644 --- a/README.md +++ b/README.md @@ -696,6 +696,15 @@ The following ensures that `$value` is a valid `HH:MM:SS` formatted string. $value = \TraderInteractive\Filter\TimeOfDayFilter::filter('12:15:23'); assert($value === '12:15:23'); ``` +#### UuidFilter::filter +Aliased in the filterer as `uuid`, this will filter a given string values as a valid UUID. + +The following ensures the `$value` is a valid UUID v4 formatted string. Disallowing null values, nil UUIDs and UUID version other than v4 + +```php +$value = \TraderInteractive\Filter\UuidFilter::filter('2c02b87a-97ec-4de0-8c50-6721a29c150f', false, false, [4]); +assert($value === '2c02b87a-97ec-4de0-8c50-6721a29c150f'); +``` #### XmlFilter::filter Aliased in the filter as `xml`, this will ensure the given string value is valid XML, returning the original value. diff --git a/src/Filterer.php b/src/Filterer.php index a4ee63d..4b1e1ba 100644 --- a/src/Filterer.php +++ b/src/Filterer.php @@ -10,6 +10,7 @@ use TraderInteractive\Filter\Json; use TraderInteractive\Filter\PhoneFilter; use TraderInteractive\Filter\TimeOfDayFilter; +use TraderInteractive\Filter\UuidFilter; use TraderInteractive\Filter\XmlFilter; /** @@ -52,6 +53,7 @@ final class Filterer implements FiltererInterface 'translate' => '\\TraderInteractive\\Filter\\Strings::translate', 'uint' => '\\TraderInteractive\\Filter\\UnsignedInt::filter', 'url' => '\\TraderInteractive\\Filter\\Url::filter', + 'uuid' => UuidFilter::class . '::filter', 'xml' => XmlFilter::class . '::filter', 'xml-extract' => XmlFilter::class . '::extract', 'xml-validate' => XmlFilter::class . '::validate', diff --git a/tests/FiltererTest.php b/tests/FiltererTest.php index e985cdf..5ceb99c 100644 --- a/tests/FiltererTest.php +++ b/tests/FiltererTest.php @@ -532,6 +532,23 @@ function (int $input, int $fieldOneValue) : int { [], ], ], + 'uuid' => [ + 'spec' => [ + 'field' => [['uuid', false, false, [4]]], + ], + 'input' => [ + 'field' => '2c02b87a-97ec-4de0-8c50-6721a29c150f', + ], + 'options' => [], + 'result' => [ + true, + [ + 'field' => '2c02b87a-97ec-4de0-8c50-6721a29c150f', + ], + null, + [], + ], + ], ]; } From fefbecb56092a88758d06e5001c95cb560dc10a8 Mon Sep 17 00:00:00 2001 From: chadicus Date: Fri, 15 Nov 2024 09:20:50 -0500 Subject: [PATCH 3/6] Remove coveralls integration --- .coveralls.yml | 3 --- composer.json | 1 - 2 files changed, 4 deletions(-) delete mode 100644 .coveralls.yml diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 4eecff5..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1,3 +0,0 @@ -service_name: travis-ci -coverage_clover: clover.xml -json_path: coveralls-upload.json diff --git a/composer.json b/composer.json index 05c9742..6ecb0b1 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,6 @@ "traderinteractive/filter-strings": "^3.6" }, "require-dev": { - "php-coveralls/php-coveralls": "^2.0", "phpunit/phpunit": "^6.0", "squizlabs/php_codesniffer": "^3.2", "symfony/yaml": "^3.4" From 19f17db52da4c6889df16ba40ded9a0816bcdb3e Mon Sep 17 00:00:00 2001 From: chadicus Date: Fri, 15 Nov 2024 09:21:15 -0500 Subject: [PATCH 4/6] Remove Travis CI integration --- .travis.yml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3312e9b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -sudo: false -language: php -php: - - 7.0 - - 7.1 - - 7.2 - - nightly -env: - - PREFER_LOWEST="--prefer-lowest --prefer-stable" - - PREFER_LOWEST="" -matrix: - fast_finish: true - allow_failures: - - php: nightly -before_script: - - composer update $PREFER_LOWEST -script: ./vendor/bin/phpunit --coverage-clover clover.xml -after_success: ./vendor/bin/php-coveralls -v From a0814eb9d528132f177fb603d29d1b25c36ca7a4 Mon Sep 17 00:00:00 2001 From: chadicus Date: Fri, 15 Nov 2024 09:20:09 -0500 Subject: [PATCH 5/6] Add workflows for php --- .github/workflows/php.yml | 29 +++++++++++++++++++++++++++++ composer.json | 4 ++++ 2 files changed, 33 insertions(+) create mode 100644 .github/workflows/php.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..aea116d --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,29 @@ +name: PHP Composer + +on: + push: + branches: [ v3.x ] + pull_request: + branches: [ v3.x ] + +jobs: + build: + runs-on: ubuntu-20.04 + strategy: + matrix: + php-versions: ['7.0', '7.2', '7.3', '7.4'] + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + - name: Validate composer.json and composer.lock + run: composer validate + - name: Install dependencies + run: composer install --prefer-dist --no-progress + - name: Run PHPCS + run: composer run-script lint + - name: Run PHPUnit + run: composer run-script test diff --git a/composer.json b/composer.json index 6ecb0b1..a5c567e 100644 --- a/composer.json +++ b/composer.json @@ -45,5 +45,9 @@ }, "autoload": { "psr-4": { "TraderInteractive\\": "src/" } + }, + "scripts": { + "lint": "vendor/bin/phpcs", + "test": "vendor/bin/phpunit" } } From 577d745545e403762df392d765d8f3d40ff810b6 Mon Sep 17 00:00:00 2001 From: chadicus Date: Fri, 15 Nov 2024 09:54:20 -0500 Subject: [PATCH 6/6] Update tests to use var_export properly for each version of PHP --- tests/FiltererTest.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/FiltererTest.php b/tests/FiltererTest.php index 5ceb99c..899c7a3 100644 --- a/tests/FiltererTest.php +++ b/tests/FiltererTest.php @@ -916,17 +916,18 @@ public function ofScalarsWithMeaninglessKeys() */ public function ofScalarsFail() { + $valueOne = '1'; + $valueTwo = []; + $valueThree = new stdClass(); try { - Filterer::ofScalars(['1', [], new stdClass], [['string']]); + Filterer::ofScalars([$valueOne, $valueTwo, $valueThree], [['string']]); $this->fail(); } catch (FilterException $e) { + $valueTwoExport = var_export($valueTwo, true); + $valueThreeExport = var_export($valueThree, true); $expected = <<assertSame($expected, $e->getMessage()); } @@ -974,20 +975,22 @@ public function ofArraysRequiredAndUnknown() */ public function ofArraysFail() { + $valueOne = new stdClass(); + $valueTwo = []; + $valueThree = null; + $valueFour = 'key'; try { Filterer::ofArrays( - [['key' => new stdClass], ['key' => []], ['key' => null], 'key'], + [['key' => $valueOne], ['key' => $valueTwo], ['key' => $valueThree], $valueFour], ['key' => [['string']]] ); $this->fail(); } catch (FilterException $e) { + $valueOneExport = var_export($valueOne, true); + $valueTwoExport = var_export($valueTwo, true); $expected = <<