Skip to content

Commit

Permalink
Merge branch 'main' into feat/improve-code-quality-rector
Browse files Browse the repository at this point in the history
  • Loading branch information
shakaran authored Apr 16, 2024
2 parents cadaec9 + 43d7cbf commit 5ffc0cf
Show file tree
Hide file tree
Showing 155 changed files with 30,597 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
CI:
runs-on: ubuntu-latest
env:
PHP_INI_VALUES: assert.exception=1, zend.assertions=1
PHP_INI_VALUES: assert.exception=1, zend.assertions=1, apc.enable_cli=1
strategy:
fail-fast: false
matrix:
Expand All @@ -21,6 +21,7 @@ jobs:
tools: composer:v2, phpcs
coverage: xdebug
ini-values: ${{ env.PHP_INI_VALUES }}
extensions: apcu

- name: Install dependencies with composer
run: composer update --no-ansi --no-interaction --no-progress
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

- [#332](https://github.com/Shopify/shopify-api-php/pull/332) [Patch] Avoid writing to system temporary directory when an API deprecation is encountered

## v5.4.0 - 2024-04-08

- [#333](https://github.com/Shopify/shopify-api-php/pull/333) [Minor] Adding support for 2024-04 API version

## v5.3.0 - 2024-01-10

- [#318](https://github.com/Shopify/shopify-api-php/pull/318) [Minor] Adding support for 2024-01 API version
Expand Down
7 changes: 7 additions & 0 deletions composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"symbol-whitelist" : [
"apcu_enabled",
"apcu_fetch",
"apcu_store"
]
}
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,21 @@
"guzzlehttp/guzzle": "^7.0",
"guzzlehttp/psr7": "^2.0",
"psr/http-client": "^1.0",
"psr/http-message": "^1.0",
"psr/http-message": "^1.0 || ^2.0",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"ramsey/uuid": "^4.1"
},
"require-dev": {
"ext-apcu": "*",
"ergebnis/composer-normalize": "^2.30",
"maglnet/composer-require-checker": "^3.0 || ^4.0",
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "^3.6"
},
"suggest": {
"ext-apcu": "Log fewer API deprecation warnings"
},
"autoload": {
"psr-4": {
"Shopify\\": "src/"
Expand Down
8 changes: 5 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/ApiVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class ApiVersion
/** @var string */
public const JANUARY_2024 = "2024-01";
/** @var string */
public const LATEST = self::JANUARY_2024;
public const APRIL_2024 = "2024-04";
/** @var string */
public const LATEST = self::APRIL_2024;

private static $ALL_VERSIONS = [
self::UNSTABLE,
Expand All @@ -37,6 +39,7 @@ class ApiVersion
self::JULY_2023,
self::OCTOBER_2023,
self::JANUARY_2024,
self::APRIL_2024,
];

public static function isValid(string $version): bool
Expand Down
32 changes: 21 additions & 11 deletions src/Clients/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class Http
public const DATA_TYPE_GRAPHQL = 'application/graphql';

private const RETRIABLE_STATUS_CODES = [429, 500];
private const DEPRECATION_ALERT_SECONDS = 60;
private const DEPRECATION_ALERT_SECONDS = 3600;

private readonly string $domain;

private int $lastApiDeprecationWarning = 0;

public function __construct(string $domain)
{
$this->domain = $domain;
Expand Down Expand Up @@ -275,27 +277,35 @@ private function logApiDeprecation(string $url, string $reason): void
*/
private function shouldLogApiDeprecation(): bool
{
$warningFilePath = $this->getApiDeprecationTimestampFilePath();
if (function_exists('apcu_enabled') && apcu_enabled()) {
$apcuKey = 'shopify/shopify-api/last-api-deprecation-warning';
} else {
$apcuKey = null;
}

$lastWarning = null;
if (file_exists($warningFilePath)) {
$lastWarning = (int)(file_get_contents($warningFilePath));
if ($this->lastApiDeprecationWarning === 0 && $apcuKey) {
$this->lastApiDeprecationWarning = (int) apcu_fetch($apcuKey);
}

if (time() - $lastWarning < self::DEPRECATION_ALERT_SECONDS) {
$result = false;
} else {
$result = true;
file_put_contents($warningFilePath, time());
$secondsSinceLastAlert = time() - $this->lastApiDeprecationWarning;
if ($secondsSinceLastAlert < self::DEPRECATION_ALERT_SECONDS) {
return false;
}

$this->lastApiDeprecationWarning = time();

if ($apcuKey) {
apcu_store($apcuKey, $this->lastApiDeprecationWarning, self::DEPRECATION_ALERT_SECONDS);
}

return $result;
return true;
}

/**
* Fetches the path to the file holding the timestamp of the last API deprecation warning we logged.
*
* @codeCoverageIgnore This is mocked in tests so we don't use real files
* @deprecated 5.4.1 This method is no longer used internally.
*/
public function getApiDeprecationTimestampFilePath(): string
{
Expand Down
101 changes: 101 additions & 0 deletions src/Rest/Admin2024_04/AbandonedCheckout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

/***********************************************************************************************************************
* This file is auto-generated. If you have an issue, please create a GitHub issue. *
***********************************************************************************************************************/

declare(strict_types=1);

namespace Shopify\Rest\Admin2024_04;

use Shopify\Auth\Session;
use Shopify\Rest\Base;

/**
* @property string|null $abandoned_checkout_url
* @property array|null $billing_address
* @property bool|null $buyer_accepts_marketing
* @property bool|null $buyer_accepts_sms_marketing
* @property string|null $cart_token
* @property string|null $closed_at
* @property string|null $completed_at
* @property string|null $created_at
* @property Currency|null $currency
* @property Customer|null $customer
* @property string|null $customer_locale
* @property int|null $device_id
* @property DiscountCode[]|null $discount_codes
* @property string|null $email
* @property string|null $gateway
* @property int|null $id
* @property string|null $landing_site
* @property array|null $line_items
* @property int|null $location_id
* @property string|null $note
* @property string|null $phone
* @property string|null $presentment_currency
* @property string|null $referring_site
* @property array|null $shipping_address
* @property array|null $shipping_lines
* @property string|null $sms_marketing_phone
* @property string|null $source_name
* @property string|null $subtotal_price
* @property array|null $tax_lines
* @property bool|null $taxes_included
* @property string|null $token
* @property string|null $total_discounts
* @property string|null $total_duties
* @property string|null $total_line_items_price
* @property string|null $total_price
* @property string|null $total_tax
* @property int|null $total_weight
* @property string|null $updated_at
* @property int|null $user_id
*/
class AbandonedCheckout extends Base
{
public static string $API_VERSION = "2024-04";
protected static array $HAS_ONE = [
"currency" => Currency::class,
"customer" => Customer::class
];
protected static array $HAS_MANY = [
"discount_codes" => DiscountCode::class
];
protected static array $PATHS = [
["http_method" => "get", "operation" => "checkouts", "ids" => [], "path" => "checkouts.json"],
["http_method" => "get", "operation" => "checkouts", "ids" => [], "path" => "checkouts.json"]
];

/**
* @param Session $session
* @param array $urlIds
* @param mixed[] $params Allowed indexes:
* since_id,
* created_at_min,
* created_at_max,
* updated_at_min,
* updated_at_max,
* status,
* limit
*
* @return array|null
*/
public static function checkouts(
Session $session,
array $urlIds = [],
array $params = []
): ?array {
$response = parent::request(
"get",
"checkouts",
$session,
[],
$params,
[],
);

return $response->getDecodedBody();
}

}
47 changes: 47 additions & 0 deletions src/Rest/Admin2024_04/AccessScope.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/***********************************************************************************************************************
* This file is auto-generated. If you have an issue, please create a GitHub issue. *
***********************************************************************************************************************/

declare(strict_types=1);

namespace Shopify\Rest\Admin2024_04;

use Shopify\Auth\Session;
use Shopify\Rest\Base;

/**
* @property string $handle
* @property array[]|null $access_scopes
*/
class AccessScope extends Base
{
public static string $API_VERSION = "2024-04";
protected static array $HAS_ONE = [];
protected static array $HAS_MANY = [];
protected static ?string $CUSTOM_PREFIX = "/admin/oauth";
protected static array $PATHS = [
["http_method" => "get", "operation" => "get", "ids" => [], "path" => "access_scopes.json"]
];

/**
* @param Session $session
* @param array $urlIds
* @param mixed[] $params
*
* @return AccessScope[]
*/
public static function all(
Session $session,
array $urlIds = [],
array $params = []
): array {
return parent::baseFind(
$session,
[],
$params,
);
}

}
Loading

0 comments on commit 5ffc0cf

Please sign in to comment.