Skip to content

Commit

Permalink
Remove justinrainbow/json-schema usage to fix pronamic/pronamic-pay…
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Sep 11, 2023
1 parent 6f57d11 commit b4d2e66
Show file tree
Hide file tree
Showing 11 changed files with 0 additions and 106 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"require": {
"php": ">=8.0",
"ext-json": "*",
"justinrainbow/json-schema": "^5.2",
"pronamic/wp-http": "^1.1",
"pronamic/wp-number": "^1.1",
"pronamic/wp-money": "^2.0"
Expand Down
12 changes: 0 additions & 12 deletions src/Amount.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
use InvalidArgumentException;
use JsonSerializable;
use stdClass;
use JsonSchema\Constraints\Constraint;
use JsonSchema\Validator;
use Pronamic\WordPress\Money\Money;

/**
Expand Down Expand Up @@ -91,16 +89,6 @@ public static function from_json( $json ) {
throw new InvalidArgumentException( 'JSON value must be an object.' );
}

$validator = new Validator();

$validator->validate(
$json,
(object) [
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/amount.json' ),
],
Constraint::CHECK_MODE_EXCEPTIONS
);

return self::from_object( $json );

Check failure on line 92 in src/Amount.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Parameter #1 $value of static method Pronamic\WordPress\Mollie\Amount::from_object() expects stdClass, object given.
}

Expand Down
11 changes: 0 additions & 11 deletions src/Chargeback.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,8 @@ public function get_amount() {
* @link https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback
* @param object $json JSON object.
* @return Chargeback
* @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid.
*/
public static function from_json( $json ) {
$validator = new \JsonSchema\Validator();

$validator->validate(
$json,
(object) [
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/chargeback.json' ),
],
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
);

$object_access = new ObjectAccess( $json );

$chargeback = new Chargeback(
Expand Down
13 changes: 0 additions & 13 deletions src/Line.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

namespace Pronamic\WordPress\Mollie;

use JsonSchema\Constraints\Constraint;
use JsonSchema\Exception\InvalidArgumentException;
use JsonSchema\Validator;
use JsonSerializable;
use Pronamic\WordPress\Number\Number;
use stdClass;
Expand Down Expand Up @@ -248,16 +245,6 @@ public static function from_json( $json ) {
throw new InvalidArgumentException( 'JSON value must be an object.' );

Check failure on line 245 in src/Line.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Instantiated class Pronamic\WordPress\Mollie\InvalidArgumentException not found.

Check failure on line 245 in src/Line.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Throwing object of an unknown class Pronamic\WordPress\Mollie\InvalidArgumentException.
}

$validator = new Validator();

$validator->validate(
$json,
(object) [
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/line.json' ),
],
Constraint::CHECK_MODE_EXCEPTIONS
);

return self::from_object( $json );

Check failure on line 248 in src/Line.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Parameter #1 $value of static method Pronamic\WordPress\Mollie\Line::from_object() expects stdClass, object given.
}

Expand Down
11 changes: 0 additions & 11 deletions src/Mandate.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,8 @@ class Mandate extends BaseResource {
*
* @param object $json JSON object.
* @return self
* @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid.
*/
public static function from_json( $json ) {
$validator = new \JsonSchema\Validator();

$validator->validate(
$json,
(object) [
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/mandate.json' ),
],
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
);

$object_access = new ObjectAccess( $json );

$mandate = new Mandate(
Expand Down
11 changes: 0 additions & 11 deletions src/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,8 @@ public function get_status(): string {
* @link https://docs.mollie.com/reference/v2/orders-api/get-order
* @param object $json JSON object.
* @return Order
* @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid.
*/
public static function from_json( $json ) {
$validator = new \JsonSchema\Validator();

$validator->validate(
$json,
(object) [
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/order.json' ),
],
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
);

$object_access = new ObjectAccess( $json );

$order = new Order( $object_access->get_property( 'id' ) );
Expand Down
3 changes: 0 additions & 3 deletions src/OrderRefundLineRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

namespace Pronamic\WordPress\Mollie;

use JsonSchema\Constraints\Constraint;
use JsonSchema\Exception\InvalidArgumentException;
use JsonSchema\Validator;
use JsonSerializable;
use stdClass;

Expand Down
11 changes: 0 additions & 11 deletions src/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,19 +421,8 @@ public function get_metadata() {
* @link https://docs.mollie.com/reference/v2/payments-api/get-payment
* @param object $json JSON object.
* @return Payment
* @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid.
*/
public static function from_json( $json ) {
$validator = new \JsonSchema\Validator();

$validator->validate(
$json,
(object) [
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/payment.json' ),
],
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
);

$object_access = new ObjectAccess( $json );

$payment = new Payment(
Expand Down
11 changes: 0 additions & 11 deletions src/PaymentDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,12 @@ class PaymentDetails {
* @param string $method Payment method.
* @param object|null $json JSON object.
* @return PaymentDetails|null
* @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid.
*/
public static function from_json( $method, $json ) {
if ( null === $json ) {
return null;
}

$validator = new \JsonSchema\Validator();

$validator->validate(
$json,
(object) [
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/payment-details.json' ),
],
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
);

$details = new PaymentDetails();

foreach ( $json as $key => $value ) {

Check failure on line 32 in src/PaymentDetails.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Argument of an invalid type object supplied for foreach, only iterables are supported.
Expand Down
11 changes: 0 additions & 11 deletions src/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,8 @@ public function get_created_at() {
* @link https://docs.mollie.com/reference/v2/refunds-api/get-refund
* @param object $json JSON object.
* @return Refund
* @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid.
*/
public static function from_json( $json ) {
$validator = new \JsonSchema\Validator();

$validator->validate(
$json,
(object) [
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/refund.json' ),
],
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
);

$object_access = new ObjectAccess( $json );

$refund = new Refund(
Expand Down
11 changes: 0 additions & 11 deletions src/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,8 @@ class Shipment extends BaseResource {
* @link https://docs.mollie.com/reference/v2/orders-api/get-shipment
* @param object $json JSON object.
* @return Shipment
* @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid.
*/
public static function from_json( $json ) {
$validator = new \JsonSchema\Validator();

$validator->validate(
$json,
(object) [
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/shipment.json' ),
],
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
);

$object_access = new ObjectAccess( $json );

$shipment = new Shipment( $object_access->get_property( 'id' ) );
Expand Down

1 comment on commit b4d2e66

@rvdsteege
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@remcotolsma some PHPStan issues introduced with this commit ⚠️

Please sign in to comment.