-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
8,210 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Coverage | ||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
run-coverage: | ||
name: Run Tests with Coverage | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Composer | ||
uses: php-actions/composer@v5 | ||
with: | ||
php_extensions: xdebug | ||
- name: Run Tests | ||
env: | ||
XDEBUG_MODE: coverage | ||
run: vendor/bin/phpunit | ||
- name: Commit Coverage | ||
uses: timkrase/[email protected] | ||
with: | ||
report: clover.xml | ||
report_type: clover | ||
coverage_badge_path: ./.github/coverage-badge.svg | ||
repo_token: ${{ secrets.GH_ACCESS_TOKEN }} | ||
push_badge: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Develop Branch | ||
on: | ||
push: | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
run-tests: | ||
name: Tests | ||
uses: ./.github/workflows/test.yml | ||
run-coverage: | ||
name: Coverage | ||
uses: ./.github/workflows/coverage.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Main Branch | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
run-tests: | ||
name: Tests | ||
uses: ./.github/workflows/test.yml | ||
run-coverage: | ||
name: Coverage | ||
uses: ./.github/workflows/coverage.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: Pull Request | ||
on: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
name: Run Tests | ||
uses: ./.github/workflows/test.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Test | ||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: ["7.4", "8.0", "8.1"] | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Composer | ||
uses: php-actions/composer@v5 | ||
with: | ||
php_version: ${{ matrix.php }} | ||
- name: Run Tests | ||
run: vendor/bin/phpunit --no-coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/vendor/ | ||
.env | ||
.phpunit.result.cache | ||
tests/html-coverage | ||
clover.xml | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,62 @@ | ||
# laravel-strict-types-validation | ||
A validator to require strict types on request data | ||
# Strict Types Form Request Validation | ||
|
||
![Tests](https://github.com/nwilging/laravel-strict-types-validation/actions/workflows/main-branch.yml/badge.svg?branch=main) | ||
![Coverage](./.github/coverage-badge.svg) | ||
[![Latest Stable Version](http://poser.pugx.org/nwilging/laravel-strict-types-validation/v)](https://packagist.org/packages/nwilging/laravel-strict-types-validation) | ||
[![License](http://poser.pugx.org/nwilging/laravel-strict-types-validation/license)](https://packagist.org/packages/nwilging/laravel-strict-types-validation) | ||
[![Total Downloads](http://poser.pugx.org/nwilging/laravel-strict-types-validation/downloads)](https://packagist.org/packages/nwilging/laravel-strict-types-validation) | ||
|
||
Ensures incoming form request data is a certain datatype. | ||
|
||
--- | ||
|
||
### About | ||
|
||
While Laravel includes many useful validation rules out of the box, [it lacks the ability to validate _data type_ as well | ||
as _content type_](https://laravel.com/docs/9.x/validation#rule-integer). There have been a [couple](https://github.com/laravel/framework/issues/18918) | ||
[complaints](https://github.com/laravel/ideas/issues/1719) about this over the years, but due to the versatile nature of | ||
Laravel, it doesn't seem likely that validation rules such as `integer` or `boolean` will begin validating that the data | ||
is actually of the desired type. | ||
|
||
This package provides a way for you to require the incoming data to be of a given type, such as `int`, `bool`, `float`, etc. | ||
|
||
--- | ||
|
||
# Installation | ||
|
||
### Pre Requisites | ||
1. Laravel v8+ | ||
2. PHP 7.4+ | ||
|
||
### Install with Composer | ||
|
||
``` | ||
composer require nwilging/laravel-strict-types-validation | ||
``` | ||
|
||
--- | ||
|
||
# Usage | ||
|
||
When constructing validation rules, simply add `type:<desired type>` to the validation rules string/array. | ||
|
||
``` | ||
$rules = [ | ||
'id' => 'required|type:int', # This will require the incoming `id` to be an integer. | ||
]; | ||
``` | ||
|
||
### Failure Messages | ||
|
||
The failure message format is: | ||
``` | ||
The :attribute must be of type :type | ||
``` | ||
|
||
Where `attribute` is the attribute being validated (`id` from the above example) and `type` is the desired type to validate | ||
against (`int` in the above example). | ||
|
||
If the above example failed, we would receive this message: | ||
``` | ||
The id must be of type int | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "nwilging/laravel-strict-types-validation", | ||
"description": "A validator for laravel to require strict types in form request data", | ||
"type": "library", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"Nwilging\\LaravelStrictValidation\\": "src/", | ||
"Nwilging\\LaravelStrictValidationTests\\": "tests/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Nick Wilging", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.4", | ||
"laravel/framework": ">=8" | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Nwilging\\LaravelStrictValidation\\Providers\\LaravelStrictValidationProvider" | ||
] | ||
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.5", | ||
"mockery/mockery": "^1.5", | ||
"squizlabs/php_codesniffer": "^3.6", | ||
"dealerinspire/laravel-coding-standard": "^2.0", | ||
"orchestra/testbench": "^7.5" | ||
} | ||
} |
Oops, something went wrong.