Skip to content

Commit

Permalink
Update doc blocks & return types.
Browse files Browse the repository at this point in the history
Signed-off-by: Raza Mehdi <[email protected]>
  • Loading branch information
srmklive committed Jun 23, 2024
1 parent f3a7858 commit e2f7340
Show file tree
Hide file tree
Showing 37 changed files with 615 additions and 522 deletions.
7 changes: 4 additions & 3 deletions src/Facades/PayPal.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
/*
* Class Facade
* @package Srmklive\PayPal\Facades
* @see Srmklive\PayPal\ExpressCheckout
* @see Srmklive\PayPal\Services\PayPal
*/

use Illuminate\Support\Facades\Facade;
use Srmklive\PayPal\PayPalFacadeAccessor;

class PayPal extends Facade
{
Expand All @@ -17,8 +18,8 @@ class PayPal extends Facade
*
* @return string
*/
protected static function getFacadeAccessor()
protected static function getFacadeAccessor(): string
{
return 'Srmklive\PayPal\PayPalFacadeAccessor';
return PayPalFacadeAccessor::class;
}
}
12 changes: 6 additions & 6 deletions src/PayPalFacadeAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ class PayPalFacadeAccessor
/**
* PayPal API provider object.
*
* @var
* @var PayPalClient
*/
public static $provider;
public static PayPalClient $provider;

