Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ vendor
build
#A library must not provide a composer.lock file
composer.lock

# Demo app excluded dirs
features/demo_app/var/

#Phpunit
.phpunit.result.cache
6 changes: 5 additions & 1 deletion .remarkrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"plugins": [
"remark-preset-lint-consistent",
"remark-preset-lint-recommended"
"remark-preset-lint-recommended",
[
"remark-lint-list-item-indent",
"space"
]
]
}
1 change: 0 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ build:
variables:
CI: 'true'
TEST_OUTPUT_STYLE: 'pretty'
COMPOSER_OPTIONS: '--optimize-autoloader'
COVERAGE_OUTPUT_STYLE: 'clover'
COVERAGE_CLOVER_FILE_PATH: 'build/coverage/clover.xml'
PHPCS_DISABLE_WARNING: 'true'
Expand Down
6 changes: 3 additions & 3 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ include:
Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
professional setting

## Our Responsibilities

Expand Down
32 changes: 19 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
# Contributing

## Getting Started
* Fork, then clone the repo:

* Fork, then clone the repo:

```bash
git clone [email protected]:your-username/php-jsonrpc-params-symfony-validator-sdk.git
````
```

* Make sure everything goes well:

* Make sure everything goes well:
```bash
make build
make test
```

* Make your changes (Add/Update tests according to your changes).
* Make sure tests are still green:
* Make your changes (Add/Update tests according to your changes).
* Make sure tests are still green:

```bash
make test
```

* To check code coverage, launch
* To check code coverage, launch

```bash
make coverage
```

