Skip to content

Commit

Permalink
Require Composer v2 and run on PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor committed Jan 23, 2021
1 parent 0335205 commit 28ced5a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 0 additions & 10 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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\\<int, array\\<string, int\\|string\\>\\> but returns array\\<int, mixed\\>\\.$#"
count: 1
path: src/EnvatoConfig.php
28 changes: 12 additions & 16 deletions src/EnvatoApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Composer\Config;
use Composer\Factory;
use Composer\IO\IOInterface;
use Composer\Util\RemoteFilesystem;
use Composer\Util\HttpDownloader;

class EnvatoApi
{
Expand All @@ -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'];
Expand All @@ -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'];
Expand Down
14 changes: 14 additions & 0 deletions src/EnvatoPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 28ced5a

Please sign in to comment.