/**
* Get specific PayPal API provider object to use.
*
* @throws Exception
*
* @return \Srmklive\PayPal\Services\PayPal
* @return PayPalClient
*/
public static function getProvider()
public static function getProvider(): PayPalClient
{
return self::$provider;
}
Expand All @@ -31,9 +31,9 @@ public static function getProvider()
*
* @throws \Exception
*
* @return \Srmklive\PayPal\Services\PayPal
* @return PayPalClient
*/
public static function setProvider()
public static function setProvider(): PayPalClient
{
// Set default provider. Defaults to ExpressCheckout
self::$provider = new PayPalClient();
Expand Down
10 changes: 5 additions & 5 deletions src/Providers/PayPalServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class PayPalServiceProvider extends ServiceProvider
*
* @var bool
*/
protected $defer = false;
protected bool $defer = false;

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
public function boot(): void
{
// Publish config files
$this->publishes([
Expand All @@ -40,7 +40,7 @@ public function boot()
*
* @return void
*/
public function register()
public function register(): void
{
$this->registerPayPal();

Expand All @@ -52,7 +52,7 @@ public function register()
*
* @return void
*/
private function registerPayPal()
private function registerPayPal(): void
{
$this->app->singleton('paypal_client', static function () {
return new PayPalClient();
Expand All @@ -64,7 +64,7 @@ private function registerPayPal()
*
* @return void
*/
private function mergeConfig()
private function mergeConfig(): void
{
$this->mergeConfigFrom(
__DIR__.'/../../config/config.php',
Expand Down
14 changes: 7 additions & 7 deletions src/Services/VerifyDocuments.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class VerifyDocuments
/**
* @var array
*/
protected static $dispute_evidence_types = [
protected static array $dispute_evidence_types = [
'application/pdf',
'image/gif',
'image/jpeg',
Expand All @@ -19,12 +19,12 @@ class VerifyDocuments
/**
* @var string
*/
protected static $dispute_evidence_file_size = 10;
protected static string|int $dispute_evidence_file_size = 10;

/**
* @var string
*/
protected static $dispute_evidences_size = 50;
protected static string|int $dispute_evidences_size = 50;

/**
* Get Mime type from filename.
Expand All @@ -33,7 +33,7 @@ class VerifyDocuments
*
* @return string
*/
public static function getMimeType($file)
public static function getMimeType(string $file): string
{
return MimeType::fromFilename($file);
}
Expand All @@ -45,7 +45,7 @@ public static function getMimeType($file)
*
* @return bool
*/
public static function isValidEvidenceFile(array $files)
public static function isValidEvidenceFile(array $files): bool
{
$validFile = true;
$validSize = true;
Expand All @@ -58,7 +58,7 @@ public static function isValidEvidenceFile(array $files)
foreach ($files as $file) {
$mime_type = self::getMimeType($file);

if (!in_array($mime_type, self::$dispute_evidence_types)) {
if (!in_array($mime_type, self::$dispute_evidence_types, true)) {
$validFile = false;
break;
}
Expand All @@ -73,6 +73,6 @@ public static function isValidEvidenceFile(array $files)
$total_size += $size;
}

return (($validFile === false) || ($validSize === false)) || ($total_size > $overall_size) ? false : true;
return !((($validFile === false) || ($validSize === false)) || ($total_size > $overall_size));
}
}
27 changes: 15 additions & 12 deletions src/Traits/PayPalAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Srmklive\PayPal\Traits;

use Psr\Http\Message\StreamInterface;
use Srmklive\PayPal\Services\PayPal as PayPalClient;

trait PayPalAPI
{
use PayPalAPI\Trackers;
Expand Down Expand Up @@ -31,14 +34,14 @@ trait PayPalAPI
/**
* Login through PayPal API to get access token.
*
* @throws \Throwable
* @return array|StreamInterface|string
*
* @return array|\Psr\Http\Message\StreamInterface|string
* @throws \Throwable
*
* @see https://developer.paypal.com/docs/api/get-an-access-token-curl/
* @see https://developer.paypal.com/docs/api/get-an-access-token-postman/
*/
public function getAccessToken()
public function getAccessToken(): StreamInterface|array|string
{
$this->apiEndPoint = 'v1/oauth2/token';

Expand Down Expand Up @@ -66,7 +69,7 @@ public function getAccessToken()
*
* @return void
*/
public function setAccessToken(array $response)
public function setAccessToken(array $response): void
{
$this->access_token = $response['access_token'];

Expand All @@ -82,7 +85,7 @@ public function setAccessToken(array $response)
*
* @return void
*/
private function setPayPalAppId(array $response)
private function setPayPalAppId(array $response): void
{
$app_id = empty($response['app_id']) ? $this->config['app_id'] : $response['app_id'];

Expand All @@ -94,9 +97,9 @@ private function setPayPalAppId(array $response)
*
* @param int $size
*
* @return \Srmklive\PayPal\Services\PayPal
* @return PayPalClient
*/
public function setPageSize(int $size): \Srmklive\PayPal\Services\PayPal
public function setPageSize(int $size): PayPalClient
{
$this->page_size = $size;

Expand All @@ -106,11 +109,11 @@ public function setPageSize(int $size): \Srmklive\PayPal\Services\PayPal
/**
* Set the current page for list resources API calls.
*
* @param int $size
* @param int $page
*
* @return \Srmklive\PayPal\Services\PayPal
* @return PayPalClient
*/
public function setCurrentPage(int $page): \Srmklive\PayPal\Services\PayPal
public function setCurrentPage(int $page): PayPalClient
{
$this->current_page = $page;

Expand All @@ -122,9 +125,9 @@ public function setCurrentPage(int $page): \Srmklive\PayPal\Services\PayPal
*
* @param bool $totals
*
* @return \Srmklive\PayPal\Services\PayPal
* @return PayPalClient
*/
public function showTotals(bool $totals): \Srmklive\PayPal\Services\PayPal
public function showTotals(bool $totals): PayPalClient
{
$this->show_totals = var_export($totals, true);

Expand Down
45 changes: 24 additions & 21 deletions src/Traits/PayPalAPI/BillingPlans.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Srmklive\PayPal\Traits\PayPalAPI;

use Psr\Http\Message\StreamInterface;
use Throwable;

trait BillingPlans
{
use BillingPlans\PricingSchemes;
Expand All @@ -11,13 +14,13 @@ trait BillingPlans
*
* @param array $data
*
* @throws \Throwable
* @throws Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
* @return array|StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_create
*/
public function createPlan(array $data)
public function createPlan(array $data): StreamInterface|array|string
{
$this->apiEndPoint = 'v1/billing/plans';

Expand All @@ -31,13 +34,13 @@ public function createPlan(array $data)
/**
* List all billing plans.
*
* @throws \Throwable
* @throws Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
* @return array|StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_list
*/
public function listPlans()
public function listPlans(): StreamInterface|array|string
{
$this->apiEndPoint = "v1/billing/plans?page={$this->current_page}&page_size={$this->page_size}&total_required={$this->show_totals}";

Expand All @@ -52,13 +55,13 @@ public function listPlans()
* @param string $plan_id
* @param array $data
*
* @throws \Throwable
* @throws Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
* @return array|StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update
*/
public function updatePlan(string $plan_id, array $data)
public function updatePlan(string $plan_id, array $data): StreamInterface|array|string
{
$this->apiEndPoint = "v1/billing/plans/{$plan_id}";

Expand All @@ -74,13 +77,13 @@ public function updatePlan(string $plan_id, array $data)
*
* @param string $plan_id
*
* @throws \Throwable
* @throws Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
* @return array|StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_get
*/
public function showPlanDetails(string $plan_id)
public function showPlanDetails(string $plan_id): StreamInterface|array|string
{
$this->apiEndPoint = "v1/billing/plans/{$plan_id}";

Expand All @@ -94,13 +97,13 @@ public function showPlanDetails(string $plan_id)
*
* @param string $plan_id
*
* @throws \Throwable
* @throws Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
* @return array|StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_activate
*/
public function activatePlan(string $plan_id)
public function activatePlan(string $plan_id): StreamInterface|array|string
{
$this->apiEndPoint = "v1/billing/plans/{$plan_id}/activate";

Expand All @@ -114,13 +117,13 @@ public function activatePlan(string $plan_id)
*
* @param string $plan_id
*
* @throws \Throwable
* @throws Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
* @return array|StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_deactivate
*/
public function deactivatePlan(string $plan_id)
public function deactivatePlan(string $plan_id): StreamInterface|array|string
{
$this->apiEndPoint = "v1/billing/plans/{$plan_id}/deactivate";

Expand All @@ -135,13 +138,13 @@ public function deactivatePlan(string $plan_id)
* @param string $plan_id
* @param array $pricing
*
* @throws \Throwable
* @throws Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
* @return array|StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_update-pricing-schemes
*/
public function updatePlanPricing(string $plan_id, array $pricing)
public function updatePlanPricing(string $plan_id, array $pricing): StreamInterface|array|string
{
$this->apiEndPoint = "v1/billing/plans/{$plan_id}/update-pricing-schemes";

Expand Down
Loading

0 comments on commit e2f7340

Please sign in to comment.