Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Add typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Aug 21, 2023
1 parent f51b528 commit 7a00efb
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .dev-tools/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"kubawerlos/php-cs-fixer-custom-fixers": "^3.16.2",
"php-cs-fixer/shim": "^3.22",
"phpstan/phpstan": "^1.10.28",
"vimeo/psalm": "^5.14.1"
"vimeo/psalm": "^5.15.0"
},
"config": {
"allow-plugins": {
Expand Down
10 changes: 5 additions & 5 deletions .dev-tools/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .dev-tools/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parameters:
bootstrapFiles:
- ../vendor/autoload.php
level: 0
level: 1
paths:
- ../src/
excludePaths:
Expand Down
2 changes: 1 addition & 1 deletion .dev-tools/psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0'?>
<psalm errorLevel='8'
<psalm errorLevel='1'
resolveFromConfigFile='true'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='https://getpsalm.org/schema/config'
Expand Down
2 changes: 1 addition & 1 deletion src/_class_tpay/CardApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function registerSaleMethod(
$clientEmail,
$saleDescription
) {
$params[CardDictionary::METHOD] = $this->method;
$params = [CardDictionary::METHOD => $this->method];
if (!is_null($this->cardData)) {
$params['card'] = $this->cardData;
}
Expand Down
8 changes: 8 additions & 0 deletions src/_class_tpay/Notifications/CardNotificationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

class CardNotificationHandler extends PaymentCard
{
/**
* @param string $apiKey
* @param string $apiPassword
* @param string $verificationCode
* @param string $hashType
*/
public function __construct($apiKey, $apiPassword, $verificationCode, $hashType)
{
$this->cardApiKey = $apiKey;
Expand All @@ -33,7 +39,9 @@ public function handleNotification()
{
Util::log('Card notification', "POST params: \n".print_r($_POST, true));

/** @var string $notificationType */
$notificationType = Util::post('type', CardDictionary::STRING);

if (CardDictionary::SALE === $notificationType) {
$response = $this->getResponse(new PaymentTypeCard());
} elseif (CardDictionary::DEREGISTER === $notificationType) {
Expand Down
60 changes: 60 additions & 0 deletions src/_class_tpay/PaymentOptions/CardOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,38 @@
class CardOptions extends ObjectsHelper
{
public $cardsApiURL = 'https://secure.tpay.com/api/cards/';

/** @var int */
protected $currency = 985;

/** @var string */
protected $orderID = '';

/** @var bool */
protected $oneTimer = true;

/** @var string */
protected $lang = 'pl';

/** @var bool */
protected $enablePowUrl = false;

/** @var string */
protected $powUrl = '';

/** @var string */
protected $powUrlBlad = '';

/** @var null|string */
protected $cardData = null;

/** @var string */
protected $method = 'register_sale';

/** @var string */
protected $clientAuthCode = '';

/** @var string */
protected $amount;

public function __construct()
Expand Down Expand Up @@ -45,6 +67,8 @@ public function setCurrency($currency)
}

/**
* @param string $orderID
*
* @return $this
*/
public function setOrderID($orderID)
Expand All @@ -53,43 +77,79 @@ public function setOrderID($orderID)
return $this;
}

/**
* @param bool $oneTimer
*
* @return $this
*/
public function setOneTimer($oneTimer)
{
$this->oneTimer = $oneTimer;
return $this;
}

/**
* @param string $lang
*
* @return $this
*/
public function setLanguage($lang)
{
$this->lang = $this->validateCardLanguage($lang);
return $this;
}

/**
* @param string $enablePowUrl
*
* @return $this
*/
public function setEnablePowUrl($enablePowUrl)
{
$this->enablePowUrl = $enablePowUrl;
return $this;
}

/**
* @param string $successUrl
* @param string $errorUrl
*
* @return $this
*/
public function setReturnUrls($successUrl, $errorUrl)
{
$this->powUrl = $successUrl;
$this->powUrlBlad = $errorUrl;
return $this;
}

/**
* @param string $data
*
* @return $this
*/
public function setCardData($data)
{
$this->cardData = $data;
return $this;
}

/**
* @param string $method
*
* @return $this
*/
public function setMethod($method)
{
$this->method = $method;
return $this;
}

/**
* @param string $amount
*
* @return $this
*/
public function setAmount($amount)
{
$this->validateNumeric($amount);
Expand Down
9 changes: 8 additions & 1 deletion src/_class_tpay/Utilities/ServerValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ class ServerValidator
private $validateServerIP;

/**
* @var bool
* @var array<string>
*/
private $secureIP;

/**
* @param bool $validateServerIP
* @param bool $validateForwardedIP
* @param array<string> $secureIP
*/
public function __construct($validateServerIP, $validateForwardedIP, array $secureIP)
{
$this->validateServerIP = $validateServerIP;
Expand Down Expand Up @@ -66,6 +71,8 @@ private function getServerValue($name)
if (isset($_SERVER[$name])) {
return $_SERVER[$name];
}

return null;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/_class_tpay/Utilities/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class Util
{
const REMOTE_ADDR = 'REMOTE_ADDRESS';

/** @var string */
static $lang = 'en';

/** @var null|string */
static $path = null;

/**
Expand Down Expand Up @@ -86,6 +89,11 @@ public static function post($name, $type)
return $val;
}

/**
* @param string $lang
*
* @return $this
*/
public function setLanguage($lang)
{
static::$lang = $lang;
Expand Down
12 changes: 6 additions & 6 deletions src/_class_tpay/Validators/FieldsConfigValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ trait FieldsConfigValidator
/**
* FieldsConfigValidator payment config
*
* @param object $paymentType
* @param array $config
* @param PaymentTypesInterface $paymentType
* @param array $config
*
* @throws TException
*
Expand Down Expand Up @@ -49,10 +49,10 @@ public function validateConfig($paymentType, $config)
/**
* Check one field form
*
* @param object $paymentType payment type
* @param string $name field name
* @param mixed $value field value
* @param bool $notResp is it not response value
* @param PaymentTypesInterface $paymentType payment type
* @param string $name field name
* @param mixed $value field value
* @param bool $notResp is it not response value
*
* @return bool
*/
Expand Down
6 changes: 6 additions & 0 deletions src/_class_tpay/Validators/PaymentTypesInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

interface PaymentTypesInterface
{
/**
* @return array<string, array<string, mixed>>
*/
public function getRequestFields();

/**
* @return null|array<string, array<string, mixed>>
*/
public function getResponseFields();
}
4 changes: 3 additions & 1 deletion src/_class_tpay/Validators/ResponseFieldsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait ResponseFieldsValidator
* Check all variables required in response
* Parse variables to valid types
*
* @param object $paymentType
* @param PaymentTypesInterface $paymentType
*
* @throws TException
*
Expand All @@ -31,7 +31,9 @@ public function getResponse($paymentType)
$missed[] = $fieldName;
}
} else {
/** @var string $val */
$val = Util::post($fieldName, FieldsConfigDictionary::STRING);

switch ($field[FieldsConfigDictionary::TYPE]) {
case FieldsConfigDictionary::STRING:
$val = (string)$val;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@

class VariableTypesValidator
{
/**
* @param string $type
* @param mixed $value
* @param string $name
*/
public function __construct($type, $value, $name)
{
$this->validateType($type, $value, $name);
}

/**
* @param string $type
* @param mixed $value
* @param string $name
*
* @throws TException
Expand Down
6 changes: 6 additions & 0 deletions src/_class_tpay/Validators/VariableTypesInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@

interface VariableTypesInterface
{
/**
* @param mixed $value
* @param string $name
*
* @return void
*/
public function validateType($value, $name);
}

0 comments on commit 7a00efb

Please sign in to comment.