Skip to content

Commit cf1a872

Browse files
committed
v4
1 parent a61cdf4 commit cf1a872

26 files changed

+689
-478
lines changed

.github/workflows/ci.yml

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,80 +2,86 @@ name: CI
22

33
on:
44
push:
5+
branches: [main]
56
pull_request:
7+
branches: [main]
68
release:
7-
types:
8-
- published
9+
types: [published]
910

1011
jobs:
11-
php-tests:
12-
runs-on: ${{ matrix.os }}
12+
################################################################################
13+
# LINTING JOB: Runs once to check for code style issues.
14+
################################################################################
15+
lint:
16+
name: "PHP Linting"
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout Code
20+
uses: actions/checkout@v6
21+
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: 8.4
26+
tools: composer:v2
27+
28+
- name: Cache Composer dependencies
29+
uses: actions/cache@v5
30+
with:
31+
path: vendor
32+
key: ubuntu-php-8.4-lint-${{ hashFiles('**/composer.lock') }}
33+
restore-keys: |
34+
ubuntu-php-8.4-lint-
35+
36+
- name: Install Dependencies
37+
uses: ramsey/composer-install@v4
38+
39+
- name: Execute linter (Pint)
40+
run: composer lint
41+
42+
################################################################################
43+
# TESTING JOB: Runs tests and handles coverage reporting.
44+
################################################################################
45+
tests:
46+
name: "P${{ matrix.php }} | L${{ matrix.laravel }}"
47+
needs: lint
48+
runs-on: ubuntu-latest
1349

1450
strategy:
1551
fail-fast: false
1652
matrix:
1753
php: [8.4]
18-
laravel: [10.*, 11.*, 12.*]
19-
os: [ubuntu-latest]
20-
coverage: [none]
21-
include:
22-
- php: 8.4
23-
laravel: 12.*
24-
os: ubuntu-latest
25-
coverage: xdebug
26-
27-
name: '[P${{ matrix.php }}] [L${{ matrix.laravel }}] [${{ matrix.coverage }}]'
54+
laravel: [12.*] # Matrix is kept to L12 due to PHP 8.4 requirement
2855

2956
steps:
3057
- name: Checkout Code
31-
uses: actions/checkout@v5
58+
uses: actions/checkout@v6
3259

3360
- name: Setup PHP
3461
uses: shivammathur/setup-php@v2
3562
with:
3663
php-version: ${{ matrix.php }}
37-
extensions: mbstring json openssl xdebug
38-
ini-values: memory_limit=-1
39-
tools: composer:v2
40-
coverage: ${{ matrix.coverage }}
41-
env:
42-
update: true
64+
extensions: mbstring, json, openssl, iconv
65+
coverage: xdebug
4366

44-
- name: Cache dependencies
45-
uses: actions/cache@v4
67+
- name: Cache Composer dependencies
68+
uses: actions/cache@v5
4669
with:
4770
path: vendor
48-
key: ${{ matrix.os }}-${{ matrix.php }}-${{ matrix.laravel }}-vendor-${{ hashFiles('**/composer.lock') }}
71+
key: ubuntu-${{ matrix.php }}-${{ matrix.laravel }}-${{ hashFiles('**/composer.lock') }}
72+
restore-keys: |
73+
ubuntu-${{ matrix.php }}-${{ matrix.laravel }}-
4974
5075
- name: Install Dependencies
51-
uses: ramsey/composer-install@v3
76+
uses: ramsey/composer-install@v4
5277

53-
- name: Execute tests (Unit and Feature tests) via PHPUnit
54-
if: matrix.coverage == 'none'
55-
run: composer test
56-
57-
- name: Run code style check
58-
if: matrix.coverage == 'xdebug'
59-
run: composer check
60-
61-
- name: Run code analyze
62-
if: matrix.coverage == 'xdebug'
63-
run: composer analyze
64-
65-
- name: Execute tests (Unit and Feature tests) via PHPUnit
66-
if: matrix.coverage == 'xdebug'
78+
- name: Execute tests (PHPUnit)
6779
run: composer test-ci
6880

69-
- name: Upload coverage reports to Codecov
70-
if: matrix.coverage == 'xdebug'
71-
uses: codecov/codecov-action@v5
72-
with:
73-
token: ${{ secrets.CODECOV_TOKEN }}
74-
slug: ${{ github.repository }}
81+
- name: Upload coverage to Codecov
82+
if: matrix.php == '8.4' && matrix.laravel == '12.*'
83+
uses: codecov/codecov-action@v6
7584

7685
- name: Upload test results to Codecov
77-
if: matrix.coverage == 'xdebug'
78-
uses: codecov/test-results-action@v1
79-
with:
80-
token: ${{ secrets.CODECOV_TOKEN }}
81-
slug: ${{ github.repository }}
86+
if: matrix.php == '8.4' && matrix.laravel == '12.*'
87+
uses: codecov/test-results-action@v2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/.idea
22
/build
33
/vendor
4+
/coverage
45
composer.phar
56
composer.lock
67
.DS_Store
78
.phpunit*
9+
coverage.xml

