json icon indicating copy to clipboard operation
json copied to clipboard

[Help/Contributor needed] Major release & refactoring for PHP8 support

Open samijnih opened this issue 3 years ago • 1 comments

  • PHPUnit ^9.3 supports PHP 7.3, 7.4 and 8.0
  • PHPUnit ^8.5.12 supports PHP >=7.2

I can't figure how to add PHP 8 support alongside PHP 5 | 7.(0-2)

The idea is to make a new major release only for people using PHP >=7.3 by using PHPUnit ^9.3 But I imagine we can also use PHPUnit 8.5.12 for 7.2, 7.3, 7.4 and 8.0

People still using PHP 5.x should stay on the v1.x release

Changes

  • added return type on every test
  • replaced string FQCN in tests with import
  • refactored classes using the old validator to use the JsonSchema validator
  • removed some tests against PHP < 7.3
  • removed src/InvalidSchemaException.php
  • removed src/JsonValidator.php
  • replaced JsonValidator with JsonSchema\Validator

Need check

  • JsonSchema provides its own implementation for checking validation against a given schema. It also raises an exception called InvalidSchemaException
  • InvalidSchemaException seems not to be raised by default with JsonSchema\Validator. I think we must explicitly use the Constraint::CHECK_MODE_EXCEPTIONS for that (https://github.com/justinrainbow/json-schema#configuration-options)
  • I've removed tests against given invalid schema string path as it does not raise an exception on the third party validator by default
  • A question needs to be answered: who has the responsibility to convert a given string schema path to a compliant object for JsonSchema\Validator? I've dropped that responsibility in the package for now. You can check the example bellow from the JsonSchema README
// Validate
$validator = new JsonSchema\Validator;
$validator->validate($data, (object)['$ref' => 'file://' . realpath('schema.json')]);

https://github.com/justinrainbow/json-schema#basic-usage

Note

I stop working on this pull request.

I wanted to add support for PHP 8 as I've created an issue which has remained unanswered.

The thing is that this library is using a very old release of JsonSchema and it has not been upgraded since 2016. JsonSchema is now at its fifth major release.

Feel free to progress this work. I'm done for now and I'll stop be using this library in my projects.

samijnih avatar Mar 04 '21 11:03 samijnih

Personally, on the JsonSchema\Validator change, I think it should be made on a separated PR.

machitgarha avatar Nov 06 '21 23:11 machitgarha