* Push to your fork and [submit a pull request](https://github.com/yoanm/php-jsonrpc-params-symfony-validator-sdk/compare/).
* Wait for feedback or merge.
* Push to your fork and [submit a pull request](https://github.com/yoanm/php-jsonrpc-params-symfony-validator-sdk/compare/).
* Wait for feedback or merge.

Some stuff that will increase your pull request's acceptance:

Some stuff that will increase your pull request's acceptance:
* Write tests.
* Follow PSR-2 coding style.
* Write good commit messages.
* Do not rebase or squash your commits when a review has been made.
* Write tests.
* Follow PSR-2 coding style.
* Write good commit messages.
* Do not rebase or squash your commits when a review has been made.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,13 @@ scrutinizer-behat:
create-build-directories:
mkdir -p ${PHPUNIT_COVERAGE_DIRECTORY} ${BEHAT_COVERAGE_DIRECTORY} ${REPORTS_DIRECTORY}

.PHONY: configure-dev-env
configure-dev-env:
npm install --global remark-cli remark-preset-lint-consistent remark-preset-lint-recommended remark-lint-list-item-indent

.PHONY: lint-markdown
lint-markdown:
npx remark . --output

.PHONY: build install configure test test-unit test-functional codestyle create-build-directories scrutinizer-behat scrutinizer-phpunit
.DEFAULT: build
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# JSON-RPC params symfony validator

[![License](https://img.shields.io/github/license/yoanm/php-jsonrpc-params-symfony-validator-sdk.svg)](https://github.com/yoanm/php-jsonrpc-params-symfony-validator-sdk)
[![Code size](https://img.shields.io/github/languages/code-size/yoanm/php-jsonrpc-params-symfony-validator-sdk.svg)](https://github.com/yoanm/php-jsonrpc-params-symfony-validator-sdk)
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github\&repo=yoanm/php-jsonrpc-params-symfony-validator-sdk)](https://dependabot.com)
![Dependabot Status](https://flat.badgen.net/github/dependabot/yoanm/php-jsonrpc-params-symfony-validator-sdk)
![Last commit](https://badgen.net/github/last-commit/yoanm/php-jsonrpc-params-symfony-validator-sdk)

[![Scrutinizer Build Status](https://img.shields.io/scrutinizer/build/g/yoanm/php-jsonrpc-params-symfony-validator-sdk.svg?label=Scrutinizer\&logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-validator-sdk/build-status/master)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/yoanm/php-jsonrpc-params-symfony-validator-sdk/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-validator-sdk/?branch=master)
Expand All @@ -14,7 +16,6 @@
[![Latest Stable Version](https://img.shields.io/packagist/v/yoanm/jsonrpc-params-symfony-validator-sdk.svg)](https://packagist.org/packages/yoanm/jsonrpc-params-symfony-validator-sdk)
[![Packagist PHP version](https://img.shields.io/packagist/php-v/yoanm/jsonrpc-params-symfony-validator-sdk.svg)](https://packagist.org/packages/yoanm/jsonrpc-params-symfony-validator-sdk)


Simple JSON-RPC params validator that use Symfony validator component

See [yoanm/symfony-jsonrpc-params-validator](https://github.com/yoanm/symfony-jsonrpc-params-validator) for automatic dependency injection.
Expand All @@ -23,23 +24,27 @@ See [yoanm/jsonrpc-params-symfony-constraint-doc-sdk](https://github.com/yoanm/p

## Versions

* Symfony v3/4 - PHP >=7.1 : `^v1.0`
* Symfony v4/5 - PHP >=7.2 : `^v2.0`
* Symfony v3/4 - PHP >=7.1 : `^v1.0`

* Symfony v4/5 - PHP >=7.2 : `^v2.0`

⚠️⚠️ `v0.2.0` is replaced by `v1.0.0` ! ⚠️⚠️
⚠️⚠️ `v0.2.0` is replaced by `v1.0.0` ! ⚠️⚠️

⚠️⚠️ `v0.3.0` was badly taggued, used `v2.0.0` instead ! ⚠️⚠️
⚠️⚠️ `v0.3.0` was badly taggued, used `v2.0.0` instead ! ⚠️⚠️

* Symfony v4.4/5.4/6.0 - PHP ^8.0 : `^v2.1`
* Symfony v4.4/5.4/6.0 - PHP ^8.0 : `^v2.1`

## How to use

In order to be validated, a JSON-RPC method must :
* Implements `JsonRpcMethodInterface` from [`yoanm/jsonrpc-server-sdk`](https://github.com/yoanm/php-jsonrpc-server-sdk)
* Implements [`MethodWithValidatedParamsInterface`](./src/Infra/JsonRpcParamsValidator.php)
In order to be validated, a JSON-RPC method must :

* Implements `JsonRpcMethodInterface` from [`yoanm/jsonrpc-server-sdk`](https://github.com/yoanm/php-jsonrpc-server-sdk)
* Implements [`MethodWithValidatedParamsInterface`](./src/Infra/JsonRpcParamsValidator.php)

### With [`yoanm/jsonrpc-server-sdk`](https://github.com/yoanm/php-jsonrpc-server-sdk)
Create the validator and inject it into request handler :

Create the validator and inject it into request handler :

```php
$requestHandler->setMethodParamsValidator(
new JsonRpcParamsValidator(
Expand All @@ -50,7 +55,8 @@ $requestHandler->setMethodParamsValidator(

Then you can send JSON-RPC request string to the server and any method wich implements `MethodWithValidatedParamsInterface` will be validated.

### Standalone
### Standalone

```php
use Symfony\Component\Validator\ValidatorBuilder;
use Yoanm\JsonRpcParamsSymfonyValidator\Infra\JsonRpcParamsValidator;
Expand All @@ -65,6 +71,7 @@ $violationList = $paramsValidator->validate($jsonRpcRequest, $jsonRpcMethod);
```

### Params validation example

```php
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Collection;
Expand Down Expand Up @@ -98,7 +105,9 @@ class MethodExample implements JsonRpcMethodInterface, MethodWithValidatedParams
```

### Violations format

Each violations will have the following format :

```php
[
'path' => 'property_path',
Expand All @@ -108,4 +117,5 @@ Each violations will have the following format :
```

## Contributing

See [contributing note](./CONTRIBUTING.md)
39 changes: 18 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupStaticAttributes="false"
colors="true"
processIsolation="false"
Expand All @@ -23,23 +22,21 @@
forceCoversAnnotation="true"

bootstrap="vendor/autoload.php"
>
<listeners>
<listener class="Yoanm\PhpUnitExtended\Listener\YoanmTestsStrategyListener"/>
</listeners>

<testsuites>
<testsuite name="functional">
<directory>tests/Functional/*</directory>
</testsuite>
<testsuite name="technical">
<directory>tests/Technical/*</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
>
<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
<listeners>
<listener class="Yoanm\PhpUnitExtended\Listener\YoanmTestsStrategyListener"/>
</listeners>
<testsuites>
<testsuite name="functional">
<directory>tests/Functional</directory>
</testsuite>
<testsuite name="technical">
<directory>tests/Technical</directory>
</testsuite>
</testsuites>
</phpunit>