Skip to content

Commit

Permalink
Move JSON validation to derived class.
Browse files Browse the repository at this point in the history
  • Loading branch information
srmklive committed Sep 27, 2023
1 parent 9a8f5f8 commit 9f0768d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<exclude>
<file>src/PayPalFacadeAccessor.php</file>
<file>src/Traits/PayPalVerifyIPN.php</file>
<file>src/Services/Str.php</file>
<directory suffix=".php">src/Facades/</directory>
<directory suffix=".php">src/Providers/</directory>
</exclude>
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml.dist.php72
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<directory suffix=".php">src/</directory>
<exclude>
<file>src/PayPalFacadeAccessor.php</file>
<file suffix=".php">src/Traits/PayPalVerifyIPN.php</file>
<file>src/Traits/PayPalVerifyIPN.php</file>
<file>src/Services/Str.php</file>
<directory suffix=".php">src/Facades/</directory>
<directory suffix=".php">src/Providers/</directory>
</exclude>
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist.php8
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<exclude>
<file>src/PayPalFacadeAccessor.php</file>
<file>src/Traits/PayPalVerifyIPN.php</file>
<file>src/Services/Str.php</file>
<directory suffix=".php">src/Facades/</directory>
<directory suffix=".php">src/Providers/</directory>
</exclude>
Expand Down
34 changes: 34 additions & 0 deletions src/Services/Str.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Srmklive\PayPal\Services;

use GuzzleHttp\Utils;

class Str extends \Illuminate\Support\Str
{
/**
* Determine if a given value is valid JSON.
*
* @param mixed $value
*
* @return bool
*/
public static function isJson($value): bool
{
if (!is_string($value)) {
return false;
}

if (function_exists('json_validate')) {
return json_validate($value, 512);
}

try {
Utils::jsonDecode($value, true, 512, 4194304);
} catch (\JsonException $jsonException) {
return false;
}

return true;
}
}
2 changes: 1 addition & 1 deletion src/Traits/PayPalHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Exception\ClientException as HttpClientException;
use GuzzleHttp\Utils;
use Illuminate\Support\Str;
use Psr\Http\Message\StreamInterface;
use RuntimeException;
use Srmklive\PayPal\Services\Str;

trait PayPalHttpClient
{
Expand Down

0 comments on commit 9f0768d

Please sign in to comment.