Skip to content

Commit

Permalink
Add return types to match newer Composer versions (#10)
Browse files Browse the repository at this point in the history
* Fixed PHPStan errors in EnvatoAPI.php null checking

* updated return type of the methods in EnvatoPackage class

* Raise min. Composer version

---------

Co-authored-by: Daniel Taki @DannyTaki 
Co-authored-by: Viktor Szépe <[email protected]>
  • Loading branch information
DannyTaki and szepeviktor authored Feb 16, 2023
1 parent 20d8f3a commit 502bfd5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"composer/installers": "^1.10"
},
"require-dev": {
"composer/composer": "^2.0.8",
"phpstan/phpstan": "^0.12"
"composer/composer": "^2.3.0",
"phpstan/phpstan": "^1.9"
},
"suggest": {
"szepeviktor/composer-theme-fusion": "Composer plugin for ThemeFusion"
Expand All @@ -34,5 +34,10 @@
"scripts": {
"lint": "find src/ -type f -name '*.php' -print0|xargs -0 -L1 -P4 -- php -l -f",
"analyze": "phpstan analyze"
},
"config": {
"allow-plugins": {
"composer/installers": true
}
}
}
12 changes: 6 additions & 6 deletions src/EnvatoApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public function getVersion(int $itemId): string

// TODO HTTP 429 response. Included in this response is a HTTP header Retry-After
if ($response->getStatusCode() === 200) {
$versionData = \json_decode($response->getBody(), true);
$versionData = \json_decode($response->getBody() ?? '', true);
// TODO Check JSON
if (\array_key_exists('wordpress_theme_latest_version', $versionData)) {
if (is_array($versionData) && \array_key_exists('wordpress_theme_latest_version', $versionData)) {
return $versionData['wordpress_theme_latest_version'];
}
if (\array_key_exists('wordpress_plugin_latest_version', $versionData)) {
if (is_array($versionData) && \array_key_exists('wordpress_plugin_latest_version', $versionData)) {
return $versionData['wordpress_plugin_latest_version'];
}
}
Expand All @@ -62,12 +62,12 @@ public function getDownloadUrl(int $itemId): string

// TODO HTTP 429 response. Included in this response is a HTTP header Retry-After
if ($response->getStatusCode() === 200) {
$urlData = \json_decode($response->getBody(), true);
$urlData = \json_decode($response->getBody() ?? '', true);
// TODO Check JSON
if (\array_key_exists('wordpress_theme', $urlData)) {
if (is_array($urlData) && \array_key_exists('wordpress_theme', $urlData)) {
return $urlData['wordpress_theme'];
}
if (\array_key_exists('wordpress_plugin', $urlData)) {
if (is_array($urlData) && \array_key_exists('wordpress_plugin', $urlData)) {
return $urlData['wordpress_plugin'];
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/EnvatoPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public function getType(): string
/**
* {@inheritDoc}
*/
public function getDistType()
public function getDistType(): string
{
return 'zip';
}

/**
* {@inheritDoc}
*/
public function getVersion()
public function getVersion(): string
{
if ($this->version !== '0.0.0.0') {
return $this->version;
Expand All @@ -75,7 +75,7 @@ public function getVersion()
/**
* {@inheritDoc}
*/
public function getPrettyVersion()
public function getPrettyVersion(): string
{
if ($this->prettyVersion !== '0.0.0') {
return $this->prettyVersion;
Expand Down

0 comments on commit 502bfd5

Please sign in to comment.