From 28ced5ab26e72571cb5cb374deaf035463602d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Sat, 23 Jan 2021 13:07:21 +0000 Subject: [PATCH] Require Composer v2 and run on PHP 8 --- composer.json | 8 ++++---- phpstan.neon.dist | 10 ---------- src/EnvatoApi.php | 28 ++++++++++++---------------- src/EnvatoPlugin.php | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/composer.json b/composer.json index 739b00b..c9d9d97 100644 --- a/composer.json +++ b/composer.json @@ -12,12 +12,12 @@ ], "license": "MIT", "require": { - "php": ">=7.1", - "composer-plugin-api": "^1.1", - "composer/installers": "^1.8" + "php": "^7.4 || ^8.0", + "composer-plugin-api": "^2.0", + "composer/installers": "^1.10" }, "require-dev": { - "composer/composer": "^1.8", + "composer/composer": "^2.0.8", "phpstan/phpstan": "^0.12" }, "suggest": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 04d5c05..200d200 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,13 +2,3 @@ parameters: level: max paths: - src/ - ignoreErrors: - - - message: "#^Parameter \\#1 \\$json of function json_decode expects string, bool\\|string given\\.$#" - count: 2 - path: src/EnvatoApi.php - - - - message: "#^Method SzepeViktor\\\\Composer\\\\Envato\\\\EnvatoConfig\\:\\:getPackageList\\(\\) should return array\\\\> but returns array\\\\.$#" - count: 1 - path: src/EnvatoConfig.php diff --git a/src/EnvatoApi.php b/src/EnvatoApi.php index 5ec7d13..505f6cc 100644 --- a/src/EnvatoApi.php +++ b/src/EnvatoApi.php @@ -7,7 +7,7 @@ use Composer\Config; use Composer\Factory; use Composer\IO\IOInterface; -use Composer\Util\RemoteFilesystem; +use Composer\Util\HttpDownloader; class EnvatoApi { @@ -20,28 +20,26 @@ class EnvatoApi protected $token; /** - * @var RemoteFilesystem + * @var HttpDownloader */ - protected $remoteFilesystem; + protected $httpDownloader; public function __construct(IOInterface $io, Config $config, string $token) { - $this->remoteFilesystem = Factory::createRemoteFilesystem($io, $config); + $this->httpDownloader = Factory::createHttpDownloader($io, $config); $this->token = $token; } public function getVersion(int $itemId): string { - $responseBody = $this->remoteFilesystem->getContents( - self::API_DOMAIN, + $response = $this->httpDownloader->get( self::API_BASE_URL . '/market/catalog/item-version?' . \http_build_query(['id' => $itemId]), - false, - ['http' => ['header' => ['Authorization: Bearer ' . $this->token]]] + ['header' => ['Authorization: Bearer ' . $this->token]] ); // TODO HTTP 429 response. Included in this response is a HTTP header Retry-After - if ($this->remoteFilesystem->findStatusCode($this->remoteFilesystem->getLastHeaders()) === 200) { - $versionData = \json_decode($responseBody, true); + if ($response->getStatusCode() === 200) { + $versionData = \json_decode($response->getBody(), true); // TODO Check JSON if (\array_key_exists('wordpress_theme_latest_version', $versionData)) { return $versionData['wordpress_theme_latest_version']; @@ -57,16 +55,14 @@ public function getVersion(int $itemId): string public function getDownloadUrl(int $itemId): string { - $responseBody = $this->remoteFilesystem->getContents( - self::API_DOMAIN, + $response = $this->httpDownloader->get( self::API_BASE_URL . '/market/buyer/download?' . \http_build_query(['item_id' => $itemId]), - false, - ['http' => ['header' => ['Authorization: Bearer ' . $this->token]]] + ['header' => ['Authorization: Bearer ' . $this->token]] ); // TODO HTTP 429 response. Included in this response is a HTTP header Retry-After - if ($this->remoteFilesystem->findStatusCode($this->remoteFilesystem->getLastHeaders()) === 200) { - $urlData = \json_decode($responseBody, true); + if ($response->getStatusCode() === 200) { + $urlData = \json_decode($response->getBody(), true); // TODO Check JSON if (\array_key_exists('wordpress_theme', $urlData)) { return $urlData['wordpress_theme']; diff --git a/src/EnvatoPlugin.php b/src/EnvatoPlugin.php index ca17ca8..49ab205 100644 --- a/src/EnvatoPlugin.php +++ b/src/EnvatoPlugin.php @@ -49,6 +49,20 @@ public function activate(Composer $composer, IOInterface $io): void $rm->addRepository($this->generateRepository()); } + /** + * @return void + */ + public function deactivate(Composer $composer, IOInterface $io) + { + } + + /** + * @return void + */ + public function uninstall(Composer $composer, IOInterface $io) + { + } + protected function generateRepository(): ArrayRepository { $api = $this->api;