diff --git a/CHANGELOG.md b/CHANGELOG.md index fd323e9..0dc7ab9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,13 @@ CHANGELOG ========= -3.2.0 ----------------- +3.2.0-beta.2 (2024-11-15) +------------------------- * The minFraud Factors subscores have been deprecated. They will be removed in March 2025. Please see [our release notes](https://dev.maxmind.com/minfraud/release-notes/2024/#deprecation-of-risk-factor-scoressubscores) for more information. +* The type hints in the PHPDocs have been improved. 3.2.0-beta.1 (2024-09-06) ------------------------- diff --git a/composer.json b/composer.json index b0cb9f4..ae6efb8 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,7 @@ "require": { "php": ">=8.1", "ext-json": "*", - "geoip2/geoip2": "^v3.0.0", - "maxmind/web-service-common": "^0.9.0" + "geoip2/geoip2": "^v3.1.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "3.*", diff --git a/dev-bin/release.sh b/dev-bin/release.sh index 0e454a1..1043769 100755 --- a/dev-bin/release.sh +++ b/dev-bin/release.sh @@ -46,10 +46,10 @@ php composer.phar update --no-dev perl -pi -e "s/(?<=const VERSION = ').+?(?=';)/$tag/g" src/MinFraud/ServiceClient.php -box_phar_hash='c24c400c424a68041d7af146c71943bf1acc0c5abafa45297c503b832b9c6b16 box.phar' +box_phar_hash='8d12a7d69a5003a80bd603ea95a8f3dcea30b9a2ad84cd7cb15b8193929def9e box.phar' if ! echo "$box_phar_hash" | sha256sum -c; then - wget -O box.phar "https://github.com/box-project/box/releases/download/4.5.1/box.phar" + wget -O box.phar "https://github.com/box-project/box/releases/download/4.6.1/box.phar" fi echo "$box_phar_hash" | sha256sum -c @@ -94,10 +94,10 @@ if [ -n "$(git status --porcelain)" ]; then fi # Using Composer is possible, but they don't recommend it. -phpdocumentor_phar_hash='bad7e4b8c99e73391bb3183a127593ecd1cd66ae42b4a33efe495d193e257f04 phpDocumentor.phar' +phpdocumentor_phar_hash='9760ac280a10041928a8743354f68692c22f14cd5d05135dfc15e11d3b3c25ea phpDocumentor.phar' if ! echo "$phpdocumentor_phar_hash" | sha256sum -c; then - wget -O phpDocumentor.phar https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.4.3/phpDocumentor.phar + wget -O phpDocumentor.phar https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.5.3/phpDocumentor.phar fi echo "$phpdocumentor_phar_hash" | sha256sum -c diff --git a/phpstan.neon b/phpstan.neon index 06f84c2..63aadba 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,4 +3,3 @@ parameters: paths: - src - tests - checkMissingIterableValueType: false diff --git a/src/MinFraud.php b/src/MinFraud.php index 71e7f65..16d09da 100644 --- a/src/MinFraud.php +++ b/src/MinFraud.php @@ -42,24 +42,21 @@ class MinFraud extends MinFraud\ServiceClient { /** - * @var array + * @var array */ - private $content; + private array $content; - /** - * @var bool - */ - private $hashEmail; + private bool $hashEmail; /** * @var array */ - private $locales; + private array $locales; /** - * @param int $accountId Your MaxMind account ID - * @param string $licenseKey Your MaxMind license key - * @param array $options An array of options. Possible keys: + * @param int $accountId Your MaxMind account ID + * @param string $licenseKey Your MaxMind license key + * @param array $options An array of options. Possible keys: * * - `host` - The host to use when connecting to the web service. * By default, the client connects to the production host. However, @@ -108,6 +105,8 @@ public function __construct( * @link https://dev.maxmind.com/minfraud/api-documentation?lang=en * minFraud API docs * + * @param array $values The request as a structured array + * * @return MinFraud A new immutable MinFraud object. This object is * a clone of the original with additional data. */ @@ -159,26 +158,26 @@ public function with(array $values): self * This returns a `MinFraud` object with the `device` array set to * the values provided. Existing `device` data will be replaced. * - * @param array $values An array of device data. The keys are the same as - * the JSON keys. You may use either this or the named - * arguments, but not both. - * @param string|null $ipAddress The IP address associated with the device - * used by the customer in the transaction. - * The IP address must be in IPv4 or IPv6 - * presentation format, i.e., dotted-quad - * notation or the IPv6 hexadecimal-colon - * notation. - * @param string|null $userAgent The HTTP `User-Agent` header of the browser - * used in the transaction - * @param string|null $acceptLanguage The HTTP `Accept-Language` header of - * the device used in the transaction - * @param float|null $sessionAge The number of seconds between the creation - * of the user's session and the time of the - * transaction. Note that `session_age` is not - * the duration of the current visit, but the - * time since the start of the first visit. - * @param string|null $sessionId An ID that uniquely identifies a visitor's - * session on the site + * @param array $values An array of device data. The keys are the same as + * the JSON keys. You may use either this or the named + * arguments, but not both. + * @param string|null $ipAddress The IP address associated with the device + * used by the customer in the transaction. + * The IP address must be in IPv4 or IPv6 + * presentation format, i.e., dotted-quad + * notation or the IPv6 hexadecimal-colon + * notation. + * @param string|null $userAgent The HTTP `User-Agent` header of the browser + * used in the transaction + * @param string|null $acceptLanguage The HTTP `Accept-Language` header of + * the device used in the transaction + * @param float|null $sessionAge The number of seconds between the creation + * of the user's session and the time of the + * transaction. Note that `session_age` is not + * the duration of the current visit, but the + * time since the start of the first visit. + * @param string|null $sessionId An ID that uniquely identifies a visitor's + * session on the site * * @return MinFraud A new immutable MinFraud object. This object is a clone * of the original with additional data. @@ -202,17 +201,21 @@ public function withDevice( } $acceptLanguage = $this->remove($values, 'accept_language'); $ipAddress = $this->remove($values, 'ip_address'); - if (($v = $this->remove($values, 'session_age', ['double', 'float', 'integer', 'string'])) && $v !== null) { + + $v = $this->remove($values, 'session_age', ['double', 'float', 'integer', 'string']); + if ($v !== null) { if (!is_numeric($v)) { $this->maybeThrowInvalidInputException('Expected session_age to be a number'); } $sessionAge = (float) $v; } - if (isset($values['session_id'])) { - if (($v = $this->remove($values, 'session_id', ['integer', 'string'])) && $v !== null) { - $sessionId = (string) $v; - } + + + $v = $this->remove($values, 'session_id', ['integer', 'string']); + if ($v !== null) { + $sessionId = (string) $v; } + $userAgent = $this->remove($values, 'user_agent'); $this->verifyEmpty($values); @@ -237,8 +240,7 @@ public function withDevice( } if ($sessionId !== null) { - if (!\is_string($sessionId) - || $sessionId === '' + if ($sessionId === '' || \strlen($sessionId) > 255) { $this->maybeThrowInvalidInputException( "Session ID ($sessionId) must be a string with length between 1 and 255", @@ -261,35 +263,35 @@ public function withDevice( * This returns a `MinFraud` object with the `event` array set to * the values provided. Existing `event` data will be replaced. * - * @param array $values An array of event data. The keys are the same as - * the JSON keys. You may use either this or the named - * arguments, but not both. - * @param string|null $shopId Your internal ID for the shop, affiliate, or - * merchant this order is coming from. Required for - * minFraud users who are resellers, payment - * providers, gateways and affiliate networks. No - * specific format is required. - * @param string|null $time The date and time the event occurred. The string - * must be in the RFC 3339 date-time format. The time - * must be within the past year. If this field is not - * in the request, the current time will be used. - * @param string|null $transactionId Your internal ID for the transaction. We - * can use this to locate a specific - * transaction in our logs, and it will also - * show up in email alerts and notifications - * from us to you. No specific format is - * required. - * @param string|null $type The type of event being scored. The valid types - * are: - * - `account_creation` - * - `account_login` - * - `email_change` - * - `password_reset` - * - `payout_change` - * - `purchase` - * - `recurring_purchase` - * - `referral` - * - `survey` + * @param array $values An array of event data. The keys are the same as + * the JSON keys. You may use either this or the named + * arguments, but not both. + * @param string|null $shopId Your internal ID for the shop, affiliate, or + * merchant this order is coming from. Required for + * minFraud users who are resellers, payment + * providers, gateways and affiliate networks. No + * specific format is required. + * @param string|null $time The date and time the event occurred. The string + * must be in the RFC 3339 date-time format. The time + * must be within the past year. If this field is not + * in the request, the current time will be used. + * @param string|null $transactionId Your internal ID for the transaction. We + * can use this to locate a specific + * transaction in our logs, and it will also + * show up in email alerts and notifications + * from us to you. No specific format is + * required. + * @param string|null $type The type of event being scored. The valid types + * are: + * - `account_creation` + * - `account_login` + * - `email_change` + * - `password_reset` + * - `payout_change` + * - `purchase` + * - `recurring_purchase` + * - `referral` + * - `survey` * * @return MinFraud A new immutable MinFraud object. This object is a clone of * the original with additional data. @@ -366,14 +368,14 @@ public function withEvent( * @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--account * minFraud account API docs * - * @param array $values An array of account data. The keys are the same as - * the JSON keys. You may use either this or the named - * arguments, but not both. - * @param string|null $userId a unique user ID associated with the end-user - * in your system - * @param string|null $usernameMd5 an MD5 hash as a hexadecimal string of - * the username or login name associated - * with the account + * @param array $values An array of account data. The keys are the same as + * the JSON keys. You may use either this or the named + * arguments, but not both. + * @param string|null $userId a unique user ID associated with the end-user + * in your system + * @param string|null $usernameMd5 an MD5 hash as a hexadecimal string of + * the username or login name associated + * with the account * * @return MinFraud A new immutable MinFraud object. This object is a clone * of the original with additional data. @@ -419,14 +421,14 @@ public function withAccount( * @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--email * minFraud email API docs * - * @param array $values An array of email data. The keys are the same as - * the JSON keys. You may use either this or the named - * arguments, but not both. - * @param string|null $address The email address used in the transaction. - * This field must be a valid email address. - * @param string|null $domain The domain of the email address used in the - * transaction. Do not include the `@` in this - * field. + * @param array $values An array of email data. The keys are the same as + * the JSON keys. You may use either this or the named + * arguments, but not both. + * @param string|null $address The email address used in the transaction. + * This field must be a valid email address. + * @param string|null $domain The domain of the email address used in the + * transaction. Do not include the `@` in this + * field. * * @return MinFraud A new immutable MinFraud object. This object is a clone * of the original with additional data. @@ -480,33 +482,33 @@ public function withEmail( * @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--billing * minFraud billing API docs * - * @param array $values An array of billing data. The keys are the same as - * the JSON keys. You may use either this or the named - * arguments, but not both. - * @param string|null $address The first line of the user's billing address - * @param string|null $address2 The second line of the user's billing address - * @param string|null $city The city of the user's billing address - * @param string|null $company The company of the end user as provided in - * their billing information - * @param string|null $country The two character ISO 3166-1 alpha-2 country - * code of the user's billing address - * @param string|null $firstName The first name of the end user as provided - * in their billing information - * @param string|null $lastName The last name of the end user as provided - * in their billing information - * @param string|null $phoneCountryCode The country code for phone number - * associated with the user's billing - * address. If you provide this - * information then you must provide - * at least one digit. - * @param string|null $phoneNumber The phone number without the country code - * for the user's billing address. Punctuation - * characters will be stripped. After - * stripping punctuation characters, the - * number must contain only digits. - * @param string|null $postal The postal code of the user's billing address - * @param string|null $region The ISO 3166-2 subdivision code for the user's - * billing address + * @param array $values An array of billing data. The keys are the same as + * the JSON keys. You may use either this or the named + * arguments, but not both. + * @param string|null $address The first line of the user's billing address + * @param string|null $address2 The second line of the user's billing address + * @param string|null $city The city of the user's billing address + * @param string|null $company The company of the end user as provided in + * their billing information + * @param string|null $country The two character ISO 3166-1 alpha-2 country + * code of the user's billing address + * @param string|null $firstName The first name of the end user as provided + * in their billing information + * @param string|null $lastName The last name of the end user as provided + * in their billing information + * @param string|null $phoneCountryCode The country code for phone number + * associated with the user's billing + * address. If you provide this + * information then you must provide + * at least one digit. + * @param string|null $phoneNumber The phone number without the country code + * for the user's billing address. Punctuation + * characters will be stripped. After + * stripping punctuation characters, the + * number must contain only digits. + * @param string|null $postal The postal code of the user's billing address + * @param string|null $region The ISO 3166-2 subdivision code for the user's + * billing address * * @return MinFraud A new immutable MinFraud object. This object is a clone * of the original with additional data. @@ -607,18 +609,18 @@ public function withBilling( * @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--shipping * minFraud shipping API docs * - * @param array $values An array of shipping data. The keys are the same as - * the JSON keys. You may use either this or the named - * arguments, but not both. - * @param string|null $company The company of the end user as provided in - * their shipping information - * @param string|null $address The first line of the user's shipping address - * @param string|null $city The city of the user's shipping address - * @param string|null $region The ISO 3166-2 subdivision code for the user's - * shipping address - * @param string|null $country The two character ISO 3166-1 alpha-2 country - * code of the user's shipping address - * @param string|null $postal The postal code of the user's shipping address + * @param array $values An array of shipping data. The keys are the same as + * the JSON keys. You may use either this or the named + * arguments, but not both. + * @param string|null $company The company of the end user as provided in + * their shipping information + * @param string|null $address The first line of the user's shipping address + * @param string|null $city The city of the user's shipping address + * @param string|null $region The ISO 3166-2 subdivision code for the user's + * shipping address + * @param string|null $country The two character ISO 3166-1 alpha-2 country + * code of the user's shipping address + * @param string|null $postal The postal code of the user's shipping address * * @return MinFraud A new immutable MinFraud object. This object is * a clone of the original with additional data. @@ -729,16 +731,16 @@ public function withShipping( * @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--payment * minFraud payment API docs * - * @param array $values An array of payment data. The keys are the same as - * the JSON keys. You may use either this or the named - * arguments, but not both. - * @param string|null $declineCode The decline code as provided by your - * payment processor. If the transaction - * was not declined, do not include this field. - * @param string|null $processor The payment processor used for the transaction - * @param bool|null $wasAuthorized The authorization outcome from the payment - * processor. If the transaction has not yet been - * approved or denied, do not include this field. + * @param array $values An array of payment data. The keys are the same as + * the JSON keys. You may use either this or the named + * arguments, but not both. + * @param string|null $declineCode The decline code as provided by your + * payment processor. If the transaction + * was not declined, do not include this field. + * @param string|null $processor The payment processor used for the transaction + * @param bool|null $wasAuthorized The authorization outcome from the payment + * processor. If the transaction has not yet been + * approved or denied, do not include this field. * * @return MinFraud A new immutable MinFraud object. This object is * a clone of the original with additional data. @@ -949,34 +951,34 @@ public function withPayment( * @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--credit-card * minFraud credit_card API docs * - * @param array $values An array of credit card data. The keys are the same as - * the JSON keys. You may use either this or the named - * arguments, but not both. - * @param string|null $avsResult The address verification system (AVS) check - * result, as returned to you by the credit card - * processor - * @param string|null $bankName The name of the issuing bank as provided by the - * end user - * @param string|null $bankPhoneCountryCode The phone country code for the - * issuing bank as provided by the end - * user - * @param string|null $bankPhoneNumber The phone number, without the country - * code, for the issuing bank as provided by - * the end user - * @param string|null $country The two character ISO 3166-1 alpha-2 country - * code where the issuer of the card is located - * @param string|null $cvvResult The card verification value (CVV) code as - * provided by the payment processor - * @param string|null $issuerIdNumber The issuer ID number for the credit card. - * This is the first six or eight digits of - * the credit card number. It identifies the - * issuing bank. - * @param string|null $lastDigits The last digits of the credit card number. - * In most cases, you should send the last four - * digits for `lastDigits`. - * @param string|null $token A token uniquely identifying the card - * @param bool|null $was3dSecureSuccessful Whether the outcome of 3-D Secure - * verification was successful + * @param array $values An array of credit card data. The keys are the same as + * the JSON keys. You may use either this or the named + * arguments, but not both. + * @param string|null $avsResult The address verification system (AVS) check + * result, as returned to you by the credit card + * processor + * @param string|null $bankName The name of the issuing bank as provided by the + * end user + * @param string|null $bankPhoneCountryCode The phone country code for the + * issuing bank as provided by the end + * user + * @param string|null $bankPhoneNumber The phone number, without the country + * code, for the issuing bank as provided by + * the end user + * @param string|null $country The two character ISO 3166-1 alpha-2 country + * code where the issuer of the card is located + * @param string|null $cvvResult The card verification value (CVV) code as + * provided by the payment processor + * @param string|null $issuerIdNumber The issuer ID number for the credit card. + * This is the first six or eight digits of + * the credit card number. It identifies the + * issuing bank. + * @param string|null $lastDigits The last digits of the credit card number. + * In most cases, you should send the last four + * digits for `lastDigits`. + * @param string|null $token A token uniquely identifying the card + * @param bool|null $was3dSecureSuccessful Whether the outcome of 3-D Secure + * verification was successful * * @return MinFraud A new immutable MinFraud object. This object is a clone of * the original with additional data. @@ -1096,6 +1098,8 @@ public function withCreditCard( * This returns a `MinFraud` object with the `custom_inputs` array set to * `$values`. Existing `custom_inputs` data will be replaced. * + * @param array $values the custom inputs to send in the request + * * @return MinFraud A new immutable MinFraud object. This object is * a clone of the original with additional data. */ @@ -1145,18 +1149,18 @@ public function withCustomInputs(array $values): self * @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--order * minFraud order API docs * - * @param array $values An array of order data. The keys are the same as the JSON keys. - * You may use either this or the named arguments, but not both. - * @param string|null $affiliateId The ID of the affiliate where the order is coming from. - * No specific format is required. - * @param float|null $amount The total order amount - * @param string|null $currency The currency code for the order amount - * @param string|null $discountCode The discount code applied to the order - * @param bool|null $hasGiftMessage Indicates if the order has a gift message - * @param bool|null $isGift Indicates if the order is a gift - * @param string|null $referrerUri The URI of the referring website - * @param string|null $subaffiliateId The ID of the sub-affiliate where the order is coming from. - * No specific format is required. + * @param array $values An array of order data. The keys are the same as the JSON keys. + * You may use either this or the named arguments, but not both. + * @param string|null $affiliateId The ID of the affiliate where the order is coming from. + * No specific format is required. + * @param float|null $amount The total order amount + * @param string|null $currency The currency code for the order amount + * @param string|null $discountCode The discount code applied to the order + * @param bool|null $hasGiftMessage Indicates if the order has a gift message + * @param bool|null $isGift Indicates if the order is a gift + * @param string|null $referrerUri The URI of the referring website + * @param string|null $subaffiliateId The ID of the sub-affiliate where the order is coming from. + * No specific format is required. * * @return MinFraud A new immutable MinFraud object. This object is a clone of the original with additional data. * @@ -1246,16 +1250,16 @@ public function withOrder( * @link https://dev.maxmind.com/minfraud/api-documentation/requests?lang=en#schema--request--shopping-cart--item * minFraud shopping cart item API docs * - * @param array $values An array of shopping cart data. The keys are the same - * as the JSON keys. You may use either this or the named - * arguments, but not both. - * @param string|null $category The category of the item. This can also be - * a hashed value; see below. - * @param float|null $price The per-unit price of this item in the shopping - * cart. This should use the same currency as the - * order currency. - * @param int|null $quantity The quantity of the item in the shopping cart. - * The value must be a whole number. + * @param array $values An array of shopping cart data. The keys are the same + * as the JSON keys. You may use either this or the named + * arguments, but not both. + * @param string|null $category The category of the item. This can also be + * a hashed value; see below. + * @param float|null $price The per-unit price of this item in the shopping + * cart. This should use the same currency as the + * order currency. + * @param int|null $quantity The quantity of the item in the shopping cart. + * The value must be a whole number. * * @return MinFraud A new immutable MinFraud object. This object is a clone * of the original with additional data. @@ -1275,9 +1279,12 @@ public function withShoppingCartItem( } $category = $this->remove($values, 'category'); - if (($v = (string) $this->remove($values, 'item_id', ['integer', 'string'])) && $v !== null) { - $itemId = $v; + + $v = $this->remove($values, 'item_id', ['integer', 'string']); + if ($v !== null) { + $itemId = (string) $v; } + $price = $this->remove($values, 'price', ['double', 'float', 'integer']); $quantity = $this->remove($values, 'quantity', ['integer']); diff --git a/src/MinFraud/Model/Address.php b/src/MinFraud/Model/Address.php index c151c66..700dd85 100644 --- a/src/MinFraud/Model/Address.php +++ b/src/MinFraud/Model/Address.php @@ -41,6 +41,9 @@ abstract class Address implements \JsonSerializable */ public readonly ?float $longitude; + /** + * @param array|null $response + */ public function __construct(?array $response) { $this->distanceToIpLocation = $response['distance_to_ip_location'] ?? null; @@ -50,6 +53,9 @@ public function __construct(?array $response) $this->longitude = $response['longitude'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/CreditCard.php b/src/MinFraud/Model/CreditCard.php index abb5243..f984fe6 100644 --- a/src/MinFraud/Model/CreditCard.php +++ b/src/MinFraud/Model/CreditCard.php @@ -63,6 +63,9 @@ class CreditCard implements \JsonSerializable */ public readonly ?string $type; + /** + * @param array|null $response + */ public function __construct(?array $response) { $this->issuer = new Issuer($response['issuer'] ?? []); @@ -77,6 +80,9 @@ public function __construct(?array $response) $this->type = $response['type'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/Device.php b/src/MinFraud/Model/Device.php index 178d90e..521c758 100644 --- a/src/MinFraud/Model/Device.php +++ b/src/MinFraud/Model/Device.php @@ -42,6 +42,9 @@ class Device implements \JsonSerializable */ public readonly ?string $localTime; + /** + * @param array|null $response + */ public function __construct(?array $response) { $this->confidence = $response['confidence'] ?? null; @@ -50,6 +53,9 @@ public function __construct(?array $response) $this->localTime = $response['local_time'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/Disposition.php b/src/MinFraud/Model/Disposition.php index 8c7e904..c999a24 100644 --- a/src/MinFraud/Model/Disposition.php +++ b/src/MinFraud/Model/Disposition.php @@ -34,6 +34,9 @@ class Disposition implements \JsonSerializable */ public readonly ?string $ruleLabel; + /** + * @param array|null $response + */ public function __construct(?array $response) { $this->action = $response['action'] ?? null; @@ -41,6 +44,9 @@ public function __construct(?array $response) $this->ruleLabel = $response['rule_label'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/Email.php b/src/MinFraud/Model/Email.php index 07e3edc..b9c73fa 100644 --- a/src/MinFraud/Model/Email.php +++ b/src/MinFraud/Model/Email.php @@ -42,6 +42,9 @@ class Email implements \JsonSerializable */ public readonly ?bool $isHighRisk; + /** + * @param array|null $response + */ public function __construct(?array $response) { $this->domain = new EmailDomain($response['domain'] ?? null); @@ -51,6 +54,9 @@ public function __construct(?array $response) $this->isHighRisk = $response['is_high_risk'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/EmailDomain.php b/src/MinFraud/Model/EmailDomain.php index da8248c..dfd5214 100644 --- a/src/MinFraud/Model/EmailDomain.php +++ b/src/MinFraud/Model/EmailDomain.php @@ -16,11 +16,17 @@ class EmailDomain implements \JsonSerializable */ public readonly ?string $firstSeen; + /** + * @param array|null $response + */ public function __construct(?array $response) { $this->firstSeen = $response['first_seen'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/Factors.php b/src/MinFraud/Model/Factors.php index fc76c57..6268d06 100644 --- a/src/MinFraud/Model/Factors.php +++ b/src/MinFraud/Model/Factors.php @@ -28,6 +28,10 @@ class Factors extends Insights */ public readonly Subscores $subscores; + /** + * @param array $response + * @param list $locales + */ public function __construct(array $response, array $locales = ['en']) { parent::__construct($response, $locales); @@ -44,6 +48,9 @@ public function __construct(array $response, array $locales = ['en']) = new Subscores($response['subscores'] ?? []); } + /** + * @return array + */ public function jsonSerialize(): array { $js = parent::jsonSerialize(); diff --git a/src/MinFraud/Model/GeoIp2Location.php b/src/MinFraud/Model/GeoIp2Location.php index 05f39b7..17eedad 100644 --- a/src/MinFraud/Model/GeoIp2Location.php +++ b/src/MinFraud/Model/GeoIp2Location.php @@ -19,6 +19,9 @@ class GeoIp2Location extends Location */ public readonly ?string $localTime; + /** + * @param array $record + */ public function __construct(array $record) { parent::__construct($record); @@ -26,6 +29,9 @@ public function __construct(array $record) $this->localTime = $record['local_time'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = parent::jsonSerialize(); diff --git a/src/MinFraud/Model/Insights.php b/src/MinFraud/Model/Insights.php index d8ddda3..2363203 100644 --- a/src/MinFraud/Model/Insights.php +++ b/src/MinFraud/Model/Insights.php @@ -94,14 +94,18 @@ class Insights implements \JsonSerializable public readonly Phone $shippingPhone; /** - * @var array This array contains \MaxMind\MinFraud\Model\Warning objects - * detailing issues with the request that was sent, such as - * invalid or unknown inputs. It is highly recommended that - * you check this array for issues when integrating the web - * service. + * @var array This array contains \MaxMind\MinFraud\Model\Warning objects + * detailing issues with the request that was sent, such as + * invalid or unknown inputs. It is highly recommended that + * you check this array for issues when integrating the web + * service. */ public readonly array $warnings; + /** + * @param array $response + * @param list $locales + */ public function __construct(array $response, array $locales = ['en']) { $this->disposition @@ -129,6 +133,9 @@ public function __construct(array $response, array $locales = ['en']) $this->shippingPhone = new Phone($response['shipping_phone'] ?? []); } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/IpAddress.php b/src/MinFraud/Model/IpAddress.php index e3e380d..4c4ea43 100644 --- a/src/MinFraud/Model/IpAddress.php +++ b/src/MinFraud/Model/IpAddress.php @@ -87,13 +87,13 @@ class IpAddress implements \JsonSerializable public readonly array $riskReasons; /** - * @var array An array of \GeoIp2\Record\Subdivision objects representing - * the country subdivisions for the requested IP address. The - * number and type of subdivisions varies by country, but a - * subdivision is typically a state, province, county, etc. - * Subdivisions are ordered from most general (largest) to most - * specific (smallest). If the response did not contain any - * subdivisions, this method returns an empty array. + * @var array An array of \GeoIp2\Record\Subdivision objects representing + * the country subdivisions for the requested IP address. The + * number and type of subdivisions varies by country, but a + * subdivision is typically a state, province, county, etc. + * Subdivisions are ordered from most general (largest) to most + * specific (smallest). If the response did not contain any + * subdivisions, this method returns an empty array. */ public readonly array $subdivisions; @@ -103,6 +103,10 @@ class IpAddress implements \JsonSerializable */ public readonly Traits $traits; + /** + * @param array|null $response + * @param list $locales + */ public function __construct(?array $response, array $locales = ['en']) { if ($response === null) { @@ -132,6 +136,9 @@ public function __construct(?array $response, array $locales = ['en']) $this->riskReasons = $riskReasons; } + /** + * @return array + */ public function jsonSerialize(): ?array { $js = []; diff --git a/src/MinFraud/Model/IpRiskReason.php b/src/MinFraud/Model/IpRiskReason.php index edadaad..606a396 100644 --- a/src/MinFraud/Model/IpRiskReason.php +++ b/src/MinFraud/Model/IpRiskReason.php @@ -41,12 +41,18 @@ class IpRiskReason implements \JsonSerializable */ public readonly ?string $reason; + /** + * @param array $response + */ public function __construct(array $response) { $this->code = $response['code']; $this->reason = $response['reason']; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/Issuer.php b/src/MinFraud/Model/Issuer.php index 2240972..03d22d1 100644 --- a/src/MinFraud/Model/Issuer.php +++ b/src/MinFraud/Model/Issuer.php @@ -38,6 +38,9 @@ class Issuer implements \JsonSerializable */ public readonly ?bool $matchesProvidedPhoneNumber; + /** + * @param array|null $response + */ public function __construct(?array $response) { $this->name = $response['name'] ?? null; @@ -48,6 +51,9 @@ public function __construct(?array $response) = $response['matches_provided_phone_number'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/Phone.php b/src/MinFraud/Model/Phone.php index 34ec9b7..b483ec7 100644 --- a/src/MinFraud/Model/Phone.php +++ b/src/MinFraud/Model/Phone.php @@ -38,6 +38,9 @@ class Phone implements \JsonSerializable */ public readonly ?string $numberType; + /** + * @param array|null $response + */ public function __construct(?array $response) { $this->country = $response['country'] ?? null; @@ -46,6 +49,9 @@ public function __construct(?array $response) $this->numberType = $response['number_type'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/Reason.php b/src/MinFraud/Model/Reason.php index e426070..ab1a3eb 100644 --- a/src/MinFraud/Model/Reason.php +++ b/src/MinFraud/Model/Reason.php @@ -66,12 +66,18 @@ class Reason implements \JsonSerializable */ public readonly string $reason; + /** + * @param array $response + */ public function __construct(array $response) { $this->code = $response['code']; $this->reason = $response['reason']; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/RiskScoreReason.php b/src/MinFraud/Model/RiskScoreReason.php index 3cbb1f7..e05b1c1 100644 --- a/src/MinFraud/Model/RiskScoreReason.php +++ b/src/MinFraud/Model/RiskScoreReason.php @@ -23,6 +23,9 @@ class RiskScoreReason implements \JsonSerializable */ public readonly array $reasons; + /** + * @param array|null $response + */ public function __construct(?array $response) { if ($response === null) { @@ -40,6 +43,9 @@ public function __construct(?array $response) $this->reasons = $reasons; } + /** + * @return array + */ public function jsonSerialize(): ?array { $js = []; diff --git a/src/MinFraud/Model/Score.php b/src/MinFraud/Model/Score.php index 2748167..6ff8352 100644 --- a/src/MinFraud/Model/Score.php +++ b/src/MinFraud/Model/Score.php @@ -50,13 +50,16 @@ class Score implements \JsonSerializable public readonly float $riskScore; /** - * @var array This array contains \MaxMind\MinFraud\Model\Warning objects - * detailing issues with the request that was sent, such as - * invalid or unknown inputs. It is highly recommended that you - * check this array for issues when integrating the web service. + * @var array This array contains \MaxMind\MinFraud\Model\Warning objects + * detailing issues with the request that was sent, such as + * invalid or unknown inputs. It is highly recommended that you + * check this array for issues when integrating the web service. */ public readonly array $warnings; + /** + * @param array $response + */ public function __construct(array $response) { $this->disposition @@ -77,6 +80,9 @@ public function __construct(array $response) $this->warnings = $warnings; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/ScoreIpAddress.php b/src/MinFraud/Model/ScoreIpAddress.php index 8cb1707..293fed5 100644 --- a/src/MinFraud/Model/ScoreIpAddress.php +++ b/src/MinFraud/Model/ScoreIpAddress.php @@ -16,11 +16,17 @@ class ScoreIpAddress implements \JsonSerializable */ public readonly ?float $risk; + /** + * @param array|null $response + */ public function __construct(?array $response) { $this->risk = $response['risk'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/ShippingAddress.php b/src/MinFraud/Model/ShippingAddress.php index 2d0ff15..fc512b5 100644 --- a/src/MinFraud/Model/ShippingAddress.php +++ b/src/MinFraud/Model/ShippingAddress.php @@ -23,6 +23,9 @@ class ShippingAddress extends Address */ public readonly ?bool $isHighRisk; + /** + * @param array|null $response + */ public function __construct(?array $response) { parent::__construct($response); @@ -31,6 +34,9 @@ public function __construct(?array $response) = $response['distance_to_billing_address'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = parent::jsonSerialize(); diff --git a/src/MinFraud/Model/Subscores.php b/src/MinFraud/Model/Subscores.php index 5638e9e..04eb072 100644 --- a/src/MinFraud/Model/Subscores.php +++ b/src/MinFraud/Model/Subscores.php @@ -133,6 +133,9 @@ class Subscores implements \JsonSerializable */ public readonly ?float $timeOfDay; + /** + * @param array|null $response + */ public function __construct(?array $response) { $this->avsResult = $response['avs_result'] ?? null; @@ -157,6 +160,9 @@ public function __construct(?array $response) $this->timeOfDay = $response['time_of_day'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/Model/Warning.php b/src/MinFraud/Model/Warning.php index 933ef3c..47d7e74 100644 --- a/src/MinFraud/Model/Warning.php +++ b/src/MinFraud/Model/Warning.php @@ -55,6 +55,9 @@ class Warning implements \JsonSerializable */ public readonly ?string $inputPointer; + /** + * @param array $response + */ public function __construct(array $response) { $this->code = $response['code']; @@ -62,6 +65,9 @@ public function __construct(array $response) $this->inputPointer = $response['input_pointer'] ?? null; } + /** + * @return array + */ public function jsonSerialize(): array { $js = []; diff --git a/src/MinFraud/ReportTransaction.php b/src/MinFraud/ReportTransaction.php index d92e99a..5c9914e 100644 --- a/src/MinFraud/ReportTransaction.php +++ b/src/MinFraud/ReportTransaction.php @@ -13,9 +13,9 @@ class ReportTransaction extends ServiceClient { /** - * @param int $accountId Your MaxMind account ID - * @param string $licenseKey Your MaxMind license key - * @param array $options An array of options. Possible keys: + * @param int $accountId Your MaxMind account ID + * @param string $licenseKey Your MaxMind license key + * @param array $options An array of options. Possible keys: * * * `host` - The host to use when connecting to the web service. * * `userAgent` - The prefix for the User-Agent header to use in the @@ -43,44 +43,44 @@ public function __construct( * updating the fraud score of future queries. The transaction should have * been previously submitted to minFraud. * - * @param array $values An array of transaction parameters. The keys are the same - * as the JSON keys. You may use either this or the named - * arguments, but not both. - * @param string $ipAddress Optional. The IP address of the customer placing the - * order. This should be passed as a string like - * "44.55.66.77" or "2001:db8::2:1". This field is not - * required if you provide at least one of the transaction's - * `maxmindId`, `minfraudId`, or `transactionId`. - * @param string $tag Required. A string indicating the likelihood that a - * transaction may be fraudulent. Possible values: - * not_fraud, suspected_fraud, spam_or_abuse, or - * chargeback. - * @param string $chargebackCode Optional. A string which is provided by your payment - * processor indicating the reason for the chargeback. - * @param string $maxmindId Optional. A unique eight character string identifying - * a minFraud Standard or Premium request. These IDs are - * returned in the `maxmindID` field of a response for a - * successful minFraud request. This field is not - * required if you provide at least one of the transaction's - * `ipAddress`, `minfraudId`, or `transactionId`. You are - * encouraged to provide it, if possible. - * @param string $minfraudId Optional. A UUID that identifies a minFraud Score, - * minFraud Insights, or minFraud Factors request. This - * ID is returned at /id in the response. This field is - * not required if you provide at least one of the transaction's - * `ipAddress`, `maxmindId`, or `transactionId`. You are - * encouraged to provide it if the request was made to one of - * these services. - * @param string $notes Optional. Your notes on the fraud tag associated with - * the transaction. We manually review many reported - * transactions to improve our scoring for you so any - * additional details to help us understand context are - * helpful. - * @param string $transactionId Optional. The transaction ID you originally passed to - * minFraud. This field is not required if you provide at - * least one of the transaction's `ipAddress`, `maxmindId`, or - * `minfraudId`. You are encouraged to provide it or the - * transaction's `maxmindId` or `minfraudId`. + * @param array $values An array of transaction parameters. The keys are the same + * as the JSON keys. You may use either this or the named + * arguments, but not both. + * @param string $ipAddress Optional. The IP address of the customer placing the + * order. This should be passed as a string like + * "44.55.66.77" or "2001:db8::2:1". This field is not + * required if you provide at least one of the transaction's + * `maxmindId`, `minfraudId`, or `transactionId`. + * @param string $tag Required. A string indicating the likelihood that a + * transaction may be fraudulent. Possible values: + * not_fraud, suspected_fraud, spam_or_abuse, or + * chargeback. + * @param string $chargebackCode Optional. A string which is provided by your payment + * processor indicating the reason for the chargeback. + * @param string $maxmindId Optional. A unique eight character string identifying + * a minFraud Standard or Premium request. These IDs are + * returned in the `maxmindID` field of a response for a + * successful minFraud request. This field is not + * required if you provide at least one of the transaction's + * `ipAddress`, `minfraudId`, or `transactionId`. You are + * encouraged to provide it, if possible. + * @param string $minfraudId Optional. A UUID that identifies a minFraud Score, + * minFraud Insights, or minFraud Factors request. This + * ID is returned at /id in the response. This field is + * not required if you provide at least one of the transaction's + * `ipAddress`, `maxmindId`, or `transactionId`. You are + * encouraged to provide it if the request was made to one of + * these services. + * @param string $notes Optional. Your notes on the fraud tag associated with + * the transaction. We manually review many reported + * transactions to improve our scoring for you so any + * additional details to help us understand context are + * helpful. + * @param string $transactionId Optional. The transaction ID you originally passed to + * minFraud. This field is not required if you provide at + * least one of the transaction's `ipAddress`, `maxmindId`, or + * `minfraudId`. You are encouraged to provide it or the + * transaction's `maxmindId` or `minfraudId`. * * @throws InvalidInputException when the request has missing or invalid * data diff --git a/src/MinFraud/ServiceClient.php b/src/MinFraud/ServiceClient.php index d24af3f..c0d059a 100644 --- a/src/MinFraud/ServiceClient.php +++ b/src/MinFraud/ServiceClient.php @@ -9,7 +9,7 @@ abstract class ServiceClient { - public const VERSION = 'v3.2.0-beta.1'; + public const VERSION = 'v3.2.0-beta.2'; /** * @var Client @@ -31,6 +31,11 @@ abstract class ServiceClient */ protected $validateInput = true; + /** + * @param int $accountId your account ID + * @param string $licenseKey your license key + * @param array $options options for the client + */ public function __construct( int $accountId, string $licenseKey, @@ -62,6 +67,13 @@ protected function maybeThrowInvalidInputException(string $msg): void } } + /** + * @ignore + * + * @param array $array the parent array + * @param string $key the key to remove + * @param list $types the expected types + */ protected function remove(array &$array, string $key, array $types = ['string']): mixed { if (\array_key_exists($key, $array)) { @@ -80,6 +92,9 @@ protected function remove(array &$array, string $key, array $types = ['string']) return null; } + /** + * @param array $values + */ protected function verifyEmpty(array $values): void { if (\count($values) !== 0) { diff --git a/src/MinFraud/Util.php b/src/MinFraud/Util.php index ce0ff5d..8057b80 100644 --- a/src/MinFraud/Util.php +++ b/src/MinFraud/Util.php @@ -280,6 +280,10 @@ class Util /** * @ignore + * + * @param array $values + * + * @return array */ public static function maybeHashEmail(array $values): array { @@ -375,6 +379,11 @@ private static function hashEmail(string $localPart, string $domain): string return md5("$localPart@$domain"); } + /** + * @param array $values + * + * @return array + */ public static function cleanCreditCard(array $values): array { if (isset($values['last_4_digits'])) { diff --git a/tests/MaxMind/Test/MinFraud/Model/ScoreTest.php b/tests/MaxMind/Test/MinFraud/Model/ScoreTest.php index 3b7a614..0df804f 100644 --- a/tests/MaxMind/Test/MinFraud/Model/ScoreTest.php +++ b/tests/MaxMind/Test/MinFraud/Model/ScoreTest.php @@ -16,6 +16,9 @@ */ class ScoreTest extends TestCase { + /** + * @return array + */ protected function response(): array { return Data::scoreFullResponse(); diff --git a/tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionData.php b/tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionData.php index a339efb..0fc3a00 100644 --- a/tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionData.php +++ b/tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionData.php @@ -6,16 +6,25 @@ class ReportTransactionData { + /** + * @return array + */ public static function fullRequest(): array { return self::decodeFile('full-request.json'); } + /** + * @return array + */ public static function minimalRequest(): array { return self::decodeFile('minimal-request.json'); } + /** + * @return array + */ private static function decodeFile(string $file): array { $contents = file_get_contents('tests/data/minfraud/reporttransaction/' . $file); diff --git a/tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionTest.php b/tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionTest.php index 4f65d42..b6184ce 100644 --- a/tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionTest.php +++ b/tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionTest.php @@ -91,6 +91,8 @@ public function testRequiredFields(): void /** * @dataProvider requestsMissingRequiredFields + * + * @param array $req */ public function testMissingRequiredFields(array $req): void { @@ -105,6 +107,8 @@ public function testMissingRequiredFields(array $req): void /** * @dataProvider requestsMissingRequiredFields + * + * @param array $req */ public function testMissingRequiredFieldsWithoutValidation(array $req): void { @@ -118,6 +122,9 @@ public function testMissingRequiredFieldsWithoutValidation(array $req): void )->report($req); } + /** + * @return array>> + */ public static function requestsMissingRequiredFields(): array { return [ @@ -208,6 +215,9 @@ public function testInvalidTransactionIds($transactionId): void )->report($req); } + /** + * @return list> + */ public static function notStringTypes(): array { return [ @@ -235,6 +245,9 @@ public function testInvalidIpAddresses(string $ip): void )->report($req); } + /** + * @return list> + */ public static function invalidIpAddresses(): array { return [ @@ -262,6 +275,9 @@ public function testInvalidMaxmindIds(string $maxmindId): void )->report($req); } + /** + * @return list> + */ public static function invalidMaxmindIds(): array { return [ @@ -289,6 +305,9 @@ public function testInvalidMinfraudIds(string $minfraudId): void )->report($req); } + /** + * @return list> + */ public static function invalidMinfraudIds(): array { return [ @@ -316,6 +335,9 @@ public function testInvalidTags(string $tag): void )->report($req); } + /** + * @return list> + */ public static function invalidTags(): array { return [ @@ -324,6 +346,11 @@ public static function invalidTags(): array ]; } + /** + * @param array $requestContent + * @param array $options + * @param $responseBody string|null + */ private function createReportTransactionRequest( array $requestContent, int $callsToRequest = 1, @@ -332,8 +359,7 @@ private function createReportTransactionRequest( string $contentType = 'application/json', ?string $responseBody = null ): ReportTransaction { - // @phpstan-ignore-next-line - return $this->createRequest( + $rv = $this->createRequest( '\MaxMind\MinFraud\ReportTransaction', 'transactions/report', $requestContent, @@ -343,5 +369,11 @@ private function createReportTransactionRequest( $options, $callsToRequest ); + + if (!$rv instanceof ReportTransaction) { + throw new \Exception('Unexpected client type!'); + } + + return $rv; } } diff --git a/tests/MaxMind/Test/MinFraud/ServiceClientTester.php b/tests/MaxMind/Test/MinFraud/ServiceClientTester.php index 688b481..7fce8ac 100644 --- a/tests/MaxMind/Test/MinFraud/ServiceClientTester.php +++ b/tests/MaxMind/Test/MinFraud/ServiceClientTester.php @@ -15,6 +15,11 @@ */ abstract class ServiceClientTester extends TestCase { + /** + * @param array $requestContent + * @param $responseBody string|null + * @param array $options + */ protected function createRequest( string $class, string $urlTail, diff --git a/tests/MaxMind/Test/MinFraud/UtilTest.php b/tests/MaxMind/Test/MinFraud/UtilTest.php index 56e8d6b..6c50757 100644 --- a/tests/MaxMind/Test/MinFraud/UtilTest.php +++ b/tests/MaxMind/Test/MinFraud/UtilTest.php @@ -292,9 +292,6 @@ public function testMaybeHashEmail(): void if (\function_exists('idn_to_ascii') && idn_to_ascii('bücher.com', \IDNA_NONTRANSITIONAL_TO_ASCII, \INTL_IDNA_VARIANT_UTS46) === 'xn--bcher-kva.com' - // This test fails on this combo and it is hard to tell what is going on - // without actual access to such a machine. - && (\PHP_OS !== 'Darwin' || \PHP_MAJOR_VERSION !== 7) ) { array_push( $tests, diff --git a/tests/MaxMind/Test/MinFraudData.php b/tests/MaxMind/Test/MinFraudData.php index 181c93c..39734a7 100644 --- a/tests/MaxMind/Test/MinFraudData.php +++ b/tests/MaxMind/Test/MinFraudData.php @@ -6,26 +6,41 @@ class MinFraudData { + /** + * @return array + */ public static function factorsFullResponse(): array { return self::decodeFile('factors-response.json'); } + /** + * @return array + */ public static function insightsFullResponse(): array { return self::decodeFile('insights-response.json'); } + /** + * @return array + */ public static function scoreFullResponse(): array { return self::decodeFile('score-response.json'); } + /** + * @return array + */ public static function fullRequest(): array { return self::decodeFile('full-request.json'); } + /** + * @return array + */ private static function decodeFile(string $file): array { $contents = file_get_contents('tests/data/minfraud/' . $file); @@ -39,6 +54,9 @@ private static function decodeFile(string $file): array return $a; } + /** + * @param array $array + */ private static function recursiveKSort(array &$array): void { ksort($array); diff --git a/tests/MaxMind/Test/MinFraudTest.php b/tests/MaxMind/Test/MinFraudTest.php index 0200d98..76f58e0 100644 --- a/tests/MaxMind/Test/MinFraudTest.php +++ b/tests/MaxMind/Test/MinFraudTest.php @@ -405,6 +405,9 @@ public function testUnknownKeys(string $method): void )->{$method}(['unknown' => 'some value']); } + /** + * @return array> + */ public static function withMethods(): array { return [ @@ -448,6 +451,9 @@ public function testEmailWithBadAddress(string $md5): void )->withEmail(['address' => $md5]); } + /** + * @return array> + */ public static function badMd5s(): array { return [ @@ -472,6 +478,9 @@ public function testBadRegions(string $method, string $region): void )->{$method}(['region' => $region]); } + /** + * @return array> + */ public static function badRegions(): array { return [ @@ -493,6 +502,9 @@ public function testGoodCountryCode(string $method, string $code): void )->{$method}(['country' => $code]); } + /** + * @return array> + */ public static function goodCountryCodes(): array { return self::generateTestData( @@ -517,6 +529,9 @@ public function testBadCountryCode(string $method, $code): void )->{$method}(['country' => $code]); } + /** + * @return array> + */ public static function badCountryCodes(): array { return self::generateTestData( @@ -533,6 +548,12 @@ public static function badCountryCodes(): array ); } + /** + * @param list $methods + * @param list $values + * + * @return array> + */ private static function generateTestData(array $methods, array $values): array { $tests = []; @@ -559,6 +580,9 @@ public function testBadPhoneCodes(string $method, string $key, string $code): vo )->{$method}([$key => $code]); } + /** + * @return array> + */ public static function badPhoneCodes(): array { return [ @@ -596,6 +620,9 @@ public function testBadIin(string $iin): void )->withCreditCard(['issuer_id_number' => $iin]); } + /** + * @return array> + */ public static function badIins(): array { return [ @@ -619,6 +646,9 @@ public function testCreditCardWithBadLastDigits(string $lastDigits): void )->withCreditCard(['last_digits' => $lastDigits]); } + /** + * @return array> + */ public static function badLastDigits(): array { return [ @@ -658,6 +688,9 @@ public function testCreditCardWithNumericToken(string $token): void )->withCreditCard(['token' => $token]); } + /** + * @return array> + */ public static function numericToken(): array { return [ @@ -680,6 +713,9 @@ public function testCreditCardWithInvalidRangeToken(string $token): void )->withCreditCard(['token' => $token]); } + /** + * @return array> + */ public static function invalidRangeToken(): array { return [ @@ -702,6 +738,9 @@ public function testCreditCardWithLongToken(string $token): void )->withCreditCard(['token' => $token]); } + /** + * @return array> + */ public static function longToken(): array { return [ @@ -720,6 +759,9 @@ public function testCreditCardWithGoodToken(string $token): void )->withCreditCard(['token' => $token]); } + /** + * @return array> + */ public static function goodToken(): array { return [ @@ -743,6 +785,9 @@ public function testAvsAndCCv(string $key): void )->withCreditCard([$key => 'Aa']); } + /** + * @return array> + */ public static function avsAndCvv(): array { return [ @@ -765,6 +810,9 @@ public function testBadIps(string $ip): void )->withDevice(['ip_address' => $ip]); } + /** + * @return array> + */ public static function badIps(): array { return [ @@ -789,6 +837,9 @@ public function testNegativeSessionAge(int $age): void )->withDevice(['ip_address' => '1.2.3.4', 'session_age' => $age]); } + /** + * @return array> + */ public static function negativeSessionAge(): array { return [ @@ -810,6 +861,9 @@ public function testBadSessionAge(string $age): void )->withDevice(['session_age' => $age]); } + /** + * @return array> + */ public static function badSessionAge(): array { return [ @@ -830,6 +884,9 @@ public function testGoodSessionAge($age): void )->withDevice(['session_age' => $age]); } + /** + * @return array> + */ public static function goodSessionAge(): array { return [ @@ -854,6 +911,9 @@ public function testBadSessionId(string $id): void )->withDevice(['ip_address' => '1.2.3.4', 'session_id' => $id]); } + /** + * @return array> + */ public static function badSessionId(): array { return [ @@ -872,6 +932,9 @@ public function testGoodSessionId(int $id): void )->withDevice(['ip_address' => '1.2.3.4', 'session_id' => $id]); } + /** + * @return array> + */ public static function goodSessionId(): array { return [ @@ -891,6 +954,9 @@ public function testGoodIps(string $ip): void )->withDevice(['ip_address' => $ip]); } + /** + * @return array> + */ public static function goodIps(): array { return [ @@ -914,6 +980,9 @@ public function testBadDomains(string $domain): void )->withEmail(['domain' => $domain]); } + /** + * @return array> + */ public static function badDomains(): array { return [ @@ -933,6 +1002,9 @@ public function testGoodDomains(string $domain): void )->withEmail(['domain' => $domain]); } + /** + * @return array> + */ public static function goodDomains(): array { return [ @@ -953,6 +1025,9 @@ public function testGoodEventTimes(string $time): void )->withEvent(['time' => $time]); } + /** + * @return array> + */ public static function goodTimes(): array { $tests = [ @@ -960,13 +1035,11 @@ public static function goodTimes(): array ['2014-04-12T23:20:50Z'], ]; - if (\PHP_VERSION_ID >= 70300) { - array_push( - $tests, - ['2014-04-12T23:20:50.052+01:00'], - ['2014-04-12T23:20:50.052Z'] - ); - } + array_push( + $tests, + ['2014-04-12T23:20:50.052+01:00'], + ['2014-04-12T23:20:50.052Z'] + ); return $tests; } @@ -993,6 +1066,9 @@ public function testGoodEventType(string $good): void )->withEvent(['type' => $good]); } + /** + * @return array> + */ public static function goodEventTypes(): array { return [ @@ -1033,6 +1109,9 @@ public function testBadCurrency(string $currency): void )->withOrder(['currency' => $currency]); } + /** + * @return array> + */ public static function badCurrency(): array { return [ @@ -1057,6 +1136,9 @@ public function testBadReferrerUri(string $uri): void )->withOrder(['referrer_uri' => $uri]); } + /** + * @return array> + */ public static function badReferrerUri(): array { return [ @@ -1098,6 +1180,9 @@ public function testGoodShoppingCartItemPrice(float $value): void )->withShoppingCartItem(['price' => $value]); } + /** + * @return array> + */ public static function validAmounts(): array { return [ @@ -1124,6 +1209,9 @@ public function testBadOrderAmount($value): void )->withOrder(['amount' => $value]); } + /** + * @return array> + */ public static function invalidAmounts(): array { return [ @@ -1165,6 +1253,9 @@ public function testBadShoppingCartItemQuantity($value): void )->withShoppingCartItem(['quantity' => $value]); } + /** + * @return array> + */ public static function invalidQuantities(): array { return [ @@ -1184,9 +1275,14 @@ public function testBadShoppingCartItemWithDoubleArray(): void $this->createMinFraudRequestWithFullResponse( 'insights', 0 + // We are testing invalid inputs here. + // @phpstan-ignore-next-line )->withShoppingCartItem([['price' => 1]]); } + /** + * @return array> + */ public static function services(): array { return [ @@ -1198,6 +1294,8 @@ public static function services(): array /** * @dataProvider badCustomInputs + * + * @param array $inputs */ public function testBadCustomInputs(array $inputs): void { @@ -1210,6 +1308,9 @@ public function testBadCustomInputs(array $inputs): void )->withCustomInputs($inputs); } + /** + * @return array> + */ public static function badCustomInputs(): array { return [ @@ -1222,6 +1323,10 @@ public static function badCustomInputs(): array ]; } + /** + * @param array $options + * @param array|null $request + */ private function createMinFraudRequestWithFullResponse( string $service, int $callsToRequest = 1, @@ -1245,6 +1350,11 @@ private function createMinFraudRequestWithFullResponse( ); } + /** + * @param array $requestContent + * @param $responseBody string|null + * @param array $options + */ private function createMinFraudRequest( string $service, array $requestContent,