composer.json

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,24 @@
2121
"role": "Developer"
2222
}
2323
],
24+
"funding": [
25+
{
26+
"type": "github",
27+
"url": "https://github.com/sponsors/aporat"
28+
}
29+
],
2430
"require": {
2531
"php": "^8.4",
32+
"ext-iconv": "*",
2633
"ext-json": "*",
27-
"illuminate/support": "^10.0 || ^11.0 || ^12.0",
34+
"ext-mbstring": "*",
35+
"illuminate/support": "^12.0",
2836
"nesbot/carbon": "^2.72 || ^3.0"
2937
},
3038
"require-dev": {
3139
"laravel/pint": "^1.21",
32-
"orchestra/testbench": "^8.0 || ^9.0 || ^10.0",
33-
"phpstan/phpstan": "^2.1",
40+
"orchestra/testbench": "^10.0",
41+
"phpstan/phpstan": "^2.0",
3442
"phpunit/phpunit": "^12.0"
3543
},
3644
"autoload": {
@@ -46,10 +54,7 @@
4654
"config": {
4755
"sort-packages": true,
4856
"optimize-autoloader": true,
49-
"preferred-install": "dist",
50-
"allow-plugins": {
51-
"dealerdirect/phpcodesniffer-composer-installer": true
52-
}
57+
"preferred-install": "dist"
5358
},
5459
"extra": {
5560
"laravel": {
@@ -62,10 +67,16 @@
6267
}
6368
},
6469
"scripts": {
65-
"test": "phpunit --colors=always",
66-
"test-ci": "phpunit --colors=always --coverage-text --coverage-clover coverage.xml --log-junit junit.xml",
67-
"check": "vendor/bin/pint --test",
68-
"analyze": "phpstan analyse src --level=7 --memory-limit=-1"
70+
"test": "phpunit --no-coverage",
71+
"test-ci": "phpunit --coverage-clover coverage.xml --log-junit junit.xml",
72+
"lint": "vendor/bin/pint --test",
73+
"format": "vendor/bin/pint",
74+
"analyse": "phpstan analyse src --level=8",
75+
"qa": [
76+
"@lint",
77+
"@analyse",
78+
"@test"
79+
]
6980
},
7081
"support": {
7182
"issues": "https://github.com/aporat/laravel-filter-var/issues",

config/filter-var.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
<?php
22

3-
namespace Aporat\FilterVar;
3+
/**
4+
* Configuration for the Laravel Filter Var package.
5+
*
6+
* Here you can register your own custom filter classes. When you add a filter here,
7+
* it becomes available to use in your application just like the built-in filters.
8+
*/
9+
return [
410

5-
return
6-
[
7-
'custom_filters' => [],
8-
];
11+
/*
12+
|--------------------------------------------------------------------------
13+
| Custom Filters
14+
|--------------------------------------------------------------------------
15+
|
16+
| This array allows you to register your own custom filter classes.
17+
| The key should be the alias you want to use for the filter (e.g., 'JsonDecode'),
18+
| and the value should be the fully qualified class name of your filter implementation.
19+
|
20+
| All custom filters must implement the Aporat\FilterVar\Contracts\Filter interface.
21+
|
22+
*/
23+
'custom_filters' => [
24+
// Example:
25+
// 'JsonDecode' => \App\Filters\JsonDecodeFilter::class,
26+
],
27+
28+
];

phpunit.xml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.0/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
5-
cacheDirectory=".phpunit.cache"
65
colors="true"
7-
executionOrder="depends,defects"
8-
shortenArraysForExportThreshold="10"
9-
beStrictAboutOutputDuringTests="true"
10-
displayDetailsOnPhpunitDeprecations="true"
11-
failOnPhpunitDeprecation="true"
12-
failOnRisky="true"
13-
failOnWarning="true">
6+
cacheDirectory=".phpunit.cache">
7+
148
<testsuites>
15-
<testsuite name="default">
9+
<testsuite name="Package Test Suite">
1610
<directory>tests</directory>
1711
</testsuite>
1812
</testsuites>
1913

20-
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
14+
<source>
2115
<include>
2216
<directory>src</directory>
2317
</include>
2418
</source>
19+
20+
<php>
21+
<env name="APP_ENV" value="testing"/>
22+
<env name="CACHE_DRIVER" value="array"/>
23+
<env name="SESSION_DRIVER" value="array"/>
24+
<env name="QUEUE_CONNECTION" value="sync"/>
25+
</php>
26+
27+
<coverage>
28+
<report>
29+
<clover outputFile="coverage.xml"/>
30+
<html outputDirectory="coverage"/>
31+
</report>
32+
</coverage>
33+
34+
<logging>
35+
<junit outputFile="junit.xml"/>
36+
</logging>
37+
2538
</phpunit>

src/Contracts/Filter.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
namespace Aporat\FilterVar\Contracts;
44

5+
/**
6+
* Defines the contract for a filter that transforms a value.
7+
*
8+
* @template TValue The type of the value being passed into the filter.
9+
* @template TFiltered The type of the value after the filter is applied.
10+
*/
511
interface Filter
612
{
713
/**
814
* Apply the filter to the given value.
915
*
10-
* @param mixed $value The value to filter
16+
* @param TValue $value The value to filter
1117
* @param array<int, mixed> $options Optional configuration for the filter
1218
* @return mixed The filtered value
1319
*/

src/Facades/FilterVar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* @see \Aporat\FilterVar\FilterVar
1616
*/
17-
class FilterVar extends Facade
17+
final class FilterVar extends Facade
1818
{
1919
/**
2020
* Get the registered name of the component in the service container.

0 commit comments

Comments
 (0)