diff --git a/composer.json b/composer.json index ec418cf..ca70c1d 100644 --- a/composer.json +++ b/composer.json @@ -15,13 +15,13 @@ "php": "^7.4|^8.0", "ext-json": "*", "psr/http-client": "~1.0.1", - "psr/http-message": "~1.0.1", - "guzzlehttp/psr7": "^1.8.4|^2.4.0" + "psr/http-message": "~1.0.1|~2.0.0", + "guzzlehttp/psr7": "^1.8.4|^2.7.0" }, "require-dev": { - "guzzlehttp/guzzle": "~7.4.5", - "phpunit/phpunit": "~9.3.8|~8.5.15", - "vimeo/psalm": "^4.15", + "guzzlehttp/guzzle": "~7.9.0", + "phpunit/phpunit": "~11.5.0|~8.5.0", + "vimeo/psalm": "^4.15|^6.4", "squizlabs/php_codesniffer": "^3.6" }, "autoload" : { diff --git a/src/Appendix/AreaCode.php b/src/Appendix/AreaCode.php index eaee958..2373adf 100644 --- a/src/Appendix/AreaCode.php +++ b/src/Appendix/AreaCode.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Appendix; +/** + * @psalm-suppress UnusedClass + */ final class AreaCode { public static function getAreaCodes(): array diff --git a/src/Appendix/CampaignOptStatus.php b/src/Appendix/CampaignOptStatus.php index 67c35db..bf7f44a 100644 --- a/src/Appendix/CampaignOptStatus.php +++ b/src/Appendix/CampaignOptStatus.php @@ -3,6 +3,9 @@ namespace Promopult\TikTokMarketingApi\Appendix; +/** + * @psalm-suppress UnusedClass + */ final class CampaignOptStatus { public const ENABLED = 'ENABLED'; diff --git a/src/Appendix/CampaignSecondaryStatus.php b/src/Appendix/CampaignSecondaryStatus.php index 522ec2b..8eb511a 100644 --- a/src/Appendix/CampaignSecondaryStatus.php +++ b/src/Appendix/CampaignSecondaryStatus.php @@ -8,6 +8,7 @@ * Class CampaignSecondaryStatus * * @discard + * @psalm-suppress UnusedClass */ final class CampaignSecondaryStatus { diff --git a/src/Appendix/Currency.php b/src/Appendix/Currency.php index a006635..e5a8386 100644 --- a/src/Appendix/Currency.php +++ b/src/Appendix/Currency.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Appendix; +/** + * @psalm-suppress UnusedClass + */ final class Currency { public static function getCurrencies(): array diff --git a/src/Appendix/Industry.php b/src/Appendix/Industry.php index fa5b0b1..e0cdca6 100644 --- a/src/Appendix/Industry.php +++ b/src/Appendix/Industry.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Appendix; +/** + * @psalm-suppress UnusedClass + */ final class Industry { public static function getIndustries(): array diff --git a/src/Appendix/RegionIDs.php b/src/Appendix/RegionIDs.php index 7eedceb..89525bc 100644 --- a/src/Appendix/RegionIDs.php +++ b/src/Appendix/RegionIDs.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Appendix; +/** + * @psalm-suppress UnusedClass + */ final class RegionIDs { public const TYPE_DMA = 'DMA'; @@ -1496,6 +1499,9 @@ public static function getRegionsList(): array foreach (self::JSON as $items) { $ids = array_column($items, 'id'); $items_with_ids = array_combine($ids, $items); + if ($items_with_ids === false) { + throw new \RuntimeException('Regions list is empty.'); + } self::$region_cache = self::$region_cache + $items_with_ids; } return self::$region_cache; diff --git a/src/Appendix/Timezone.php b/src/Appendix/Timezone.php index 2525a51..41b398c 100644 --- a/src/Appendix/Timezone.php +++ b/src/Appendix/Timezone.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Appendix; +/** + * @psalm-suppress UnusedClass + */ final class Timezone { public static function getTimezones(): array diff --git a/src/Client.php b/src/Client.php index bdadb8e..6069554 100644 --- a/src/Client.php +++ b/src/Client.php @@ -22,6 +22,9 @@ * @property Service\Creatives $creatives * @property Service\Images $images * @property Service\Video $video + * + * * @psalm-suppress UnusedClass + * */ final class Client implements ServiceFactoryInterface { diff --git a/src/Enumeration/AdvertiserBillingType.php b/src/Enumeration/AdvertiserBillingType.php index c8df799..61c4ade 100644 --- a/src/Enumeration/AdvertiserBillingType.php +++ b/src/Enumeration/AdvertiserBillingType.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Enumeration; +/** + * @psalm-suppress UnusedClass + */ final class AdvertiserBillingType { public const TRANS_TYPE_TRANSFER = 'TRANS_TYPE_TRANSFER'; // Transfer diff --git a/src/Enumeration/AdvertiserDisplayStatus.php b/src/Enumeration/AdvertiserDisplayStatus.php index 3b4b976..12a683c 100644 --- a/src/Enumeration/AdvertiserDisplayStatus.php +++ b/src/Enumeration/AdvertiserDisplayStatus.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Enumeration; +/** + * @psalm-suppress UnusedClass + */ final class AdvertiserDisplayStatus { public const SHOW_ACCOUNT_STATUS_NOT_APPROVED = 'SHOW_ACCOUNT_STATUS_NOT_APPROVED'; // Failed diff --git a/src/Enumeration/AdvertiserRole.php b/src/Enumeration/AdvertiserRole.php index 1065320..d2d6133 100644 --- a/src/Enumeration/AdvertiserRole.php +++ b/src/Enumeration/AdvertiserRole.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Enumeration; +/** + * @psalm-suppress UnusedClass + */ final class AdvertiserRole { public const ROLE_ADVERTISER = 'ROLE_ADVERTISER'; // Standard advertiser (direct customer) diff --git a/src/Enumeration/AdvertiserStatus.php b/src/Enumeration/AdvertiserStatus.php index e5bf0e7..f74848c 100644 --- a/src/Enumeration/AdvertiserStatus.php +++ b/src/Enumeration/AdvertiserStatus.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Enumeration; +/** + * @psalm-suppress UnusedClass + */ final class AdvertiserStatus { public const STATUS_DISABLE = 'STATUS_DISABLE'; // Disabled diff --git a/src/Enumeration/BusinessCenterStatus.php b/src/Enumeration/BusinessCenterStatus.php index 4c8fbf0..b0d785e 100644 --- a/src/Enumeration/BusinessCenterStatus.php +++ b/src/Enumeration/BusinessCenterStatus.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Enumeration; +/** + * @psalm-suppress UnusedClass + */ final class BusinessCenterStatus { public const REVIEWING = 'REVIEWING'; // Under review diff --git a/src/Enumeration/BusinessCenterType.php b/src/Enumeration/BusinessCenterType.php index 3c68fd4..f3a872c 100644 --- a/src/Enumeration/BusinessCenterType.php +++ b/src/Enumeration/BusinessCenterType.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Enumeration; +/** + * @psalm-suppress UnusedClass + */ final class BusinessCenterType { public const NORMAL = 'NORMAL'; // General diff --git a/src/Exception/TooManyJumpsException.php b/src/Exception/TooManyJumpsException.php index 227ff36..05c41a6 100644 --- a/src/Exception/TooManyJumpsException.php +++ b/src/Exception/TooManyJumpsException.php @@ -69,7 +69,13 @@ public function getJumpResponses(): array public function getLastResponse(): ResponseInterface { - return end($this->jumpResponses); + $lastJump = end($this->jumpResponses); + + if ($lastJump === false) { + throw new \RuntimeException('Unable to retrieve last jump.'); + } + + return $lastJump; } public function getLastResponseAsString(): string diff --git a/src/OAuth2Client.php b/src/OAuth2Client.php index 9897c4e..fe0db1a 100644 --- a/src/OAuth2Client.php +++ b/src/OAuth2Client.php @@ -8,6 +8,9 @@ use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; +/** + * @psalm-suppress UnusedClass + */ final class OAuth2Client { use RequestSenderTrait; @@ -63,7 +66,7 @@ public function advertiserGet( /** @var array $parsedBody */ $parsedBody = json_decode( - (string) $response->getBody(), + $response->getBody()->__toString(), true, JSON_THROW_ON_ERROR ); @@ -103,13 +106,13 @@ public function getAccessToken( 'app_id' => $appId, 'auth_code' => $authCode, 'secret' => $secret - ]) + ], JSON_THROW_ON_ERROR) ); $response = $this->sendRequest($request); /** @var array $accessToken */ - $accessToken = json_decode($response->getBody()->getContents(), true, JSON_THROW_ON_ERROR); + $accessToken = json_decode($response->getBody()->__toString(), true, JSON_THROW_ON_ERROR); if (empty($accessToken)) { throw new MalformedResponse($request, $response); @@ -147,7 +150,10 @@ public static function createAuthorizationUrl( 'redirect_uri' => $redirectUri, ]; - if ($scope) { + if ( + $scope !== null + && count($scope) > 0 + ) { $queryParams['scope'] = '[' . implode(',', $scope) . ']'; } diff --git a/src/RequestSenderTrait.php b/src/RequestSenderTrait.php index 5e1d129..ff3b25e 100644 --- a/src/RequestSenderTrait.php +++ b/src/RequestSenderTrait.php @@ -42,9 +42,11 @@ protected function sendRequest( $uri = current($response->getHeader('Location')); - /** - * @psalm-suppress UnusedVariable - */ + if ($uri === false) { + throw new \RuntimeException('Location header is invalid'); + } + + /** @psalm-suppress UnusedVariable */ $request = $request->withUri(new Uri($uri)); goto jump; diff --git a/src/Service/Ad.php b/src/Service/Ad.php index 9f073ad..8e26f52 100644 --- a/src/Service/Ad.php +++ b/src/Service/Ad.php @@ -6,6 +6,9 @@ use Throwable; +/** + * @psalm-suppress UnusedClass + */ final class Ad extends \Promopult\TikTokMarketingApi\AbstractService { /** diff --git a/src/Service/AdGroup.php b/src/Service/AdGroup.php index 4113b6a..a591627 100644 --- a/src/Service/AdGroup.php +++ b/src/Service/AdGroup.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Service; +/** + * @psalm-suppress UnusedClass + */ final class AdGroup extends \Promopult\TikTokMarketingApi\AbstractService { /** diff --git a/src/Service/Advertiser.php b/src/Service/Advertiser.php index 039a633..1dae46e 100644 --- a/src/Service/Advertiser.php +++ b/src/Service/Advertiser.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Service; +/** + * @psalm-suppress UnusedClass + */ final class Advertiser extends \Promopult\TikTokMarketingApi\AbstractService { /** diff --git a/src/Service/Bc.php b/src/Service/Bc.php index a471b38..0974af9 100644 --- a/src/Service/Bc.php +++ b/src/Service/Bc.php @@ -11,6 +11,7 @@ * place, and oversee multiple TikTok For Business accounts. * * @see https://ads.tiktok.com/marketing_api/docs?id=1690849685291009 + * @psalm-suppress UnusedClass */ final class Bc extends \Promopult\TikTokMarketingApi\AbstractService { diff --git a/src/Service/Campaign.php b/src/Service/Campaign.php index d1e56a1..b366040 100644 --- a/src/Service/Campaign.php +++ b/src/Service/Campaign.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Service; +/** + * @psalm-suppress UnusedClass + */ final class Campaign extends \Promopult\TikTokMarketingApi\AbstractService { /** diff --git a/src/Service/Creatives.php b/src/Service/Creatives.php index b5cd4af..ec23f14 100644 --- a/src/Service/Creatives.php +++ b/src/Service/Creatives.php @@ -6,6 +6,9 @@ use Promopult\TikTokMarketingApi\AbstractService; +/** + * @psalm-suppress UnusedClass + */ final class Creatives extends AbstractService { /** diff --git a/src/Service/Images.php b/src/Service/Images.php index d97baf3..8e216f3 100644 --- a/src/Service/Images.php +++ b/src/Service/Images.php @@ -6,6 +6,9 @@ use Promopult\TikTokMarketingApi\AbstractService; +/** + * @psalm-suppress UnusedClass + */ final class Images extends AbstractService { /** diff --git a/src/Service/Leads.php b/src/Service/Leads.php index ddaa348..326638d 100644 --- a/src/Service/Leads.php +++ b/src/Service/Leads.php @@ -7,6 +7,9 @@ use Throwable; use function json_decode; +/** + * @psalm-suppress UnusedClass + */ final class Leads extends \Promopult\TikTokMarketingApi\AbstractService { /** diff --git a/src/Service/Pages.php b/src/Service/Pages.php index 33e488d..ba58160 100644 --- a/src/Service/Pages.php +++ b/src/Service/Pages.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Service; +/** + * @psalm-suppress UnusedClass + */ final class Pages extends \Promopult\TikTokMarketingApi\AbstractService { /** diff --git a/src/Service/Report.php b/src/Service/Report.php index ad6fdc9..1856c85 100644 --- a/src/Service/Report.php +++ b/src/Service/Report.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Service; +/** + * @psalm-suppress UnusedClass + */ final class Report extends \Promopult\TikTokMarketingApi\AbstractService { /** diff --git a/src/Service/Tools.php b/src/Service/Tools.php index ba80ebe..ad95616 100644 --- a/src/Service/Tools.php +++ b/src/Service/Tools.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Service; +/** + * @psalm-suppress UnusedClass + */ final class Tools extends \Promopult\TikTokMarketingApi\AbstractService { /** diff --git a/src/Service/User.php b/src/Service/User.php index 6d4aaf5..4b1efca 100644 --- a/src/Service/User.php +++ b/src/Service/User.php @@ -4,6 +4,9 @@ namespace Promopult\TikTokMarketingApi\Service; +/** + * @psalm-suppress UnusedClass + */ final class User extends \Promopult\TikTokMarketingApi\AbstractService { /** diff --git a/src/Service/Video.php b/src/Service/Video.php index 7163a3c..ce92996 100644 --- a/src/Service/Video.php +++ b/src/Service/Video.php @@ -6,6 +6,9 @@ use Promopult\TikTokMarketingApi\AbstractService; +/** + * @psalm-suppress UnusedClass + */ final class Video extends AbstractService { /**