diff --git a/src/AndroidServicesApi.php b/src/AndroidServicesApi.php index 86947a5..b0a3558 100644 --- a/src/AndroidServicesApi.php +++ b/src/AndroidServicesApi.php @@ -37,8 +37,10 @@ public function __construct( /** * @throws AndroidServiceException|JsonException + * @phpcs:disable Generic.Files.LineLength.TooLong * @link https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2 Purchases.subscriptionsV2 - * */ + * @phpcs:enable + */ public function getPurchaseSubscriptionV2( AndroidPublisherModelInterface $androidPublisherModel ): ?SubscriptionPurchaseV2 { @@ -66,8 +68,10 @@ public function getPurchaseSubscriptionV2( /** * @throws AndroidServiceException|JsonException + * @phpcs:disable Generic.Files.LineLength.TooLong * @link https://developers.google.com/android-publisher/api-ref/rest/v3/monetization.subscriptions.basePlans.offers Monetization.subscriptions.basePlans.offers - * */ + * @phpcs:enable + */ public function getBasePlanOffers( AndroidPublisherModelInterface $androidPublisherModel ): ?ListSubscriptionOffersResponse { @@ -99,7 +103,9 @@ public function getBasePlanOffers( /** * @throws AndroidServiceException|JsonException + * @phpcs:disable Generic.Files.LineLength.TooLong * @link https://developers.google.com/android-publisher/api-ref/rest/v3/monetization.subscriptions Monetization.subscriptions + * @phpcs:enable */ public function getPackageSubscriptions( AndroidPublisherModelInterface $androidPublisherModel diff --git a/src/DependencyInjection/AndroidServicesExtension.php b/src/DependencyInjection/AndroidServicesExtension.php index 2e7af23..d541df3 100644 --- a/src/DependencyInjection/AndroidServicesExtension.php +++ b/src/DependencyInjection/AndroidServicesExtension.php @@ -13,7 +13,10 @@ class AndroidServicesExtension extends Extension { - /**@throws Exception */ + /** + * @suppressWarnings(PHPMD.UnusedFormalParameter) + * @throws Exception + */ public function load(array $configs, ContainerBuilder $container): void { $loader = new YamlFileLoader( diff --git a/src/Factory/Authenticator.php b/src/Factory/Authenticator.php index a40e409..30874f6 100644 --- a/src/Factory/Authenticator.php +++ b/src/Factory/Authenticator.php @@ -6,6 +6,7 @@ use Google\Client; use Google\Exception; +use IM\Fabric\Bundle\AndroidServicesBundle\Traits\HasAndroidServiceException; use JsonException; /** @@ -14,6 +15,8 @@ */ class Authenticator { + use HasAndroidServiceException; + public function __construct( private string $googleCredentials, private Client $client @@ -32,6 +35,10 @@ public function getAuthenticatedClient(string|array $scopes): Client /** @throws JsonException */ private function getAuthConfig(): array { - return json_decode($this->googleCredentials, true, 512, JSON_THROW_ON_ERROR); + try { + return json_decode($this->googleCredentials, true, 512, JSON_THROW_ON_ERROR); + } catch (JsonException $exception) { + $this->throwAndroidServiceException($exception->getMessage(), $exception->getCode()); + } } } diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index c43a930..1c50563 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -1,6 +1,6 @@ parameters: app.deployed_env: '%env(string:DEPLOYED_ENV)%' - app.google_creds: 'env(GOOGLE_API_SERVICE_ACCOUNT_CREDENTIALS)%' + app.google_creds: '%env(GOOGLE_API_SERVICE_ACCOUNT_CREDENTIALS)%' services: # default configuration for services in *this* file _defaults: diff --git a/tests/phpunit/Unit/AndroidServiceApiTest.php b/tests/phpunit/Unit/AndroidServiceApiTest.php index ecc7bec..2cfab00 100644 --- a/tests/phpunit/Unit/AndroidServiceApiTest.php +++ b/tests/phpunit/Unit/AndroidServiceApiTest.php @@ -21,7 +21,10 @@ use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -/** @SuppressWarnings("LongVariable") */ +/** + * @SuppressWarnings("LongVariable") + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * */ class AndroidServiceApiTest extends TestCase { use MockeryPHPUnitIntegration; diff --git a/tests/phpunit/Unit/Factory/AuthenticatorTest.php b/tests/phpunit/Unit/Factory/AuthenticatorTest.php index f0ecf7f..e2eae16 100644 --- a/tests/phpunit/Unit/Factory/AuthenticatorTest.php +++ b/tests/phpunit/Unit/Factory/AuthenticatorTest.php @@ -6,6 +6,7 @@ use Google\Client; use Google\Exception; +use IM\Fabric\Bundle\AndroidServicesBundle\Exception\AndroidServiceException; use IM\Fabric\Bundle\AndroidServicesBundle\Factory\Authenticator; use JsonException; use Mockery; @@ -30,11 +31,13 @@ class AuthenticatorTest extends TestCase "client_x509_cert_url": "mock_url" }'; - /**@throws Exception*/ + /**@throws Exception + * @throws JsonException + */ public function testItThrowsAnExceptionIfTheCertIsNotValidJson(): void { $client = Mockery::mock(Client::class); - $this->expectException(JsonException::class); + $this->expectException(AndroidServiceException::class); $unit = new Authenticator('bad json key', $client); $unit->getAuthenticatedClient(self::MOCK_SCOPE); }