From 202f7f814d59a0b1497c5261c200084dfdd32fb0 Mon Sep 17 00:00:00 2001 From: Michael Naab Date: Tue, 25 Jul 2023 11:52:03 +0200 Subject: [PATCH 01/13] Add Laravel 10 compatibility --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 2c77211..d315e47 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ "email": "cyrill.kalita@gmail.com" }], "require": { - "illuminate/support": "^8.0|^9.0", - "illuminate/validation": "^8.0|^9.0", + "illuminate/support": "^8.0|^9.0|^10.0", + "illuminate/validation": "^8.0|^9.0|^10.0", "nesbot/carbon": "^2.0" }, "require-dev": { From d14e04cf0e1b6b102e15957766e19b7f1160cd74 Mon Sep 17 00:00:00 2001 From: Fleeym <61891787+Fleeym@users.noreply.github.com> Date: Tue, 30 Apr 2024 14:20:32 +0300 Subject: [PATCH 02/13] Add Laravel 11 compatibility --- composer.json | 8 ++++---- phpunit.xml | 16 +++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index d315e47..dae7796 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ "email": "cyrill.kalita@gmail.com" }], "require": { - "illuminate/support": "^8.0|^9.0|^10.0", - "illuminate/validation": "^8.0|^9.0|^10.0", - "nesbot/carbon": "^2.0" + "illuminate/support": "^8.0|^9.0|^10.0|^11.0", + "illuminate/validation": "^8.0|^9.0|^10.0|^11.0", + "nesbot/carbon": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^10.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index c136f86..1418fc6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,11 @@ - From f069bdfd121dfe9fb0a92d8190367b0ee74e3f57 Mon Sep 17 00:00:00 2001 From: Cyrill Kalita Date: Wed, 17 Jul 2024 10:50:14 -0500 Subject: [PATCH 03/13] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 53fdb8d..14bb152 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[](https://supportukrainenow.org) + # Sanitizer ![https://github.com/binary-cats/sanitizer/actions](https://github.com/binary-cats/sanitizer/workflows/Laravel/badge.svg) From 2626679af4cfee3fa3c561e3fa18faaefaa06b34 Mon Sep 17 00:00:00 2001 From: Cyrill N Kalita Date: Wed, 2 Apr 2025 10:37:41 -0500 Subject: [PATCH 04/13] Add Laravel 9 support and update PHP dependencies --- .devcontainer/Dockerfile | 29 +++++++++++++++ .devcontainer/devcontainer.bash | 46 ++++++++++++++++++++++++ .devcontainer/devcontainer.json | 27 ++++++++++++++ .gitignore | 1 + composer.json | 6 ++-- src/Laravel/SanitizerServiceProvider.php | 2 +- src/Sanitizer.php | 2 +- 7 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.bash create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..ed2a212 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,29 @@ +# Base image is from Microsoft +FROM mcr.microsoft.com/vscode/devcontainers/base:ubuntu-22.04 + +# Avoid interactive prompts (e.g. tzdata) during installation +ENV DEBIAN_FRONTEND=noninteractive + +RUN mkdir -p /var/www/html + +# Install 8.3 from Ondrej's PPA +RUN apt-get update && apt-get install -y \ + software-properties-common \ + && add-apt-repository ppa:ondrej/php -y \ + && apt-get update && apt-get install -y sqlite3 \ + && apt-get install -y php8.3-cli php8.3-dev \ + php8.3-pgsql php8.3-sqlite3 php8.3-gd \ + php8.3-curl \ + php8.3-imap php8.3-mysql php8.3-mbstring \ + php8.3-xml php8.3-zip php8.3-bcmath php8.3-soap \ + php8.3-intl php8.3-readline \ + php8.3-ldap \ + php8.3-msgpack php8.3-igbinary php8.3-redis php8.3-swoole \ + php8.3-memcached php8.3-pcov php8.3-imagick php8.3-xdebug \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +# Install Composer +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ + && php composer-setup.php --install-dir=/usr/local/bin --filename=composer \ + && php -r "unlink('composer-setup.php');" \ + && composer --version \ No newline at end of file diff --git a/.devcontainer/devcontainer.bash b/.devcontainer/devcontainer.bash new file mode 100644 index 0000000..5d8fe63 --- /dev/null +++ b/.devcontainer/devcontainer.bash @@ -0,0 +1,46 @@ +alias art='php artisan --ansi' +alias tinker='art tinker' +alias format='php vendor/bin/pint' +alias analyze='php vendor/bin/phpstan analyse' +alias test='php vendor/bin/paratest --coverage-html coverage' +alias stf='php vendor/bin/phpunit --filter' + +# commit AI +function commit() { + commitMessage="$*" + + git add . + + if [ "$commitMessage" = "" ]; then + aicommits + return + fi + + eval "git commit -a -m '${commitMessage}'" +} + +# function gfind +function gfind() { + local excludeVendor="--exclude-dir=vendor" # Default to excluding the vendor directory + local searchString="" + local searchPath="./" + + # Process all arguments + for arg in "$@"; do + if [[ "$arg" == "-w" || "$arg" == "--with-vendor" ]]; then + excludeVendor="" # Remove the exclude directive to include vendor + elif [[ -z "$searchString" && "$arg" != -* ]]; then + searchString="$arg" # Set the search string if it's not a flag and is the first non-flag argument + fi + done + + # Check if a search string was provided + if [[ -z "$searchString" ]]; then + echo -e "${RED}Error: Missing required search string.${NC}" + echo -e "${YELLOW}Usage: ${NC}gfind searchString [-w|--with-vendor]" + return 1 + fi + + # Execute grep command + grep --include=\*.php $excludeVendor -rnw $searchPath -e "$searchString" +} \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..f668d69 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,27 @@ +{ + "name": "Laravel Exportify", + "build": { + "dockerfile": "Dockerfile", + "context": "." + }, + "features": {}, + "customizations": { + "vscode": { + "extensions": [ + "bmewburn.vscode-intelephense-client", + "calebporzio.better-phpunit", + "laravel.vscode-laravel", + "mikestead.dotenv", + "ms-azuretools.vscode-docker", + "php.intelephense" + ], + "settings": { + "intelephense.environment.phpVersion": "8.3" + } + } + }, + "remoteUser": "vscode", + "postCreateCommand": "cat ./.devcontainer/devcontainer.bash >> /home/vscode/.bashrc", + "forwardPorts": [], + "portsAttributes": {} + } \ No newline at end of file diff --git a/.gitignore b/.gitignore index 58e6535..9cf4d43 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /vendor/ composer.lock .phpunit.result.cache +.php-cs-fixer.cache \ No newline at end of file diff --git a/composer.json b/composer.json index dae7796..4c2e5ac 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ "email": "cyrill.kalita@gmail.com" }], "require": { - "illuminate/support": "^8.0|^9.0|^10.0|^11.0", - "illuminate/validation": "^8.0|^9.0|^10.0|^11.0", + "illuminate/support": "^12.0", + "illuminate/validation": "^12.0", "nesbot/carbon": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^10.0" + "phpunit/phpunit": "^11.0" }, "autoload": { "psr-4": { diff --git a/src/Laravel/SanitizerServiceProvider.php b/src/Laravel/SanitizerServiceProvider.php index bdcd8e8..16379d9 100644 --- a/src/Laravel/SanitizerServiceProvider.php +++ b/src/Laravel/SanitizerServiceProvider.php @@ -15,7 +15,7 @@ public function register() { // Register the sanitizer factory: $this->app->singleton('sanitizer', function ($app) { - return new Factory; + return new Factory(); }); // Register make request command diff --git a/src/Sanitizer.php b/src/Sanitizer.php index ff070de..bb6351e 100644 --- a/src/Sanitizer.php +++ b/src/Sanitizer.php @@ -145,7 +145,7 @@ protected function applyFilter($rule, $value) if ($filter instanceof Closure) { return call_user_func_array($filter, [$value, $options]); } else { - return (new $filter)->apply($value, $options); + return (new $filter())->apply($value, $options); } } From ece569194a3ed3f3c7c785806502a0ed50a56d3d Mon Sep 17 00:00:00 2001 From: Cyrill N Kalita Date: Wed, 2 Apr 2025 10:41:58 -0500 Subject: [PATCH 05/13] Update PHPUnit configuration and remove unused _PHPUnitShim --- phpunit.xml | 2 +- tests/Filters/CastTest.php | 2 -- tests/_PHPUnitShim.php | 37 ------------------------------------- 3 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 tests/_PHPUnitShim.php diff --git a/phpunit.xml b/phpunit.xml index 1418fc6..9bec3e5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -9,7 +9,7 @@ > - ./tests/ + ./tests/ diff --git a/tests/Filters/CastTest.php b/tests/Filters/CastTest.php index d2f514e..3a153e1 100644 --- a/tests/Filters/CastTest.php +++ b/tests/Filters/CastTest.php @@ -5,8 +5,6 @@ class CastTest extends TestCase { - use _PHPUnitShim; - /** * @param $data * @param $rules diff --git a/tests/_PHPUnitShim.php b/tests/_PHPUnitShim.php deleted file mode 100644 index a314e6d..0000000 --- a/tests/_PHPUnitShim.php +++ /dev/null @@ -1,37 +0,0 @@ -=')) { - trait _PHPUnitShim - { - } -} - -if (version_compare(PHP_VERSION, '7.2.0', '<')) { - trait _PHPUnitShim - { - public function assertIsArray($actual, $message = '') - { - $this->assertInternalType('array', $actual, $message); - } - - public function assertIsBool($actual, $message = '') - { - $this->assertInternalType('bool', $actual, $message); - } - - public function assertIsFloat($actual, $message = '') - { - $this->assertInternalType('float', $actual, $message); - } - - public function assertIsInt($actual, $message = '') - { - $this->assertInternalType('integer', $actual, $message); - } - - public function assertIsString($actual, $message = '') - { - $this->assertInternalType('string', $actual, $message); - } - } -} From 4a2aafc3d1fae53728b2021de353e88b078ee89e Mon Sep 17 00:00:00 2001 From: Cyrill N Kalita Date: Wed, 2 Apr 2025 10:43:26 -0500 Subject: [PATCH 06/13] Update dependencies and minimum stability settings --- UPGRADING.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/UPGRADING.md b/UPGRADING.md index f9c5815..070a88d 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,2 +1,22 @@ # Upgrading +## Version Changes + +### Dependencies +- **illuminate/support**: Updated to version `^12.0` +- **illuminate/validation**: Updated to version `^12.0` +- **nesbot/carbon**: Updated to version `^3.0` +- **phpunit/phpunit**: Updated to version `^11.0` for development. + +### Minimum Stability +- The minimum stability is set to `dev`, which may allow for unstable packages to be installed. Ensure that you are aware of the implications of using development versions. + +## Upgrade Steps +1. **Update Dependencies**: Run `composer update` to install the latest versions of the required packages. +2. **Check for Breaking Changes**: Review the changelogs for `illuminate/support`, `illuminate/validation`, and `nesbot/carbon` for any breaking changes that may affect your application. +3. **Test Your Application**: After updating, run your tests to ensure everything works as expected. Use the command `composer test` to execute your PHPUnit tests. +4. **Review Laravel Configuration**: Ensure that the service provider and facade alias are correctly registered in your Laravel application. + +## Additional Notes +- If you encounter issues, consider checking the documentation for each package for guidance on resolving compatibility problems. + From 4071d8fa5d6b4e6a2439a9e68186e3e2931ec840 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 2 Apr 2025 15:45:09 +0000 Subject: [PATCH 07/13] Apply fixes from StyleCI --- src/Contracts/Filter.php | 4 +-- src/Filters/Capitalize.php | 4 +-- src/Filters/Cast.php | 4 +-- src/Filters/Digit.php | 4 +-- src/Filters/EscapeHTML.php | 4 +-- src/Filters/FilterIf.php | 6 ++-- src/Filters/FormatDate.php | 4 +-- src/Filters/Lowercase.php | 4 +-- src/Filters/StripTags.php | 4 +-- src/Filters/Trim.php | 4 +-- src/Filters/Uppercase.php | 4 +-- src/Laravel/Factory.php | 16 +++++----- src/Laravel/FormRequest.php | 8 ++--- src/Laravel/SanitizesInput.php | 10 +++---- src/Sanitizer.php | 50 ++++++++++++++++---------------- tests/FactoryTest.php | 10 +++---- tests/Filters/CapitalizeTest.php | 4 +-- tests/Filters/CastTest.php | 4 +-- tests/Filters/DigitTest.php | 4 +-- tests/Filters/EscapeHTMLTest.php | 4 +-- tests/Filters/FilterIfTest.php | 4 +-- tests/Filters/FormatDateTest.php | 4 +-- tests/Filters/LowercaseTest.php | 4 +-- tests/Filters/StripTagsTest.php | 4 +-- tests/Filters/TrimTest.php | 4 +-- tests/Filters/UppercaseTest.php | 4 +-- tests/SanitizerTest.php | 14 ++++----- 27 files changed, 97 insertions(+), 97 deletions(-) diff --git a/src/Contracts/Filter.php b/src/Contracts/Filter.php index fbc5f0b..272c82d 100644 --- a/src/Contracts/Filter.php +++ b/src/Contracts/Filter.php @@ -7,8 +7,8 @@ interface Filter /** * Return the result of applying this filter to the given input. * - * @param mixed $value - * @return mixed + * @param mixed $value + * @return mixed */ public function apply($value, $options = []); } diff --git a/src/Filters/Capitalize.php b/src/Filters/Capitalize.php index ccde60c..0b17415 100644 --- a/src/Filters/Capitalize.php +++ b/src/Filters/Capitalize.php @@ -9,8 +9,8 @@ class Capitalize implements Filter /** * Capitalize the given string. * - * @param string $value - * @return string + * @param string $value + * @return string */ public function apply($value, $options = []) { diff --git a/src/Filters/Cast.php b/src/Filters/Cast.php index b7255e8..0a74d8b 100644 --- a/src/Filters/Cast.php +++ b/src/Filters/Cast.php @@ -10,8 +10,8 @@ class Cast implements Filter /** * Capitalize the given string. * - * @param string $value - * @return string + * @param string $value + * @return string */ public function apply($value, $options = []) { diff --git a/src/Filters/Digit.php b/src/Filters/Digit.php index 5b664de..f07b5f4 100644 --- a/src/Filters/Digit.php +++ b/src/Filters/Digit.php @@ -9,8 +9,8 @@ class Digit implements Filter /** * Get only digit characters from the string. * - * @param string $value - * @return string + * @param string $value + * @return string */ public function apply($value, $options = []) { diff --git a/src/Filters/EscapeHTML.php b/src/Filters/EscapeHTML.php index 7dcab26..a7963f0 100644 --- a/src/Filters/EscapeHTML.php +++ b/src/Filters/EscapeHTML.php @@ -9,8 +9,8 @@ class EscapeHTML implements Filter /** * Remove HTML tags and encode special characters from the given string. * - * @param string $value - * @return string + * @param string $value + * @return string */ public function apply($value, $options = []) { diff --git a/src/Filters/FilterIf.php b/src/Filters/FilterIf.php index 33b59cd..93a4306 100644 --- a/src/Filters/FilterIf.php +++ b/src/Filters/FilterIf.php @@ -9,9 +9,9 @@ class FilterIf implements Filter /** * Checks if filters should run if there is value passed that matches. * - * @param array $values - * @param array $options - * @return bool + * @param array $values + * @param array $options + * @return bool */ public function apply($values, $options = []) { diff --git a/src/Filters/FormatDate.php b/src/Filters/FormatDate.php index 676257e..359db11 100644 --- a/src/Filters/FormatDate.php +++ b/src/Filters/FormatDate.php @@ -11,8 +11,8 @@ class FormatDate implements Filter /** * Lowercase the given string. * - * @param string $value - * @return string + * @param string $value + * @return string */ public function apply($value, $options = []) { diff --git a/src/Filters/Lowercase.php b/src/Filters/Lowercase.php index 253e7b8..54f7ebb 100644 --- a/src/Filters/Lowercase.php +++ b/src/Filters/Lowercase.php @@ -9,8 +9,8 @@ class Lowercase implements Filter /** * Lowercase the given string. * - * @param string $value - * @return string + * @param string $value + * @return string */ public function apply($value, $options = []) { diff --git a/src/Filters/StripTags.php b/src/Filters/StripTags.php index 549466d..a60c94b 100644 --- a/src/Filters/StripTags.php +++ b/src/Filters/StripTags.php @@ -9,8 +9,8 @@ class StripTags implements Filter /** * Strip tags from the given string. * - * @param string $value - * @return string + * @param string $value + * @return string */ public function apply($value, $options = []) { diff --git a/src/Filters/Trim.php b/src/Filters/Trim.php index e4d4f66..a524e5b 100644 --- a/src/Filters/Trim.php +++ b/src/Filters/Trim.php @@ -9,8 +9,8 @@ class Trim implements Filter /** * Trims the given string. * - * @param string $value - * @return string + * @param string $value + * @return string */ public function apply($value, $options = []) { diff --git a/src/Filters/Uppercase.php b/src/Filters/Uppercase.php index 762e39a..c6f75e8 100644 --- a/src/Filters/Uppercase.php +++ b/src/Filters/Uppercase.php @@ -9,8 +9,8 @@ class Uppercase implements Filter /** * Lowercase the given string. * - * @param string $value - * @return string + * @param string $value + * @return string */ public function apply($value, $options = []) { diff --git a/src/Laravel/Factory.php b/src/Laravel/Factory.php index a7fe05f..dd452ac 100644 --- a/src/Laravel/Factory.php +++ b/src/Laravel/Factory.php @@ -12,7 +12,7 @@ class Factory /** * List of custom filters. * - * @var array + * @var array */ protected $customFilters; @@ -29,9 +29,9 @@ public function __construct() /** * Create a new Sanitizer instance. * - * @param array $data Data to be sanitized - * @param array $rules Filters to be applied to the given data - * @return Sanitizer + * @param array $data Data to be sanitized + * @param array $rules Filters to be applied to the given data + * @return Sanitizer */ public function make(array $data, array $rules) { @@ -43,11 +43,11 @@ public function make(array $data, array $rules) /** * Add a custom filters to all Sanitizers created with this Factory. * - * @param string $name Name of the filter - * @param mixed $extension Either the full class name of a Filter class implementing the Filter contract, or a Closure. - * @return void + * @param string $name Name of the filter + * @param mixed $extension Either the full class name of a Filter class implementing the Filter contract, or a Closure. + * @return void * - * @throws InvalidArgumentException + * @throws InvalidArgumentException */ public function extend($name, $customFilter) { diff --git a/src/Laravel/FormRequest.php b/src/Laravel/FormRequest.php index c7e9c85..dd90304 100644 --- a/src/Laravel/FormRequest.php +++ b/src/Laravel/FormRequest.php @@ -9,7 +9,7 @@ class FormRequest extends LaravelFormRequest /** * Sanitize input before validating. * - * @return void + * @return void */ public function validate() { @@ -20,7 +20,7 @@ public function validate() /** * Sanitize this request's input. * - * @return void + * @return void */ public function sanitize() { @@ -31,7 +31,7 @@ public function sanitize() /** * Filters to be applied to the input. * - * @return array + * @return array */ public function filters() { @@ -41,7 +41,7 @@ public function filters() /** * Validation rules to be applied to the input. * - * @return array + * @return array */ public function rules() { diff --git a/src/Laravel/SanitizesInput.php b/src/Laravel/SanitizesInput.php index bff5c52..f808537 100644 --- a/src/Laravel/SanitizesInput.php +++ b/src/Laravel/SanitizesInput.php @@ -7,7 +7,7 @@ trait SanitizesInput /** * Sanitize input before validating. * - * @return void + * @return void */ public function validateResolved() { @@ -18,7 +18,7 @@ public function validateResolved() /** * Sanitize this request's input. * - * @return void + * @return void */ public function sanitize() { @@ -30,7 +30,7 @@ public function sanitize() /** * Add custom fields to the Sanitizer. * - * @return void + * @return void */ public function addCustomFilters() { @@ -42,7 +42,7 @@ public function addCustomFilters() /** * Filters to be applied to the input. * - * @return array + * @return array */ public function filters() { @@ -52,7 +52,7 @@ public function filters() /** * Custom Filters to be applied to the input. * - * @return array + * @return array */ public function customFilters() { diff --git a/src/Sanitizer.php b/src/Sanitizer.php index bb6351e..a983e42 100644 --- a/src/Sanitizer.php +++ b/src/Sanitizer.php @@ -13,42 +13,42 @@ class Sanitizer /** * Data to sanitize. * - * @var array + * @var array */ protected $data; /** * Filters to apply. * - * @var array + * @var array */ protected $rules; /** * Available filters as $name => $classPath. * - * @var array + * @var array */ protected $filters = [ - 'capitalize' => \BinaryCats\Sanitizer\Filters\Capitalize::class, - 'cast' => \BinaryCats\Sanitizer\Filters\Cast::class, - 'escape' => \BinaryCats\Sanitizer\Filters\EscapeHTML::class, + 'capitalize' => \BinaryCats\Sanitizer\Filters\Capitalize::class, + 'cast' => \BinaryCats\Sanitizer\Filters\Cast::class, + 'escape' => \BinaryCats\Sanitizer\Filters\EscapeHTML::class, 'format_date' => \BinaryCats\Sanitizer\Filters\FormatDate::class, - 'lowercase' => \BinaryCats\Sanitizer\Filters\Lowercase::class, - 'uppercase' => \BinaryCats\Sanitizer\Filters\Uppercase::class, - 'trim' => \BinaryCats\Sanitizer\Filters\Trim::class, - 'strip_tags' => \BinaryCats\Sanitizer\Filters\StripTags::class, - 'digit' => \BinaryCats\Sanitizer\Filters\Digit::class, - 'filter_if' => \BinaryCats\Sanitizer\Filters\FilterIf::class, + 'lowercase' => \BinaryCats\Sanitizer\Filters\Lowercase::class, + 'uppercase' => \BinaryCats\Sanitizer\Filters\Uppercase::class, + 'trim' => \BinaryCats\Sanitizer\Filters\Trim::class, + 'strip_tags' => \BinaryCats\Sanitizer\Filters\StripTags::class, + 'digit' => \BinaryCats\Sanitizer\Filters\Digit::class, + 'filter_if' => \BinaryCats\Sanitizer\Filters\FilterIf::class, ]; /** * Create a new sanitizer instance. * - * @param array $data - * @param array $rules Rules to be applied to each data attribute - * @param array $filters Available filters for this sanitizer - * @return Sanitizer + * @param array $data + * @param array $rules Rules to be applied to each data attribute + * @param array $filters Available filters for this sanitizer + * @return Sanitizer */ public function __construct(array $data, array $rules, array $customFilters = []) { @@ -60,8 +60,8 @@ public function __construct(array $data, array $rules, array $customFilters = [] /** * Parse a rules array. * - * @param array $rules - * @return array + * @param array $rules + * @return array */ protected function parseRules(array $rules) { @@ -84,8 +84,8 @@ protected function parseRules(array $rules) /** * Parse a rule. * - * @param string|Closure $rule - * @return array|Closure + * @param string|Closure $rule + * @return array|Closure */ protected function parseRule($rule) { @@ -101,8 +101,8 @@ protected function parseRule($rule) /** * Parse a rule string formatted as filterName:option1, option2 into an array formatted as [name => filterName, options => [option1, option2]]. * - * @param string $rule Formatted as 'filterName:option1, option2' or just 'filterName' - * @return array Formatted as [name => filterName, options => [option1, option2]]. Empty array if no filter name was found. + * @param string $rule Formatted as 'filterName:option1, option2' or just 'filterName' + * @return array Formatted as [name => filterName, options => [option1, option2]]. Empty array if no filter name was found. */ protected function parseRuleString($rule) { @@ -123,8 +123,8 @@ protected function parseRuleString($rule) /** * Apply the given filter by its name. * - * @param string|Closure $rule - * @return Filter + * @param string|Closure $rule + * @return Filter */ protected function applyFilter($rule, $value) { @@ -152,7 +152,7 @@ protected function applyFilter($rule, $value) /** * Sanitize the given data. * - * @return array + * @return array */ public function sanitize() { diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 0dec7b3..b7867e1 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -9,12 +9,12 @@ class FactoryTest extends TestCase public function sanitize($data, $rules) { $sanitizer = new Sanitizer($data, $rules, [ - 'capitalize' => \BinaryCats\Sanitizer\Filters\Capitalize::class, - 'escape' => \BinaryCats\Sanitizer\Filters\EscapeHTML::class, + 'capitalize' => \BinaryCats\Sanitizer\Filters\Capitalize::class, + 'escape' => \BinaryCats\Sanitizer\Filters\EscapeHTML::class, 'format_date' => \BinaryCats\Sanitizer\Filters\FormatDate::class, - 'lowercase' => \BinaryCats\Sanitizer\Filters\Lowercase::class, - 'uppercase' => \BinaryCats\Sanitizer\Filters\Uppercase::class, - 'trim' => \BinaryCats\Sanitizer\Filters\Trim::class, + 'lowercase' => \BinaryCats\Sanitizer\Filters\Lowercase::class, + 'uppercase' => \BinaryCats\Sanitizer\Filters\Uppercase::class, + 'trim' => \BinaryCats\Sanitizer\Filters\Trim::class, ]); return $sanitizer->sanitize(); diff --git a/tests/Filters/CapitalizeTest.php b/tests/Filters/CapitalizeTest.php index 279b17e..764a227 100644 --- a/tests/Filters/CapitalizeTest.php +++ b/tests/Filters/CapitalizeTest.php @@ -6,8 +6,8 @@ class CapitalizeTest extends TestCase { /** - * @param $data - * @param $rules + * @param $data + * @param $rules * @return mixed */ public function sanitize($data, $rules) diff --git a/tests/Filters/CastTest.php b/tests/Filters/CastTest.php index 3a153e1..6530366 100644 --- a/tests/Filters/CastTest.php +++ b/tests/Filters/CastTest.php @@ -6,8 +6,8 @@ class CastTest extends TestCase { /** - * @param $data - * @param $rules + * @param $data + * @param $rules * @return mixed */ public function sanitize($data, $rules) diff --git a/tests/Filters/DigitTest.php b/tests/Filters/DigitTest.php index 6adac5b..aac9643 100644 --- a/tests/Filters/DigitTest.php +++ b/tests/Filters/DigitTest.php @@ -6,8 +6,8 @@ class DigitTest extends TestCase { /** - * @param $data - * @param $rules + * @param $data + * @param $rules * @return mixed */ public function sanitize($data, $rules) diff --git a/tests/Filters/EscapeHTMLTest.php b/tests/Filters/EscapeHTMLTest.php index f78edd4..c8b3d2f 100644 --- a/tests/Filters/EscapeHTMLTest.php +++ b/tests/Filters/EscapeHTMLTest.php @@ -6,8 +6,8 @@ class EscapeHTMLTest extends TestCase { /** - * @param $data - * @param $rules + * @param $data + * @param $rules * @return mixed */ public function sanitize($data, $rules) diff --git a/tests/Filters/FilterIfTest.php b/tests/Filters/FilterIfTest.php index 0747b09..acbf4fc 100644 --- a/tests/Filters/FilterIfTest.php +++ b/tests/Filters/FilterIfTest.php @@ -6,8 +6,8 @@ class FilterIfTest extends TestCase { /** - * @param $data - * @param $rules + * @param $data + * @param $rules * @return mixed */ public function sanitize($data, $rules) diff --git a/tests/Filters/FormatDateTest.php b/tests/Filters/FormatDateTest.php index b363d91..f86d84a 100644 --- a/tests/Filters/FormatDateTest.php +++ b/tests/Filters/FormatDateTest.php @@ -6,8 +6,8 @@ class FormatDateTest extends TestCase { /** - * @param $data - * @param $rules + * @param $data + * @param $rules * @return mixed */ public function sanitize($data, $rules) diff --git a/tests/Filters/LowercaseTest.php b/tests/Filters/LowercaseTest.php index 9b7bf76..de91636 100644 --- a/tests/Filters/LowercaseTest.php +++ b/tests/Filters/LowercaseTest.php @@ -6,8 +6,8 @@ class LowercaseTest extends TestCase { /** - * @param $data - * @param $rules + * @param $data + * @param $rules * @return mixed */ public function sanitize($data, $rules) diff --git a/tests/Filters/StripTagsTest.php b/tests/Filters/StripTagsTest.php index 0e0a396..82923b2 100644 --- a/tests/Filters/StripTagsTest.php +++ b/tests/Filters/StripTagsTest.php @@ -6,8 +6,8 @@ class StripTagsTest extends TestCase { /** - * @param $data - * @param $rules + * @param $data + * @param $rules * @return mixed */ public function sanitize($data, $rules) diff --git a/tests/Filters/TrimTest.php b/tests/Filters/TrimTest.php index ac53e33..2fbb770 100644 --- a/tests/Filters/TrimTest.php +++ b/tests/Filters/TrimTest.php @@ -6,8 +6,8 @@ class TrimTest extends TestCase { /** - * @param $data - * @param $rules + * @param $data + * @param $rules * @return mixed */ public function sanitize($data, $rules) diff --git a/tests/Filters/UppercaseTest.php b/tests/Filters/UppercaseTest.php index 711b291..3489859 100644 --- a/tests/Filters/UppercaseTest.php +++ b/tests/Filters/UppercaseTest.php @@ -6,8 +6,8 @@ class UppercaseTest extends TestCase { /** - * @param $data - * @param $rules + * @param $data + * @param $rules * @return mixed */ public function sanitize($data, $rules) diff --git a/tests/SanitizerTest.php b/tests/SanitizerTest.php index e54ebad..993c783 100644 --- a/tests/SanitizerTest.php +++ b/tests/SanitizerTest.php @@ -6,8 +6,8 @@ class SanitizerTest extends TestCase { /** - * @param $data - * @param $rules + * @param $data + * @param $rules * @return mixed */ public function sanitize($data, $rules) @@ -56,23 +56,23 @@ public function test_array_filters() public function test_wildcard_filters() { $data = [ - 'name' => [ + 'name' => [ 'first' => ' John ', - 'last' => ' Doe ', + 'last' => ' Doe ', ], 'address' => [ 'street' => ' Some street ', - 'city' => ' New York ', + 'city' => ' New York ', ], ]; $rules = [ - 'name.*' => 'trim', + 'name.*' => 'trim', 'address.city' => 'trim', ]; $data = $this->sanitize($data, $rules); $sanitized = [ - 'name' => ['first' => 'John', 'last' => 'Doe'], + 'name' => ['first' => 'John', 'last' => 'Doe'], 'address' => ['street' => ' Some street ', 'city' => 'New York'], ]; From 009d993c2e1ce8d5e1f97daaf734a8a6d7fe7366 Mon Sep 17 00:00:00 2001 From: "Cyrill N. Kalita" Date: Fri, 20 Mar 2026 17:30:47 -0500 Subject: [PATCH 08/13] Update PHP version to 8.4 and Laravel dependencies --- .devcontainer/Dockerfile | 18 +++++++++--------- .devcontainer/devcontainer.json | 2 +- composer.json | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index ed2a212..138d4dc 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -11,15 +11,15 @@ RUN apt-get update && apt-get install -y \ software-properties-common \ && add-apt-repository ppa:ondrej/php -y \ && apt-get update && apt-get install -y sqlite3 \ - && apt-get install -y php8.3-cli php8.3-dev \ - php8.3-pgsql php8.3-sqlite3 php8.3-gd \ - php8.3-curl \ - php8.3-imap php8.3-mysql php8.3-mbstring \ - php8.3-xml php8.3-zip php8.3-bcmath php8.3-soap \ - php8.3-intl php8.3-readline \ - php8.3-ldap \ - php8.3-msgpack php8.3-igbinary php8.3-redis php8.3-swoole \ - php8.3-memcached php8.3-pcov php8.3-imagick php8.3-xdebug \ + && apt-get install -y php8.4-cli php8.4-dev \ + php8.4-pgsql php8.4-sqlite3 php8.4-gd \ + php8.4-curl \ + php8.4-imap php8.4-mysql php8.4-mbstring \ + php8.4-xml php8.4-zip php8.4-bcmath php8.4-soap \ + php8.4-intl php8.4-readline \ + php8.4-ldap \ + php8.4-msgpack php8.4-igbinary php8.4-redis php8.4-swoole \ + php8.4-memcached php8.4-pcov php8.4-imagick php8.4-xdebug \ && apt-get clean && rm -rf /var/lib/apt/lists/* # Install Composer diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f668d69..36cf6e8 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -16,7 +16,7 @@ "php.intelephense" ], "settings": { - "intelephense.environment.phpVersion": "8.3" + "intelephense.environment.phpVersion": "8.4" } } }, diff --git a/composer.json b/composer.json index 4c2e5ac..c5b927d 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ "email": "cyrill.kalita@gmail.com" }], "require": { - "illuminate/support": "^12.0", - "illuminate/validation": "^12.0", + "illuminate/support": "^12.0|^13.0", + "illuminate/validation": "^12.0|^13.0", "nesbot/carbon": "^3.0" }, "require-dev": { From 4abdc578034b9d3c94065eb248081b5dc59e5f08 Mon Sep 17 00:00:00 2001 From: "Cyrill N. Kalita" Date: Fri, 20 Mar 2026 17:35:20 -0500 Subject: [PATCH 09/13] Add automated PR merging and changelog updating workflows --- .github/workflows/dependabot-auto-merge.yml | 33 +++++++++++++++++++++ .github/workflows/update-changelog.yml | 32 ++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 .github/workflows/dependabot-auto-merge.yml create mode 100644 .github/workflows/update-changelog.yml diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml new file mode 100644 index 0000000..a4ebb3e --- /dev/null +++ b/.github/workflows/dependabot-auto-merge.yml @@ -0,0 +1,33 @@ +name: dependabot-auto-merge +on: pull_request_target + +permissions: + pull-requests: write + contents: write + +jobs: + dependabot: + runs-on: ubuntu-latest + timeout-minutes: 5 + if: ${{ github.actor == 'dependabot[bot]' }} + steps: + + - name: Dependabot metadata + id: metadata + uses: dependabot/fetch-metadata@v2.5.0 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + + - name: Auto-merge Dependabot PRs for semver-minor updates + if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + + - name: Auto-merge Dependabot PRs for semver-patch updates + if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 0000000..c6c3e24 --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,32 @@ +name: "Update Changelog" + +on: + release: + types: [released] + +permissions: + contents: write + +jobs: + update: + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + ref: main + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.name }} + release-notes: ${{ github.event.release.body }} + + - name: Commit updated CHANGELOG + uses: stefanzweifel/git-auto-commit-action@v7 + with: + branch: main + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md From 9c245ea59f412349b16a759397451be74cad8037 Mon Sep 17 00:00:00 2001 From: "Cyrill N. Kalita" Date: Fri, 20 Mar 2026 17:43:15 -0500 Subject: [PATCH 10/13] Update project name to "Sanitizer" and add Dependabot configuration --- .devcontainer/devcontainer.json | 2 +- .github/dependabot.yml | 19 ++++++++++++++++++ .github/dependabot.yml:Zone.Identifier | Bin 0 -> 25 bytes .../workflows/{laravel.yml => run-tests.yml} | 0 README.md | 7 +++---- 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/dependabot.yml:Zone.Identifier rename .github/workflows/{laravel.yml => run-tests.yml} (100%) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 36cf6e8..fa94e81 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,5 +1,5 @@ { - "name": "Laravel Exportify", + "name": "Sanitizer", "build": { "dockerfile": "Dockerfile", "context": "." diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..39b1580 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,19 @@ +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + labels: + - "dependencies" + + - package-ecosystem: "composer" + directory: "/" + schedule: + interval: "weekly" + labels: + - "dependencies" diff --git a/.github/dependabot.yml:Zone.Identifier b/.github/dependabot.yml:Zone.Identifier new file mode 100644 index 0000000000000000000000000000000000000000..d6c1ec682968c796b9f5e9e080cc6f674b57c766 GIT binary patch literal 25 dcma!!%Fjy;DN4*MPD?F{<>dl#JyUFr831@K2x Date: Fri, 20 Mar 2026 17:51:31 -0500 Subject: [PATCH 11/13] Refactor test annotations in test classes --- .github/dependabot.yml:Zone.Identifier | Bin 25 -> 0 bytes src/Filters/EscapeHTML.php | 2 +- tests/FactoryTest.php | 4 ++++ tests/Filters/CapitalizeTest.php | 9 +++------ tests/SanitizerTest.php | 11 ++++++++--- 5 files changed, 16 insertions(+), 10 deletions(-) delete mode 100644 .github/dependabot.yml:Zone.Identifier diff --git a/.github/dependabot.yml:Zone.Identifier b/.github/dependabot.yml:Zone.Identifier deleted file mode 100644 index d6c1ec682968c796b9f5e9e080cc6f674b57c766..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25 dcma!!%Fjy;DN4*MPD?F{<>dl#JyUFr831@K2xsanitize(); } + #[Test] public function test_custom_closure_filter() { $factory = new Factory; @@ -38,6 +40,7 @@ public function test_custom_closure_filter() $this->assertEquals(sha1('TEST'), $newData['name']); } + #[Test] public function test_custom_class_filter() { $factory = new Factory; @@ -54,6 +57,7 @@ public function test_custom_class_filter() $this->assertEquals('TESTTEST', $newData['name']); } + #[Test] public function test_replace_filter() { $factory = new Factory; diff --git a/tests/Filters/CapitalizeTest.php b/tests/Filters/CapitalizeTest.php index 764a227..52146a4 100644 --- a/tests/Filters/CapitalizeTest.php +++ b/tests/Filters/CapitalizeTest.php @@ -1,6 +1,7 @@ sanitize(); } - /** - * @test - */ + #[Test] public function it_capitalizes_strings() { $result = $this->sanitize(['name' => ' jon snow 145'], ['name' => 'capitalize']); $this->assertEquals(' Jon Snow 145', $result['name']); } - /** - * @test - */ + #[Test] public function it_capitalizes_special_characters() { $result = $this->sanitize(['name' => 'Τάχιστη αλώπηξ'], ['name' => 'capitalize']); diff --git a/tests/SanitizerTest.php b/tests/SanitizerTest.php index 993c783..103d3b3 100644 --- a/tests/SanitizerTest.php +++ b/tests/SanitizerTest.php @@ -1,6 +1,7 @@ sanitize(); } + #[Test] public function test_combine_filters() { $data = [ @@ -29,6 +31,7 @@ public function test_combine_filters() $this->assertEquals('Hello Everybody', $data['name']); } + #[Test] public function test_input_unchanged_if_no_filter() { $data = [ @@ -41,6 +44,7 @@ public function test_input_unchanged_if_no_filter() $this->assertEquals(' HellO EverYboDy ', $data['name']); } + #[Test] public function test_array_filters() { $data = [ @@ -53,6 +57,7 @@ public function test_array_filters() $this->assertEquals('Hello Everybody', $data['name']); } + #[Test] public function test_wildcard_filters() { $data = [ @@ -79,9 +84,7 @@ public function test_wildcard_filters() $this->assertEquals($sanitized, $data); } - /** - * @test - */ + #[Test] public function it_throws_exception_if_non_existing_filter() { $this->expectException(InvalidArgumentException::class); @@ -94,6 +97,7 @@ public function it_throws_exception_if_non_existing_filter() $data = $this->sanitize($data, $rules); } + #[Test] public function test_it_should_only_sanitize_passed_data() { $data = [ @@ -112,6 +116,7 @@ public function test_it_should_only_sanitize_passed_data() $this->assertEquals(1, count($data)); } + #[Test] public function test_closure_rule() { $data = [ From c3cfa8e3dbe5d5725cb6db46fc48832f04f7add2 Mon Sep 17 00:00:00 2001 From: "Cyrill N. Kalita" Date: Fri, 20 Mar 2026 17:53:53 -0500 Subject: [PATCH 12/13] Refactor casting logic using match expression --- src/Filters/Cast.php | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/Filters/Cast.php b/src/Filters/Cast.php index 0a74d8b..3112f47 100644 --- a/src/Filters/Cast.php +++ b/src/Filters/Cast.php @@ -15,30 +15,17 @@ class Cast implements Filter */ public function apply($value, $options = []) { - $type = isset($options[0]) ? $options[0] : null; - switch ($type) { - case 'int': - case 'integer': - return (int) $value; - case 'real': - case 'float': - case 'double': - return (float) $value; - case 'string': - return (string) $value; - case 'bool': - case 'boolean': - return (bool) $value; - case 'object': - return is_array($value) ? (object) $value : json_decode($value, false); - case 'array': - return json_decode($value, true); - case 'collection': - $array = is_array($value) ? $value : json_decode($value, true); + $type = $options[0] ?? null; - return new Collection($array); - default: - throw new \InvalidArgumentException("Wrong Sanitizer casting format: {$type}."); - } + return match ($type) { + 'int', 'integer' => (int) $value, + 'real', 'float', 'double' => (float) $value, + 'string' => (string) $value, + 'bool', 'boolean' => (bool) $value, + 'object' => is_array($value) ? (object) $value : json_decode($value, false), + 'array' => json_decode($value, true), + 'collection' => new Collection(is_array($value) ? $value : json_decode($value, true)), + default => throw new \InvalidArgumentException("Wrong Sanitizer casting format: {$type}."), + }; } } From dbcc7412ff4621624c40b74bd8c9151bb652938b Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 20 Mar 2026 22:55:56 +0000 Subject: [PATCH 13/13] Apply fixes from StyleCI --- src/Filters/Cast.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Filters/Cast.php b/src/Filters/Cast.php index 3112f47..14b8aa5 100644 --- a/src/Filters/Cast.php +++ b/src/Filters/Cast.php @@ -17,15 +17,15 @@ public function apply($value, $options = []) { $type = $options[0] ?? null; - return match ($type) { - 'int', 'integer' => (int) $value, - 'real', 'float', 'double' => (float) $value, - 'string' => (string) $value, - 'bool', 'boolean' => (bool) $value, - 'object' => is_array($value) ? (object) $value : json_decode($value, false), - 'array' => json_decode($value, true), - 'collection' => new Collection(is_array($value) ? $value : json_decode($value, true)), - default => throw new \InvalidArgumentException("Wrong Sanitizer casting format: {$type}."), + return match ($type) { + 'int', 'integer' => (int) $value, + 'real', 'float', 'double' => (float) $value, + 'string' => (string) $value, + 'bool', 'boolean' => (bool) $value, + 'object' => is_array($value) ? (object) $value : json_decode($value, false), + 'array' => json_decode($value, true), + 'collection' => new Collection(is_array($value) ? $value : json_decode($value, true)), + default => throw new \InvalidArgumentException("Wrong Sanitizer casting format: {$type}."), }; } }