diff --git a/.gitignore b/.gitignore index a1372b3..c9b5c4b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ composer.lock .subsplit .php_cs.cache .php-cs-fixer.cache +.pint.cache .idea /index.php /config.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php deleted file mode 100644 index 27db30d..0000000 --- a/.php-cs-fixer.dist.php +++ /dev/null @@ -1,12 +0,0 @@ -setRules([ - '@Symfony' => true, - ]) - ->setFinder( - PhpCsFixer\Finder::create() - ->exclude('vendor') - ->in([__DIR__.'/src/', __DIR__.'/tests/']) - ) -; diff --git a/composer.json b/composer.json index dd8cfa7..d27030a 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "phpunit/phpunit": "^9.5.8", "mockery/mockery": "^1.4.2", "jetbrains/phpstorm-attributes": "^1.0", - "friendsofphp/php-cs-fixer": "^3.54" + "laravel/pint": "^1.0" }, "autoload": { "psr-4": { @@ -33,8 +33,9 @@ ], "scripts": { "phpstan": "phpstan analyse", - "check-style": "php-cs-fixer fix --using-cache=no --diff --config=.php-cs-fixer.dist.php --dry-run --allow-risky=yes --ansi", - "fix-style": "php-cs-fixer fix --using-cache=no --config=.php-cs-fixer.dist.php --allow-risky=yes --ansi", + "check-style": "pint --test", + "fix-style": "pint", + "fix": "pint", "test": "phpunit --colors", "psalm": "psalm --show-info=true --no-cache", "psalm-fix": "psalm --no-cache --alter --issues=MissingReturnType,MissingParamType" diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..93061b6 --- /dev/null +++ b/pint.json @@ -0,0 +1,3 @@ +{ + "preset": "laravel" +} diff --git a/src/EasySms.php b/src/EasySms.php index d927834..8adf754 100644 --- a/src/EasySms.php +++ b/src/EasySms.php @@ -73,7 +73,7 @@ public function send(array|string $to, MessageInterface|array $message, array $g */ public function gateway(?string $name): GatewayInterface { - if (!isset($this->gateways[$name])) { + if (! isset($this->gateways[$name])) { $this->gateways[$name] = $this->createGateway($name); } @@ -91,15 +91,15 @@ public function strategy(?string $strategy = null): StrategyInterface $strategy = $this->config->get('default.strategy', OrderStrategy::class); } - if (!\class_exists($strategy)) { - $strategy = __NAMESPACE__ . '\Strategies\\' . \ucfirst($strategy); + if (! \class_exists($strategy)) { + $strategy = __NAMESPACE__.'\Strategies\\'.\ucfirst($strategy); } - if (!\class_exists($strategy)) { + if (! \class_exists($strategy)) { throw new InvalidArgumentException("Unsupported strategy \"{$strategy}\""); } - if (empty($this->strategies[$strategy]) || !($this->strategies[$strategy] instanceof StrategyInterface)) { + if (empty($this->strategies[$strategy]) || ! ($this->strategies[$strategy] instanceof StrategyInterface)) { $this->strategies[$strategy] = new $strategy($this); } @@ -138,7 +138,7 @@ protected function createGateway(string $name): GatewayInterface { $config = $this->config->get("gateways.{$name}", []); - if (!isset($config['timeout'])) { + if (! isset($config['timeout'])) { $config['timeout'] = $this->config->get('timeout', Gateway::DEFAULT_TIMEOUT); } @@ -151,7 +151,7 @@ protected function createGateway(string $name): GatewayInterface $gateway = $this->makeGateway($className, $config); } - if (!($gateway instanceof GatewayInterface)) { + if (! ($gateway instanceof GatewayInterface)) { throw new InvalidArgumentException(\sprintf('Gateway "%s" must implement interface %s.', $name, GatewayInterface::class)); } @@ -165,7 +165,7 @@ protected function createGateway(string $name): GatewayInterface */ protected function makeGateway(string $gateway, array $config): GatewayInterface { - if (!\class_exists($gateway) || !\in_array(GatewayInterface::class, \class_implements($gateway))) { + if (! \class_exists($gateway) || ! \in_array(GatewayInterface::class, \class_implements($gateway))) { throw new InvalidArgumentException(\sprintf('Class "%s" is a invalid easy-sms gateway.', $gateway)); } @@ -183,7 +183,7 @@ protected function formatGatewayClassName(string $name): string $name = \ucfirst(\str_replace(['-', '_', ''], '', $name)); - return __NAMESPACE__ . "\\Gateways\\{$name}Gateway"; + return __NAMESPACE__."\\Gateways\\{$name}Gateway"; } /** @@ -205,10 +205,10 @@ protected function formatPhoneNumber(PhoneNumberInterface|string $number): Phone protected function formatMessage(MessageInterface|array|string $message): MessageInterface { - if (!($message instanceof MessageInterface)) { - if (!\is_array($message)) { + if (! ($message instanceof MessageInterface)) { + if (! \is_array($message)) { $message = [ - 'content' => $message, + 'content' => $message, 'template' => $message, ]; } @@ -235,7 +235,7 @@ protected function formatGateways(array $gateways): array $formatted[$gateway] = $setting; $globalSettings = $this->config->get("gateways.{$gateway}", []); - if (\is_string($gateway) && !empty($globalSettings) && \is_array($setting)) { + if (\is_string($gateway) && ! empty($globalSettings) && \is_array($setting)) { $formatted[$gateway] = new Config(\array_merge($globalSettings, $setting)); } } @@ -248,4 +248,4 @@ protected function formatGateways(array $gateways): array return $result; } -} \ No newline at end of file +} diff --git a/src/Exceptions/Exception.php b/src/Exceptions/Exception.php index 079d415..e74378f 100644 --- a/src/Exceptions/Exception.php +++ b/src/Exceptions/Exception.php @@ -16,6 +16,4 @@ * * @author overtrue */ -class Exception extends \Exception -{ -} +class Exception extends \Exception {} diff --git a/src/Exceptions/GatewayErrorException.php b/src/Exceptions/GatewayErrorException.php index 084aec5..2da718f 100644 --- a/src/Exceptions/GatewayErrorException.php +++ b/src/Exceptions/GatewayErrorException.php @@ -24,8 +24,8 @@ class GatewayErrorException extends Exception /** * GatewayErrorException constructor. * - * @param string $message - * @param int $code + * @param string $message + * @param int $code */ public function __construct($message, $code, array $raw = []) { diff --git a/src/Exceptions/InvalidArgumentException.php b/src/Exceptions/InvalidArgumentException.php index c2be998..6f04363 100644 --- a/src/Exceptions/InvalidArgumentException.php +++ b/src/Exceptions/InvalidArgumentException.php @@ -14,6 +14,4 @@ /** * Class InvalidArgumentException. */ -class InvalidArgumentException extends Exception -{ -} +class InvalidArgumentException extends Exception {} diff --git a/src/Exceptions/NoGatewayAvailableException.php b/src/Exceptions/NoGatewayAvailableException.php index edc1622..98dd7d2 100644 --- a/src/Exceptions/NoGatewayAvailableException.php +++ b/src/Exceptions/NoGatewayAvailableException.php @@ -31,7 +31,7 @@ class NoGatewayAvailableException extends Exception /** * NoGatewayAvailableException constructor. * - * @param int $code + * @param int $code */ public function __construct(array $results = [], $code = 0, ?\Throwable $previous = null) { @@ -50,8 +50,7 @@ public function getResults() } /** - * @param string $gateway - * + * @param string $gateway * @return mixed|null */ public function getException($gateway) diff --git a/src/Gateways/AliyunGateway.php b/src/Gateways/AliyunGateway.php index cece11c..7c15838 100644 --- a/src/Gateways/AliyunGateway.php +++ b/src/Gateways/AliyunGateway.php @@ -51,7 +51,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config { $data = $message->getData($this); - $signName = !empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name'); + $signName = ! empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name'); unset($data['sign_name']); @@ -65,7 +65,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'), 'Action' => self::ENDPOINT_METHOD, 'Version' => self::ENDPOINT_VERSION, - 'PhoneNumbers' => !\is_null($to->getIDDCode()) ? strval($to->getZeroPrefixedNumber()) : $to->getNumber(), + 'PhoneNumbers' => ! \is_null($to->getIDDCode()) ? strval($to->getZeroPrefixedNumber()) : $to->getNumber(), 'SignName' => $signName, 'TemplateCode' => $message->getTemplate($this), 'TemplateParam' => json_encode($data, JSON_FORCE_OBJECT), @@ -75,7 +75,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->get(self::ENDPOINT_URL, $params); - if (!empty($result['Code']) && 'OK' != $result['Code']) { + if (! empty($result['Code']) && $result['Code'] != 'OK') { throw new GatewayErrorException($result['Message'], $result['Code'], $result); } @@ -85,8 +85,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Generate Sign. * - * @param array $params - * + * @param array $params * @return string * * @see https://help.aliyun.com/document_detail/101343.html diff --git a/src/Gateways/AliyunIntlGateway.php b/src/Gateways/AliyunIntlGateway.php index fd90eae..37913fb 100644 --- a/src/Gateways/AliyunIntlGateway.php +++ b/src/Gateways/AliyunIntlGateway.php @@ -40,7 +40,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config { $data = $message->getData($this); - $signName = !empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name'); + $signName = ! empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name'); unset($data['sign_name']); @@ -53,7 +53,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'SignatureNonce' => uniqid('', true), 'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'), 'Version' => self::ENDPOINT_VERSION, - 'To' => !\is_null($to->getIDDCode()) ? (int) $to->getZeroPrefixedNumber() : $to->getNumber(), + 'To' => ! \is_null($to->getIDDCode()) ? (int) $to->getZeroPrefixedNumber() : $to->getNumber(), 'Action' => self::ENDPOINT_ACTION, 'From' => $signName, 'TemplateCode' => $message->getTemplate($this), @@ -64,7 +64,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->get(self::ENDPOINT_URL, $params); - if ('OK' !== $result['ResponseCode']) { + if ($result['ResponseCode'] !== 'OK') { throw new GatewayErrorException($result['ResponseDescription'], $result['ResponseCode'], $result); } diff --git a/src/Gateways/AliyunrestGateway.php b/src/Gateways/AliyunrestGateway.php index b4dfb6d..0c6020e 100644 --- a/src/Gateways/AliyunrestGateway.php +++ b/src/Gateways/AliyunrestGateway.php @@ -56,14 +56,14 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'sms_type' => 'normal', 'sms_free_sign_name' => $config->get('sign_name'), 'sms_param' => json_encode($message->getData($this)), - 'rec_num' => !\is_null($to->getIDDCode()) ? strval($to->getZeroPrefixedNumber()) : $to->getNumber(), + 'rec_num' => ! \is_null($to->getIDDCode()) ? strval($to->getZeroPrefixedNumber()) : $to->getNumber(), 'sms_template_code' => $message->getTemplate($this), ]; $urlParams['sign'] = $this->generateSign(array_merge($params, $urlParams)); $result = $this->post($this->getEndpointUrl($urlParams), $params); - if (isset($result['error_response']) && 0 != $result['error_response']['code']) { + if (isset($result['error_response']) && $result['error_response']['code'] != 0) { throw new GatewayErrorException($result['error_response']['msg'], $result['error_response']['code'], $result); } @@ -71,8 +71,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config } /** - * @param array $params - * + * @param array $params * @return string */ protected function getEndpointUrl($params) @@ -81,8 +80,7 @@ protected function getEndpointUrl($params) } /** - * @param array $params - * + * @param array $params * @return string */ protected function generateSign($params) @@ -91,7 +89,7 @@ protected function generateSign($params) $stringToBeSigned = $this->config->get('app_secret_key'); foreach ($params as $k => $v) { - if (!is_array($v) && '@' != substr($v, 0, 1)) { + if (! is_array($v) && substr($v, 0, 1) != '@') { $stringToBeSigned .= "$k$v"; } } diff --git a/src/Gateways/BaiduGateway.php b/src/Gateways/BaiduGateway.php index af7378a..2b34de2 100644 --- a/src/Gateways/BaiduGateway.php +++ b/src/Gateways/BaiduGateway.php @@ -51,12 +51,12 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'template' => $message->getTemplate($this), 'contentVar' => $message->getData($this), ]; - if (!empty($params['contentVar']['custom'])) { + if (! empty($params['contentVar']['custom'])) { // 用户自定义参数,格式为字符串,状态回调时会回传该值 $params['custom'] = $params['contentVar']['custom']; unset($params['contentVar']['custom']); } - if (!empty($params['contentVar']['userExtId'])) { + if (! empty($params['contentVar']['userExtId'])) { // 通道自定义扩展码,上行回调时会回传该值,其格式为纯数字串。默认为不开通,请求时无需设置该参数。如需开通请联系客服申请 $params['userExtId'] = $params['contentVar']['userExtId']; unset($params['contentVar']['userExtId']); @@ -76,7 +76,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->request('post', self::buildEndpoint($config), ['headers' => $headers, 'json' => $params]); - if (self::SUCCESS_CODE != $result['code']) { + if ($result['code'] != self::SUCCESS_CODE) { throw new GatewayErrorException($result['message'], $result['code'], $result); } @@ -96,8 +96,7 @@ protected function buildEndpoint(Config $config) /** * Generate Authorization header. * - * @param int $datetime - * + * @param int $datetime * @return string */ protected function generateSign(array $signHeaders, $datetime, Config $config) diff --git a/src/Gateways/ChuanglanGateway.php b/src/Gateways/ChuanglanGateway.php index 0a7fafb..7afe979 100644 --- a/src/Gateways/ChuanglanGateway.php +++ b/src/Gateways/ChuanglanGateway.php @@ -55,7 +55,7 @@ class ChuanglanGateway extends Gateway */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { - $IDDCode = !empty($to->getIDDCode()) ? $to->getIDDCode() : 86; + $IDDCode = ! empty($to->getIDDCode()) ? $to->getIDDCode() : 86; $params = [ 'account' => $config->get('account'), @@ -64,7 +64,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'msg' => $this->wrapChannelContent($message->getContent($this), $config, $IDDCode), ]; - if (86 != $IDDCode) { + if ($IDDCode != 86) { $params['mobile'] = $to->getIDDCode().$to->getNumber(); $params['account'] = $config->get('intel_account') ?: $config->get('account'); $params['password'] = $config->get('intel_password') ?: $config->get('password'); @@ -72,7 +72,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->postJson($this->buildEndpoint($config, $IDDCode), $params); - if (!isset($result['code']) || '0' != $result['code']) { + if (! isset($result['code']) || $result['code'] != '0') { throw new GatewayErrorException(json_encode($result, JSON_UNESCAPED_UNICODE), isset($result['code']) ? $result['code'] : 0, $result); } @@ -80,8 +80,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config } /** - * @param int $IDDCode - * + * @param int $IDDCode * @return string * * @throws InvalidArgumentException @@ -90,7 +89,7 @@ protected function buildEndpoint(Config $config, $IDDCode = 86) { $channel = $this->getChannel($config, $IDDCode); - if (self::INT_URL === $channel) { + if ($channel === self::INT_URL) { return $channel; } @@ -98,18 +97,18 @@ protected function buildEndpoint(Config $config, $IDDCode = 86) } /** - * @param int $IDDCode + * @param int $IDDCode * * @throws InvalidArgumentException */ protected function getChannel(Config $config, $IDDCode) { - if (86 != $IDDCode) { + if ($IDDCode != 86) { return self::INT_URL; } $channel = $config->get('channel', self::CHANNEL_VALIDATE_CODE); - if (!in_array($channel, [self::CHANNEL_VALIDATE_CODE, self::CHANNEL_PROMOTION_CODE])) { + if (! in_array($channel, [self::CHANNEL_VALIDATE_CODE, self::CHANNEL_PROMOTION_CODE])) { throw new InvalidArgumentException('Invalid channel for ChuanglanGateway.'); } @@ -117,9 +116,8 @@ protected function getChannel(Config $config, $IDDCode) } /** - * @param string $content - * @param int $IDDCode - * + * @param string $content + * @param int $IDDCode * @return string|string * * @throws InvalidArgumentException @@ -128,7 +126,7 @@ protected function wrapChannelContent($content, Config $config, $IDDCode) { $channel = $this->getChannel($config, $IDDCode); - if (self::CHANNEL_PROMOTION_CODE == $channel) { + if ($channel == self::CHANNEL_PROMOTION_CODE) { $sign = (string) $config->get('sign', ''); if (empty($sign)) { throw new InvalidArgumentException('Invalid sign for ChuanglanGateway when using promotion channel'); diff --git a/src/Gateways/Chuanglanv1Gateway.php b/src/Gateways/Chuanglanv1Gateway.php index a89bcf9..9df5eb2 100644 --- a/src/Gateways/Chuanglanv1Gateway.php +++ b/src/Gateways/Chuanglanv1Gateway.php @@ -55,7 +55,7 @@ class Chuanglanv1Gateway extends Gateway */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { - $IDDCode = !empty($to->getIDDCode()) ? $to->getIDDCode() : 86; + $IDDCode = ! empty($to->getIDDCode()) ? $to->getIDDCode() : 86; $params = [ 'account' => $config->get('account'), @@ -63,13 +63,13 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'report' => $config->get('needstatus') ?? false, ]; - if (86 != $IDDCode) { + if ($IDDCode != 86) { $params['mobile'] = $to->getIDDCode().$to->getNumber(); $params['account'] = $config->get('intel_account') ?: $config->get('account'); $params['password'] = $config->get('intel_password') ?: $config->get('password'); } - if (self::CHANNEL_VARIABLE_CODE == $this->getChannel($config, $IDDCode)) { + if ($this->getChannel($config, $IDDCode) == self::CHANNEL_VARIABLE_CODE) { $params['params'] = $message->getData($this); $params['msg'] = $this->wrapChannelContent($message->getTemplate($this), $config, $IDDCode); } else { @@ -79,7 +79,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->postJson($this->buildEndpoint($config, $IDDCode), $params); - if (!isset($result['code']) || '0' != $result['code']) { + if (! isset($result['code']) || $result['code'] != '0') { throw new GatewayErrorException(json_encode($result, JSON_UNESCAPED_UNICODE), isset($result['code']) ? $result['code'] : 0, $result); } @@ -87,8 +87,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config } /** - * @param int $IDDCode - * + * @param int $IDDCode * @return string * * @throws InvalidArgumentException @@ -97,7 +96,7 @@ protected function buildEndpoint(Config $config, $IDDCode = 86) { $channel = $this->getChannel($config, $IDDCode); - if (self::INT_URL === $channel) { + if ($channel === self::INT_URL) { return $channel; } @@ -105,18 +104,18 @@ protected function buildEndpoint(Config $config, $IDDCode = 86) } /** - * @param int $IDDCode + * @param int $IDDCode * * @throws InvalidArgumentException */ protected function getChannel(Config $config, $IDDCode) { - if (86 != $IDDCode) { + if ($IDDCode != 86) { return self::INT_URL; } $channel = $config->get('channel', self::CHANNEL_NORMAL_CODE); - if (!in_array($channel, [self::CHANNEL_NORMAL_CODE, self::CHANNEL_VARIABLE_CODE])) { + if (! in_array($channel, [self::CHANNEL_NORMAL_CODE, self::CHANNEL_VARIABLE_CODE])) { throw new InvalidArgumentException('Invalid channel for ChuanglanGateway.'); } @@ -124,9 +123,8 @@ protected function getChannel(Config $config, $IDDCode) } /** - * @param string $content - * @param int $IDDCode - * + * @param string $content + * @param int $IDDCode * @return string|string * * @throws InvalidArgumentException diff --git a/src/Gateways/CtyunGateway.php b/src/Gateways/CtyunGateway.php index 7272c09..52f40be 100644 --- a/src/Gateways/CtyunGateway.php +++ b/src/Gateways/CtyunGateway.php @@ -69,7 +69,7 @@ protected function execute(string $url, array $data) $headers['eop-date'] = $time; $result = $this->postJson($url, $data, $headers); - if (self::SUCCESS_CODE !== $result['code']) { + if ($result['code'] !== self::SUCCESS_CODE) { throw new GatewayErrorException($result['message'], $result['code'], $result); } diff --git a/src/Gateways/Gateway.php b/src/Gateways/Gateway.php index 3c7ae90..7870d5e 100644 --- a/src/Gateways/Gateway.php +++ b/src/Gateways/Gateway.php @@ -57,8 +57,7 @@ public function getTimeout() /** * Set timeout. * - * @param int $timeout - * + * @param int $timeout * @return $this */ public function setTimeout($timeout) diff --git a/src/Gateways/HuaweiGateway.php b/src/Gateways/HuaweiGateway.php index 8132065..3d9b504 100644 --- a/src/Gateways/HuaweiGateway.php +++ b/src/Gateways/HuaweiGateway.php @@ -81,7 +81,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->unwrapResponse($e->getResponse()); } - if (self::SUCCESS_CODE != $result['code']) { + if ($result['code'] != self::SUCCESS_CODE) { throw new GatewayErrorException($result['description'], ltrim($result['code'], 'E'), $result); } @@ -103,9 +103,8 @@ protected function getEndpoint(Config $config) /** * 获取请求 Headers 参数. * - * @param string $appKey - * @param string $appSecret - * + * @param string $appKey + * @param string $appSecret * @return array */ protected function getHeaders($appKey, $appSecret) @@ -120,9 +119,8 @@ protected function getHeaders($appKey, $appSecret) /** * 构造X-WSSE参数值 * - * @param string $appKey - * @param string $appSecret - * + * @param string $appKey + * @param string $appSecret * @return string */ protected function buildWsseHeader($appKey, $appSecret) diff --git a/src/Gateways/HuaxinGateway.php b/src/Gateways/HuaxinGateway.php index 7e1ade1..a6f819c 100644 --- a/src/Gateways/HuaxinGateway.php +++ b/src/Gateways/HuaxinGateway.php @@ -48,7 +48,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'extno' => $config->get('ext_no'), ]); - if ('Success' !== $result['returnstatus']) { + if ($result['returnstatus'] !== 'Success') { throw new GatewayErrorException($result['message'], 400, $result); } @@ -58,8 +58,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Build endpoint url. * - * @param string $ip - * + * @param string $ip * @return string */ protected function buildEndpoint($ip) diff --git a/src/Gateways/HuyiGateway.php b/src/Gateways/HuyiGateway.php index f48e210..96b4708 100644 --- a/src/Gateways/HuyiGateway.php +++ b/src/Gateways/HuyiGateway.php @@ -52,7 +52,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->post(self::ENDPOINT_URL, $params); - if (self::SUCCESS_CODE != $result['code']) { + if ($result['code'] != self::SUCCESS_CODE) { throw new GatewayErrorException($result['msg'], $result['code'], $result); } @@ -62,8 +62,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Generate Sign. * - * @param array $params - * + * @param array $params * @return string */ protected function generateSign($params) diff --git a/src/Gateways/KingttoGateway.php b/src/Gateways/KingttoGateway.php index e0fa429..425db10 100644 --- a/src/Gateways/KingttoGateway.php +++ b/src/Gateways/KingttoGateway.php @@ -48,7 +48,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->post(self::ENDPOINT_URL, $params); - if ('Success' != $result['returnstatus']) { + if ($result['returnstatus'] != 'Success') { throw new GatewayErrorException($result['message'], $result['remainpoint'], $result); } diff --git a/src/Gateways/LuosimaoGateway.php b/src/Gateways/LuosimaoGateway.php index 9ce6693..f9bfdc6 100644 --- a/src/Gateways/LuosimaoGateway.php +++ b/src/Gateways/LuosimaoGateway.php @@ -58,9 +58,8 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Build endpoint url. * - * @param string $type - * @param string $function - * + * @param string $type + * @param string $function * @return string */ protected function buildEndpoint($type, $function) diff --git a/src/Gateways/MaapGateway.php b/src/Gateways/MaapGateway.php index a00a921..292baf6 100644 --- a/src/Gateways/MaapGateway.php +++ b/src/Gateways/MaapGateway.php @@ -48,7 +48,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->postJson(self::ENDPOINT_URL, $params); - if (0 != $result['resultcode']) { + if ($result['resultcode'] != 0) { throw new GatewayErrorException($result['resultmsg'], $result['resultcode'], $result); } @@ -58,9 +58,8 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Generate Sign. * - * @param array $params - * @param string $key 签名Key - * + * @param array $params + * @param string $key 签名Key * @return string */ protected function generateSign($params, $key) diff --git a/src/Gateways/ModuyunGateway.php b/src/Gateways/ModuyunGateway.php index 296fbf2..f96687e 100644 --- a/src/Gateways/ModuyunGateway.php +++ b/src/Gateways/ModuyunGateway.php @@ -57,7 +57,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->postJson($this->getEndpointUrl($urlParams), $params); $result = is_string($result) ? json_decode($result, true) : $result; - if (0 != $result['result']) { + if ($result['result'] != 0) { throw new GatewayErrorException($result['errmsg'], $result['result'], $result); } @@ -65,8 +65,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config } /** - * @param array $params - * + * @param array $params * @return string */ protected function getEndpointUrl($params) @@ -77,9 +76,8 @@ protected function getEndpointUrl($params) /** * Generate Sign. * - * @param array $params - * @param string $random - * + * @param array $params + * @param string $random * @return string */ protected function generateSign($params, $random) diff --git a/src/Gateways/NowcnGateway.php b/src/Gateways/NowcnGateway.php index 06041ba..208a127 100644 --- a/src/Gateways/NowcnGateway.php +++ b/src/Gateways/NowcnGateway.php @@ -18,7 +18,7 @@ class NowcnGateway extends Gateway public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { - if (!$config->get('key')) { + if (! $config->get('key')) { throw new GatewayErrorException('key not found', -2, []); } $params = [ @@ -30,7 +30,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config ]; $result = $this->get(self::ENDPOINT_URL, $params); $result = is_string($result) ? json_decode($result, true) : $result; - if (self::SUCCESS_CODE != $result['code']) { + if ($result['code'] != self::SUCCESS_CODE) { throw new GatewayErrorException($result['msg'], $result['code'], $result); } diff --git a/src/Gateways/QcloudGateway.php b/src/Gateways/QcloudGateway.php index 3af2686..530059f 100644 --- a/src/Gateways/QcloudGateway.php +++ b/src/Gateways/QcloudGateway.php @@ -48,11 +48,11 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config { $data = $message->getData($this); - $signName = !empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name', ''); + $signName = ! empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name', ''); unset($data['sign_name']); - $phone = !\is_null($to->getIDDCode()) ? strval($to->getUniversalNumber()) : $to->getNumber(); + $phone = ! \is_null($to->getIDDCode()) ? strval($to->getUniversalNumber()) : $to->getNumber(); $params = [ 'PhoneNumberSet' => [ $phone, @@ -80,13 +80,13 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'json' => $params, ]); - if (!empty($result['Response']['Error']['Code'])) { + if (! empty($result['Response']['Error']['Code'])) { throw new GatewayErrorException($result['Response']['Error']['Message'], 400, $result); } - if (!empty($result['Response']['SendStatusSet'])) { + if (! empty($result['Response']['SendStatusSet'])) { foreach ($result['Response']['SendStatusSet'] as $group) { - if ('Ok' != $group['Code']) { + if ($group['Code'] != 'Ok') { throw new GatewayErrorException($group['Message'], 400, $result); } } @@ -98,8 +98,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Generate Sign. * - * @param array $params - * + * @param array $params * @return string */ protected function generateSign($params, $timestamp) diff --git a/src/Gateways/QiniuGateway.php b/src/Gateways/QiniuGateway.php index a59ac7a..6eb8e9f 100644 --- a/src/Gateways/QiniuGateway.php +++ b/src/Gateways/QiniuGateway.php @@ -46,7 +46,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'mobile' => $to->getNumber(), ]; - if (!empty($data)) { + if (! empty($data)) { $params['parameters'] = $data; } @@ -68,9 +68,8 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Build endpoint url. * - * @param string $type - * @param string $function - * + * @param string $type + * @param string $function * @return string */ protected function buildEndpoint($type, $function) @@ -81,11 +80,10 @@ protected function buildEndpoint($type, $function) /** * Build endpoint url. * - * @param string $url - * @param string $method - * @param string $body - * @param string $contentType - * + * @param string $url + * @param string $method + * @param string $body + * @param string $contentType * @return string */ protected function generateSign($url, $method, $body, $contentType, Config $config) @@ -105,21 +103,21 @@ protected function generateSign($url, $method, $body, $contentType, Config $conf } // write request uri $toSignStr = $method.' '.$path; - if (!empty($query)) { + if (! empty($query)) { $toSignStr .= '?'.$query; } // write host and port $toSignStr .= "\nHost: ".$host; - if (!empty($port)) { + if (! empty($port)) { $toSignStr .= ':'.$port; } // write content type - if (!empty($contentType)) { + if (! empty($contentType)) { $toSignStr .= "\nContent-Type: ".$contentType; } $toSignStr .= "\n\n"; // write body - if (!empty($body)) { + if (! empty($body)) { $toSignStr .= $body; } @@ -129,8 +127,7 @@ protected function generateSign($url, $method, $body, $contentType, Config $conf } /** - * @param string $data - * + * @param string $data * @return string */ protected function base64UrlSafeEncode($data) diff --git a/src/Gateways/RongcloudGateway.php b/src/Gateways/RongcloudGateway.php index f0c2648..2eda670 100644 --- a/src/Gateways/RongcloudGateway.php +++ b/src/Gateways/RongcloudGateway.php @@ -67,8 +67,8 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config break; case 'verifyCode': - if (!array_key_exists('code', $data) - or !array_key_exists('sessionId', $data)) { + if (! array_key_exists('code', $data) + or ! array_key_exists('sessionId', $data)) { throw new GatewayErrorException('"code" or "sessionId" is not set', 0); } $params = [ @@ -93,7 +93,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config try { $result = $this->post($endpoint, $params, $headers); - if (self::SUCCESS_CODE !== $result['code']) { + if ($result['code'] !== self::SUCCESS_CODE) { throw new GatewayErrorException($result['errorMessage'], $result['code'], $result); } } catch (ClientException $e) { @@ -106,8 +106,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Generate Sign. * - * @param array $params - * + * @param array $params * @return string */ protected function generateSign($params, Config $config) @@ -118,8 +117,7 @@ protected function generateSign($params, Config $config) /** * Build endpoint url. * - * @param string $action - * + * @param string $action * @return string */ protected function buildEndpoint($action) diff --git a/src/Gateways/RongheyunGateway.php b/src/Gateways/RongheyunGateway.php index c8a22f4..635b9f9 100644 --- a/src/Gateways/RongheyunGateway.php +++ b/src/Gateways/RongheyunGateway.php @@ -56,7 +56,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $params, ['Content-Type' => 'application/json; charset="UTF-8"'] ); - if (200 != $result['code']) { + if ($result['code'] != 200) { throw new GatewayErrorException($result['msg'], $result['code'], $result); } diff --git a/src/Gateways/SendcloudGateway.php b/src/Gateways/SendcloudGateway.php index bce0e4c..d2c398b 100644 --- a/src/Gateways/SendcloudGateway.php +++ b/src/Gateways/SendcloudGateway.php @@ -53,7 +53,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->post(sprintf(self::ENDPOINT_TEMPLATE, 'send'), $params); - if (!$result['result']) { + if (! $result['result']) { throw new GatewayErrorException($result['message'], $result['statusCode'], $result); } @@ -75,9 +75,8 @@ protected function formatTemplateVars(array $vars) } /** - * @param array $params - * @param string $key - * + * @param array $params + * @param string $key * @return string */ protected function sign($params, $key) diff --git a/src/Gateways/SmsbaoGateway.php b/src/Gateways/SmsbaoGateway.php index ec22241..2684ba2 100644 --- a/src/Gateways/SmsbaoGateway.php +++ b/src/Gateways/SmsbaoGateway.php @@ -48,7 +48,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config { $data = $message->getContent($this); - if (is_null($to->getIDDCode()) || '86' == $to->getIDDCode()) { + if (is_null($to->getIDDCode()) || $to->getIDDCode() == '86') { $number = $to->getNumber(); $action = 'sms'; } else { @@ -65,7 +65,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->get($this->buildEndpoint($action), $params); - if (self::SUCCESS_CODE !== $result) { + if ($result !== self::SUCCESS_CODE) { throw new GatewayErrorException($this->errorStatuses[$result], $result); } diff --git a/src/Gateways/SubmailGateway.php b/src/Gateways/SubmailGateway.php index 94ca757..e36e5a7 100644 --- a/src/Gateways/SubmailGateway.php +++ b/src/Gateways/SubmailGateway.php @@ -53,7 +53,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $params = [ 'appid' => $config->get('app_id'), 'signature' => $config->get('app_key'), - 'project' => !empty($template_code) ? $template_code : (!empty($data['project']) ? $data['project'] : $config->get('project')), + 'project' => ! empty($template_code) ? $template_code : (! empty($data['project']) ? $data['project'] : $config->get('project')), 'to' => $to->getUniversalNumber(), 'vars' => json_encode($data, JSON_FORCE_OBJECT), ]; @@ -61,7 +61,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->post($endpoint, $params); - if ('success' != $result['status']) { + if ($result['status'] != 'success') { throw new GatewayErrorException($result['msg'], $result['code'], $result); } @@ -71,8 +71,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Build endpoint url. * - * @param string $function - * + * @param string $function * @return string */ protected function buildEndpoint($function) @@ -83,14 +82,13 @@ protected function buildEndpoint($function) /** * Check if the phone number belongs to chinese mainland. * - * @param PhoneNumberInterface $to - * + * @param PhoneNumberInterface $to * @return bool */ protected function inChineseMainland($to) { $code = $to->getIDDCode(); - return empty($code) || 86 === $code; + return empty($code) || $code === 86; } } diff --git a/src/Gateways/TianyiwuxianGateway.php b/src/Gateways/TianyiwuxianGateway.php index 201d797..510e48d 100644 --- a/src/Gateways/TianyiwuxianGateway.php +++ b/src/Gateways/TianyiwuxianGateway.php @@ -61,7 +61,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = json_decode($result, true); - if (self::SUCCESS_STATUS !== $result['returnstatus'] || self::SUCCESS_CODE !== $result['code']) { + if ($result['returnstatus'] !== self::SUCCESS_STATUS || $result['code'] !== self::SUCCESS_CODE) { throw new GatewayErrorException($result['remark'], $result['code']); } diff --git a/src/Gateways/TiniyoGateway.php b/src/Gateways/TiniyoGateway.php index 64c5476..224d1da 100644 --- a/src/Gateways/TiniyoGateway.php +++ b/src/Gateways/TiniyoGateway.php @@ -60,7 +60,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config ], ]); - if (self::SUCCESS_CODE != $result['statusCode']) { + if ($result['statusCode'] != self::SUCCESS_CODE) { throw new GatewayErrorException($result['statusCode'], $result['statusCode'], $result); } @@ -70,8 +70,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * build endpoint url. * - * @param string $accountSid - * + * @param string $accountSid * @return string */ protected function buildEndPoint($accountSid) diff --git a/src/Gateways/TinreeGateway.php b/src/Gateways/TinreeGateway.php index e42643a..e5fb011 100644 --- a/src/Gateways/TinreeGateway.php +++ b/src/Gateways/TinreeGateway.php @@ -46,7 +46,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->post(self::ENDPOINT_URL, $params); - if (0 != $result['code']) { + if ($result['code'] != 0) { throw new GatewayErrorException($result['msg'], $result['code'], $result); } diff --git a/src/Gateways/TwilioGateway.php b/src/Gateways/TwilioGateway.php index 226dca8..c65d5d4 100644 --- a/src/Gateways/TwilioGateway.php +++ b/src/Gateways/TwilioGateway.php @@ -63,7 +63,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config ], 'form_params' => $params, ]); - if (in_array($result['status'], $this->errorStatuses) || !is_null($result['error_code'])) { + if (in_array($result['status'], $this->errorStatuses) || ! is_null($result['error_code'])) { throw new GatewayErrorException($result['message'], $result['error_code'], $result); } } catch (ClientException $e) { @@ -76,8 +76,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * build endpoint url. * - * @param string $accountSid - * + * @param string $accountSid * @return string */ protected function buildEndPoint($accountSid) diff --git a/src/Gateways/UcloudGateway.php b/src/Gateways/UcloudGateway.php index d48a3cf..71a5eb7 100644 --- a/src/Gateways/UcloudGateway.php +++ b/src/Gateways/UcloudGateway.php @@ -43,7 +43,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->get(self::ENDPOINT_URL, $params); - if (self::SUCCESS_CODE != $result['RetCode']) { + if ($result['RetCode'] != self::SUCCESS_CODE) { throw new GatewayErrorException($result['Message'], $result['RetCode'], $result); } @@ -60,23 +60,23 @@ protected function buildParams(PhoneNumberInterface $to, MessageInterface $messa $data = $message->getData($this); $params = [ 'Action' => self::ENDPOINT_Action, - 'SigContent' => !empty($data['sig_content']) ? $data['sig_content'] : $config->get('sig_content', ''), + 'SigContent' => ! empty($data['sig_content']) ? $data['sig_content'] : $config->get('sig_content', ''), 'TemplateId' => $message->getTemplate($this), 'PublicKey' => $config->get('public_key'), ]; $code = isset($data['code']) ? $data['code'] : ''; - if (is_array($code) && !empty($code)) { + if (is_array($code) && ! empty($code)) { foreach ($code as $key => $value) { $params['TemplateParams.'.$key] = $value; } } else { - if (!empty($code) || !is_null($code)) { + if (! empty($code) || ! is_null($code)) { $params['TemplateParams.0'] = $code; } } $mobiles = isset($data['mobiles']) ? $data['mobiles'] : ''; - if (!empty($mobiles) && !is_null($mobiles)) { + if (! empty($mobiles) && ! is_null($mobiles)) { if (is_array($mobiles)) { foreach ($mobiles as $key => $value) { $params['PhoneNumbers.'.$key] = $value; @@ -88,7 +88,7 @@ protected function buildParams(PhoneNumberInterface $to, MessageInterface $messa $params['PhoneNumbers.0'] = $to->getNumber(); } - if (!is_null($config->get('project_id')) && !empty($config->get('project_id'))) { + if (! is_null($config->get('project_id')) && ! empty($config->get('project_id'))) { $params['ProjectId'] = $config->get('project_id'); } @@ -101,9 +101,8 @@ protected function buildParams(PhoneNumberInterface $to, MessageInterface $messa /** * Generate Sign. * - * @param array $params - * @param string $privateKey - * + * @param array $params + * @param string $privateKey * @return string */ protected function getSignature($params, $privateKey) diff --git a/src/Gateways/Ue35Gateway.php b/src/Gateways/Ue35Gateway.php index ff4b569..6c83779 100644 --- a/src/Gateways/Ue35Gateway.php +++ b/src/Gateways/Ue35Gateway.php @@ -59,7 +59,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = json_decode(json_encode(simplexml_load_string($result)), true); } - if (self::SUCCESS_CODE != $result['errorcode']) { + if ($result['errorcode'] != self::SUCCESS_CODE) { throw new GatewayErrorException($result['message'], $result['errorcode'], $result); } diff --git a/src/Gateways/VolcengineGateway.php b/src/Gateways/VolcengineGateway.php index eb01439..b817d5a 100644 --- a/src/Gateways/VolcengineGateway.php +++ b/src/Gateways/VolcengineGateway.php @@ -33,10 +33,15 @@ class VolcengineGateway extends Gateway use HasHttpRequest; public const ENDPOINT_ACTION = 'SendSms'; + public const ENDPOINT_VERSION = '2020-01-01'; + public const ENDPOINT_CONTENT_TYPE = 'application/json; charset=utf-8'; + public const ENDPOINT_ACCEPT = 'application/json'; + public const ENDPOINT_USER_AGENT = 'overtrue/easy-sms'; + public const ENDPOINT_SERVICE = 'volcSMS'; public const Algorithm = 'HMAC-SHA256'; @@ -49,18 +54,19 @@ class VolcengineGateway extends Gateway ]; private $regionId = self::ENDPOINT_DEFAULT_REGION_ID; + protected $requestDate; public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { $data = $message->getData($this); - $signName = !empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name'); - $smsAccount = !empty($data['sms_account']) ? $data['sms_account'] : $config->get('sms_account'); + $signName = ! empty($data['sign_name']) ? $data['sign_name'] : $config->get('sign_name'); + $smsAccount = ! empty($data['sms_account']) ? $data['sms_account'] : $config->get('sms_account'); $templateId = $message->getTemplate($this); - $phoneNumbers = !empty($data['phone_numbers']) ? $data['phone_numbers'] : $to->getNumber(); - $templateParam = !empty($data['template_param']) ? $data['template_param'] : $message->getData($this); + $phoneNumbers = ! empty($data['phone_numbers']) ? $data['phone_numbers'] : $to->getNumber(); + $templateParam = ! empty($data['template_param']) ? $data['template_param'] : $message->getData($this); - $tag = !empty($data['tag']) ? $data['tag'] : ''; + $tag = ! empty($data['tag']) ? $data['tag'] : ''; $payload = [ 'SmsAccount' => $smsAccount, // 消息组帐号,火山短信页面右上角,短信应用括号中的字符串 @@ -122,7 +128,7 @@ protected function signHandle() return function (callable $handler) { return function (RequestInterface $request, array $options) use ($handler) { $request = $request->withHeader('X-Date', $this->getRequestDate()); - list($canonicalHeaders, $signedHeaders) = $this->getCanonicalHeaders($request); + [$canonicalHeaders, $signedHeaders] = $this->getCanonicalHeaders($request); $queries = Query::parse($request->getUri()->getQuery()); $canonicalRequest = $request->getMethod()."\n" @@ -193,7 +199,7 @@ public function getRegionId() public function getEndpoint() { $regionId = $this->getRegionId(); - if (!in_array($regionId, array_keys(self::$endpoints))) { + if (! in_array($regionId, array_keys(self::$endpoints))) { $regionId = self::ENDPOINT_DEFAULT_REGION_ID; } diff --git a/src/Gateways/WeiqucloudGateway.php b/src/Gateways/WeiqucloudGateway.php index 93a4f10..05b7494 100644 --- a/src/Gateways/WeiqucloudGateway.php +++ b/src/Gateways/WeiqucloudGateway.php @@ -2,14 +2,14 @@ namespace Overtrue\EasySms\Gateways; -use Overtrue\EasySms\Exceptions\GatewayErrorException; use Overtrue\EasySms\Contracts\MessageInterface; use Overtrue\EasySms\Contracts\PhoneNumberInterface; +use Overtrue\EasySms\Exceptions\GatewayErrorException; use Overtrue\EasySms\Support\Config; use Overtrue\EasySms\Traits\HasHttpRequest; /** - * 微趣云短信网关 + * 微趣云短信网关. */ class WeiqucloudGateway extends Gateway { @@ -20,13 +20,13 @@ class WeiqucloudGateway extends Gateway public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { $data = [ - "userId" => $config->get('userId'), - "account" => $config->get('account'), - "password" => $config->get('password'), - "mobile" => $to->getNumber(), - "content" => $message->getContent($this), - "sendTime" => "", - "action" => "sendhy", + 'userId' => $config->get('userId'), + 'account' => $config->get('account'), + 'password' => $config->get('password'), + 'mobile' => $to->getNumber(), + 'content' => $message->getContent($this), + 'sendTime' => '', + 'action' => 'sendhy', ]; $result = $this->postJson(self::ENDPOINT_URL, $data); diff --git a/src/Gateways/YidongmasblackGateway.php b/src/Gateways/YidongmasblackGateway.php index c76f416..8d520d7 100644 --- a/src/Gateways/YidongmasblackGateway.php +++ b/src/Gateways/YidongmasblackGateway.php @@ -48,7 +48,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $params['content'] = $message->getContent(); $result = $this->postJson(self::ENDPOINT_URL, $this->generateContent($params)); - if ('true' != $result['success']) { + if ($result['success'] != 'true') { throw new GatewayErrorException($result['success'], $result['rspcod'], $result); } @@ -58,8 +58,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Generate Content. * - * @param array $params - * + * @param array $params * @return string */ protected function generateContent($params) diff --git a/src/Gateways/YunpianGateway.php b/src/Gateways/YunpianGateway.php index dc93b59..33e3c08 100644 --- a/src/Gateways/YunpianGateway.php +++ b/src/Gateways/YunpianGateway.php @@ -49,7 +49,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'exceptions' => false, ]; - if (!is_null($template)) { + if (! is_null($template)) { $function = 'tpl_single_send'; $data = []; @@ -67,7 +67,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $content = $message->getContent($this); $signature = $config->get('signature', ''); $option['form_params'] = array_merge($option['form_params'], [ - 'text' => 0 === \stripos($content, '【') ? $content : $signature.$content, + 'text' => \stripos($content, '【') === 0 ? $content : $signature.$content, ]); } @@ -84,10 +84,9 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Build endpoint url. * - * @param string $type - * @param string $resource - * @param string $function - * + * @param string $type + * @param string $resource + * @param string $function * @return string */ protected function buildEndpoint($type, $resource, $function) diff --git a/src/Gateways/YuntongxunGateway.php b/src/Gateways/YuntongxunGateway.php index 49511de..9979249 100644 --- a/src/Gateways/YuntongxunGateway.php +++ b/src/Gateways/YuntongxunGateway.php @@ -83,7 +83,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config ], ]); - if (self::SUCCESS_CODE != $result['statusCode']) { + if ($result['statusCode'] != self::SUCCESS_CODE) { throw new GatewayErrorException($result['statusCode'], $result['statusCode'], $result); } @@ -93,10 +93,9 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Build endpoint url. * - * @param string $type - * @param string $resource - * @param string $datetime - * + * @param string $type + * @param string $resource + * @param string $datetime * @return string */ protected function buildEndpoint($type, $resource, $datetime, Config $config) diff --git a/src/Gateways/YunxinGateway.php b/src/Gateways/YunxinGateway.php index 7da6001..9986a23 100755 --- a/src/Gateways/YunxinGateway.php +++ b/src/Gateways/YunxinGateway.php @@ -71,7 +71,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config try { $result = $this->post($endpoint, $params, $headers); - if (!isset($result['code']) || self::SUCCESS_CODE !== $result['code']) { + if (! isset($result['code']) || $result['code'] !== self::SUCCESS_CODE) { $code = isset($result['code']) ? $result['code'] : 0; $error = isset($result['msg']) ? $result['msg'] : json_encode($result, JSON_UNESCAPED_UNICODE); @@ -138,7 +138,7 @@ public function buildVerifyCodeParams(PhoneNumberInterface $to, MessageInterface { $data = $message->getData($this); - if (!array_key_exists('code', $data)) { + if (! array_key_exists('code', $data)) { throw new GatewayErrorException('"code" cannot be empty', 0); } diff --git a/src/Gateways/YunzhixunGateway.php b/src/Gateways/YunzhixunGateway.php index 1ae6774..c3902a6 100755 --- a/src/Gateways/YunzhixunGateway.php +++ b/src/Gateways/YunzhixunGateway.php @@ -92,7 +92,7 @@ protected function execute($endpoint, $params) try { $result = $this->postJson($endpoint, $params); - if (!isset($result['code']) || self::SUCCESS_CODE !== $result['code']) { + if (! isset($result['code']) || $result['code'] !== self::SUCCESS_CODE) { $code = isset($result['code']) ? $result['code'] : 0; $error = isset($result['msg']) ? $result['msg'] : json_encode($result, JSON_UNESCAPED_UNICODE); diff --git a/src/Gateways/ZzyunGateway.php b/src/Gateways/ZzyunGateway.php index 429daf5..2244def 100644 --- a/src/Gateways/ZzyunGateway.php +++ b/src/Gateways/ZzyunGateway.php @@ -50,7 +50,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->post(self::ENDPOINT_URL, $params); - if ('Success' != $result['Code']) { + if ($result['Code'] != 'Success') { throw new GatewayErrorException($result['Message'], $result['Code'], $result); } diff --git a/src/Messenger.php b/src/Messenger.php index 9c19b61..0634771 100644 --- a/src/Messenger.php +++ b/src/Messenger.php @@ -67,7 +67,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, array } } - if (!$isSuccessful) { + if (! $isSuccessful) { throw new NoGatewayAvailableException($results); } diff --git a/src/PhoneNumber.php b/src/PhoneNumber.php index 758ccdc..cb1d233 100644 --- a/src/PhoneNumber.php +++ b/src/PhoneNumber.php @@ -41,9 +41,9 @@ public function __construct(int|string $numberWithoutIDDCode, ?string $IDDCode = // Try to parse using libphonenumber try { - if (null !== $parsedIDDCode) { + if ($parsedIDDCode !== null) { // If IDD code is provided, construct the phone number directly - $this->phoneNumberObject = new \libphonenumber\PhoneNumber(); + $this->phoneNumberObject = new \libphonenumber\PhoneNumber; $this->phoneNumberObject->setCountryCode($parsedIDDCode); $this->phoneNumberObject->setNationalNumber($numberStr); @@ -101,7 +101,7 @@ public function getNumber(): int|string */ public function getUniversalNumber(): string { - if (null !== $this->phoneNumberObject && null !== $this->IDDCode && $this->phoneUtil->isValidNumber($this->phoneNumberObject)) { + if ($this->phoneNumberObject !== null && $this->IDDCode !== null && $this->phoneUtil->isValidNumber($this->phoneNumberObject)) { return $this->phoneUtil->format($this->phoneNumberObject, PhoneNumberFormat::E164); } @@ -113,7 +113,7 @@ public function getUniversalNumber(): string */ public function getZeroPrefixedNumber(): string { - if (null !== $this->phoneNumberObject && null !== $this->IDDCode) { + if ($this->phoneNumberObject !== null && $this->IDDCode !== null) { $e164 = $this->phoneUtil->format($this->phoneNumberObject, PhoneNumberFormat::E164); // Convert +XX to 00XX @@ -157,6 +157,6 @@ public function jsonSerialize() */ public function inChineseMainland(): bool { - return empty($this->IDDCode) || 86 === $this->IDDCode; + return empty($this->IDDCode) || $this->IDDCode === 86; } } diff --git a/src/Strategies/RandomStrategy.php b/src/Strategies/RandomStrategy.php index 6c7c2e6..431fa27 100644 --- a/src/Strategies/RandomStrategy.php +++ b/src/Strategies/RandomStrategy.php @@ -24,7 +24,7 @@ public function apply(array $gateways): array $keys = \array_keys($gateways); $n = \count($keys); - for ($i = $n - 1; $i > 0; --$i) { + for ($i = $n - 1; $i > 0; $i--) { $j = \random_int(0, $i); [$keys[$i], $keys[$j]] = [$keys[$j], $keys[$i]]; } diff --git a/src/Support/Config.php b/src/Support/Config.php index 54d0c84..a7b2bc1 100644 --- a/src/Support/Config.php +++ b/src/Support/Config.php @@ -41,12 +41,12 @@ public function get(string $key, mixed $default = null): mixed return $config[$key]; } - if (!str_contains($key, '.')) { + if (! str_contains($key, '.')) { return $default; } foreach (explode('.', $key) as $segment) { - if (!is_array($config) || !array_key_exists($segment, $config)) { + if (! is_array($config) || ! array_key_exists($segment, $config)) { return $default; } $config = $config[$segment]; @@ -60,10 +60,9 @@ public function get(string $key, mixed $default = null): mixed * * @see http://php.net/manual/en/arrayaccess.offsetexists.php * - * @param mixed $offset
- * An offset to check for. - *
- * + * @param mixed $offset+ * An offset to check for. + *
* @return bool true on success or false on failure. * *@@ -82,10 +81,9 @@ public function offsetExists(mixed $offset): bool * * @see http://php.net/manual/en/arrayaccess.offsetget.php * - * @param mixed $offset
- * The offset to retrieve. - *
- * + * @param mixed $offset+ * The offset to retrieve. + *
* @return mixed Can return all value types * * @since 5.0.0 @@ -101,12 +99,12 @@ public function offsetGet(mixed $offset): mixed * * @see http://php.net/manual/en/arrayaccess.offsetset.php * - * @param mixed $offset- * The offset to assign the value to. - *
- * @param mixed $value- * The value to set. - *
+ * @param mixed $offset+ * The offset to assign the value to. + *
+ * @param mixed $value+ * The value to set. + *
* * @since 5.0.0 */ @@ -123,9 +121,9 @@ public function offsetSet(mixed $offset, mixed $value): void * * @see http://php.net/manual/en/arrayaccess.offsetunset.php * - * @param mixed $offset- * The offset to unset. - *
+ * @param mixed $offset+ * The offset to unset. + *
* * @since 5.0.0 */ diff --git a/src/Traits/HasHttpRequest.php b/src/Traits/HasHttpRequest.php index aaeef0d..29f82e1 100644 --- a/src/Traits/HasHttpRequest.php +++ b/src/Traits/HasHttpRequest.php @@ -22,10 +22,9 @@ trait HasHttpRequest /** * Make a get request. * - * @param string $endpoint - * @param array $query - * @param array $headers - * + * @param string $endpoint + * @param array $query + * @param array $headers * @return ResponseInterface|array|string */ protected function get($endpoint, $query = [], $headers = []) @@ -39,10 +38,9 @@ protected function get($endpoint, $query = [], $headers = []) /** * Make a post request. * - * @param string $endpoint - * @param array $params - * @param array $headers - * + * @param string $endpoint + * @param array $params + * @param array $headers * @return ResponseInterface|array|string */ protected function post($endpoint, $params = [], $headers = []) @@ -56,9 +54,8 @@ protected function post($endpoint, $params = [], $headers = []) /** * Make a post request with json params. * - * @param array $params - * @param array $headers - * + * @param array $params + * @param array $headers * @return ResponseInterface|array|string */ protected function postJson($endpoint, $params = [], $headers = []) @@ -72,10 +69,9 @@ protected function postJson($endpoint, $params = [], $headers = []) /** * Make a http request. * - * @param string $method - * @param string $endpoint - * @param array $options http://docs.guzzlephp.org/en/latest/request-options.html - * + * @param string $method + * @param string $endpoint + * @param array $options http://docs.guzzlephp.org/en/latest/request-options.html * @return ResponseInterface|array|string */ protected function request($method, $endpoint, $options = []) @@ -120,9 +116,9 @@ protected function unwrapResponse(ResponseInterface $response) $contentType = $response->getHeaderLine('Content-Type'); $contents = $response->getBody()->getContents(); - if (false !== stripos($contentType, 'json') || stripos($contentType, 'javascript')) { + if (stripos($contentType, 'json') !== false || stripos($contentType, 'javascript')) { return json_decode($contents, true); - } elseif (false !== stripos($contentType, 'xml')) { + } elseif (stripos($contentType, 'xml') !== false) { return json_decode(json_encode(simplexml_load_string($contents)), true); } diff --git a/tests/EasySmsTest.php b/tests/EasySmsTest.php index e85ea9d..c9564b6 100644 --- a/tests/EasySmsTest.php +++ b/tests/EasySmsTest.php @@ -23,7 +23,7 @@ class EasySmsTest extends TestCase { - public function testGateway() + public function test_gateway() { $easySms = new EasySms([]); @@ -36,7 +36,7 @@ public function testGateway() $easySms->gateway('NotExistsGatewayName'); } - public function testGatewayNameConflicts() + public function test_gateway_name_conflicts() { $easySms = \Mockery::mock(EasySms::class.'[makeGateway]', [['default' => DummyGatewayForTest::class]]); @@ -44,23 +44,23 @@ public function testGatewayNameConflicts() $easySms->makeGateway(DummyGatewayNotImplementsGatewayInterface::class, []); } - public function testExtend() + public function test_extend() { $easySms = new EasySms([]); $easySms->extend('foo', function () { - return new DummyGatewayForTest(); + return new DummyGatewayForTest; }); $this->assertInstanceOf(DummyGatewayForTest::class, $easySms->gateway('foo')); } - public function testSend() + public function test_send() { $messenger = \Mockery::mock(Messenger::class); $messenger->allows()->send(\Mockery::on(function ($number) { - return $number instanceof PhoneNumber && !empty($number->getNumber()); + return $number instanceof PhoneNumber && ! empty($number->getNumber()); }), \Mockery::on(function ($message) { - return $message instanceof MessageInterface && !empty($message->getContent()); + return $message instanceof MessageInterface && ! empty($message->getContent()); }), [])->andReturn([]); $easySms = \Mockery::mock(EasySms::class.'[getMessenger]', [['default' => DummyGatewayForTest::class]]); @@ -87,7 +87,7 @@ public function testSend() $this->assertIsArray($easySms->send($number, $message)); } - public function testFormatMessage() + public function test_format_message() { $easySms = \Mockery::mock(EasySms::class.'[formatMessage]', [[]])->makePartial()->shouldAllowMockingProtectedMethods(); @@ -122,14 +122,14 @@ public function testFormatMessage() $this->assertSame(['c' => 'd'], $message->setData(['c' => 'd'])->getData()); } - public function testGetMessenger() + public function test_get_messenger() { $easySms = new EasySms([]); $this->assertInstanceOf(Messenger::class, $easySms->getMessenger()); } - public function testFormatGateways() + public function test_format_gateways() { $config = [ 'gateways' => [ @@ -173,7 +173,7 @@ public function testFormatGateways() $this->assertSame('e', $gateways['bar']->get('c')); } - public function testCreateGatewayWithDefaultTimeout() + public function test_create_gateway_with_default_timeout() { $easySms = new EasySms([ 'timeout' => 10.0, @@ -189,9 +189,7 @@ public function testCreateGatewayWithDefaultTimeout() } } -class DummyGatewayNotImplementsGatewayInterface -{ -} +class DummyGatewayNotImplementsGatewayInterface {} class DummyGatewayForTest implements GatewayInterface { diff --git a/tests/Gateways/AliyunGatewayTest.php b/tests/Gateways/AliyunGatewayTest.php index aad9980..4c4ef7a 100644 --- a/tests/Gateways/AliyunGatewayTest.php +++ b/tests/Gateways/AliyunGatewayTest.php @@ -20,7 +20,7 @@ class AliyunGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'access_key_id' => 'mock-api-key', diff --git a/tests/Gateways/AliyunIntlGatewayTest.php b/tests/Gateways/AliyunIntlGatewayTest.php index 8bb7859..3403419 100644 --- a/tests/Gateways/AliyunIntlGatewayTest.php +++ b/tests/Gateways/AliyunIntlGatewayTest.php @@ -15,7 +15,7 @@ class AliyunIntlGatewayTest extends TestCase { /** @test */ - public function itCanSenSmsByAliyunIntlGateway() + public function it_can_sen_sms_by_aliyun_intl_gateway() { $config = [ 'access_key_id' => 'mock-api-key', @@ -42,26 +42,26 @@ public function itCanSenSmsByAliyunIntlGateway() ]; $gateway->shouldReceive('get') - ->with(AliyunIntlGateway::ENDPOINT_URL, \Mockery::on(function ($params) use ($expected) { - if (empty($params['Signature'])) { - return false; - } + ->with(AliyunIntlGateway::ENDPOINT_URL, \Mockery::on(function ($params) use ($expected) { + if (empty($params['Signature'])) { + return false; + } - unset($params['SignatureNonce'], $params['Timestamp'], $params['Signature']); + unset($params['SignatureNonce'], $params['Timestamp'], $params['Signature']); - ksort($params); - ksort($expected); + ksort($params); + ksort($expected); - return $params == $expected; - })) - ->andReturn([ - 'ResponseCode' => 'OK', - 'ResponseDescription' => 'mock-result', - ], [ - 'ResponseCode' => 1234, - 'ResponseDescription' => 'mock-err-msg', - ]) - ->twice(); + return $params == $expected; + })) + ->andReturn([ + 'ResponseCode' => 'OK', + 'ResponseDescription' => 'mock-result', + ], [ + 'ResponseCode' => 1234, + 'ResponseDescription' => 'mock-err-msg', + ]) + ->twice(); $message = new Message([ 'template' => 'mock-template-code', diff --git a/tests/Gateways/AliyunrestGatewayTest.php b/tests/Gateways/AliyunrestGatewayTest.php index e27b38b..315d7b3 100644 --- a/tests/Gateways/AliyunrestGatewayTest.php +++ b/tests/Gateways/AliyunrestGatewayTest.php @@ -23,7 +23,7 @@ */ class AliyunrestGatewayTest extends TestCase { - public function testSend() + public function test_send() { $urlParams = [ 'app_key' => 'mock-app-key', @@ -51,7 +51,7 @@ public function testSend() $gateway = \Mockery::mock(AliyunrestGateway::class.'[post]', [$config])->shouldAllowMockingProtectedMethods(); $gateway->shouldReceive('post')->with(\Mockery::on(function ($url) use ($urlParams) { $url = implode('&', array_filter(explode('&', $url), function ($s) { - return 'sign=' != substr($s, 0, 5); + return substr($s, 0, 5) != 'sign='; })); return $url == 'http://gw.api.taobao.com/router/rest?'.http_build_query($urlParams); diff --git a/tests/Gateways/BaiduGatewayTest.php b/tests/Gateways/BaiduGatewayTest.php index 7f86f56..10b7c2f 100644 --- a/tests/Gateways/BaiduGatewayTest.php +++ b/tests/Gateways/BaiduGatewayTest.php @@ -20,7 +20,7 @@ class BaiduGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'ak' => 'mock-ak', @@ -37,7 +37,7 @@ public function testSend() $gateway->shouldReceive('request')->with( 'post', \Mockery::on(function ($api) { - return 0 == strpos($api, 'http://'.BaiduGateway::ENDPOINT_HOST.BaiduGateway::ENDPOINT_URI); + return strpos($api, 'http://'.BaiduGateway::ENDPOINT_HOST.BaiduGateway::ENDPOINT_URI) == 0; }), \Mockery::on(function ($params) use ($expected) { ksort($params['json']); diff --git a/tests/Gateways/ChuanglanGatewayTest.php b/tests/Gateways/ChuanglanGatewayTest.php index e0b136a..0aa87d0 100644 --- a/tests/Gateways/ChuanglanGatewayTest.php +++ b/tests/Gateways/ChuanglanGatewayTest.php @@ -27,7 +27,7 @@ class ChuanglanGatewayTest extends TestCase /** * 发送验证码通道短信. */ - public function testSendValidateCodeSMS() + public function test_send_validate_code_sms() { $config = [ 'account' => 'mock-account', @@ -79,7 +79,7 @@ public function testSendValidateCodeSMS() /** * 发送营销通道短信. */ - public function testSendPromotionSMS() + public function test_send_promotion_sms() { $config = [ 'account' => 'mock-account', @@ -135,7 +135,7 @@ public function testSendPromotionSMS() * * @throws \ReflectionException */ - public function testBuildEndpoint() + public function test_build_endpoint() { $method = new \ReflectionMethod(ChuanglanGateway::class, 'buildEndpoint'); $method->setAccessible(true); @@ -159,7 +159,7 @@ public function testBuildEndpoint() * * @throws \ReflectionException */ - public function testGetChannel() + public function test_get_channel() { $method = new \ReflectionMethod(ChuanglanGateway::class, 'getChannel'); $method->setAccessible(true); @@ -181,7 +181,7 @@ public function testGetChannel() * * @throws \ReflectionException */ - public function testGetChannelException() + public function test_get_channel_exception() { $method = new \ReflectionMethod(ChuanglanGateway::class, 'getChannel'); $method->setAccessible(true); @@ -200,7 +200,7 @@ public function testGetChannelException() * * @throws \ReflectionException */ - public function testValidateCodeChannelWrapChannelContent() + public function test_validate_code_channel_wrap_channel_content() { $method = new \ReflectionMethod(ChuanglanGateway::class, 'wrapChannelContent'); $method->setAccessible(true); @@ -219,7 +219,7 @@ public function testValidateCodeChannelWrapChannelContent() * * @throws \ReflectionException */ - public function testPromotionChannelWrapChannelContent() + public function test_promotion_channel_wrap_channel_content() { $method = new \ReflectionMethod(ChuanglanGateway::class, 'wrapChannelContent'); $method->setAccessible(true); @@ -242,7 +242,7 @@ public function testPromotionChannelWrapChannelContent() * * @throws \ReflectionException */ - public function testPromotionChannelWrapChannelContentWithoutSign() + public function test_promotion_channel_wrap_channel_content_without_sign() { $method = new \ReflectionMethod(ChuanglanGateway::class, 'wrapChannelContent'); $method->setAccessible(true); @@ -267,7 +267,7 @@ public function testPromotionChannelWrapChannelContentWithoutSign() * * @throws \ReflectionException */ - public function testPromotionChannelWrapChannelContentWithoutUnsubscribe() + public function test_promotion_channel_wrap_channel_content_without_unsubscribe() { $method = new \ReflectionMethod(ChuanglanGateway::class, 'wrapChannelContent'); $method->setAccessible(true); diff --git a/tests/Gateways/CtyunGatewayTest.php b/tests/Gateways/CtyunGatewayTest.php index 44803e2..b96bf51 100644 --- a/tests/Gateways/CtyunGatewayTest.php +++ b/tests/Gateways/CtyunGatewayTest.php @@ -11,7 +11,7 @@ class CtyunGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'secret_key' => 'mock-secrey-key', diff --git a/tests/Gateways/ErrorlogGatewayTest.php b/tests/Gateways/ErrorlogGatewayTest.php index 52a9fd5..09f2226 100644 --- a/tests/Gateways/ErrorlogGatewayTest.php +++ b/tests/Gateways/ErrorlogGatewayTest.php @@ -29,7 +29,7 @@ public function removeLogFile() unlink($this->logFile); } - public function testSend() + public function test_send() { $gateway = new ErrorlogGateway([ 'file' => $this->logFile, @@ -40,7 +40,7 @@ public function testSend() 'data' => ['foo' => 'bar'], ]); - $gateway->send(new PhoneNumber(18188888888), $message, new Config()); + $gateway->send(new PhoneNumber(18188888888), $message, new Config); $this->assertTrue(file_exists($this->logFile)); $this->assertNotFalse( diff --git a/tests/Gateways/GatewayTest.php b/tests/Gateways/GatewayTest.php index b0b4772..cbc77f4 100644 --- a/tests/Gateways/GatewayTest.php +++ b/tests/Gateways/GatewayTest.php @@ -19,7 +19,7 @@ class GatewayTest extends TestCase { - public function testTimeout() + public function test_timeout() { $gateway = new DummyGatewayForGatewayTest(['foo' => 'bar']); @@ -32,7 +32,7 @@ public function testTimeout() $this->assertSame(12.0, $gateway->getTimeout()); } - public function testConfigSetterAndGetter() + public function test_config_setter_and_getter() { $gateway = new DummyGatewayForGatewayTest(['foo' => 'bar']); diff --git a/tests/Gateways/HuaweiGatewayTest.php b/tests/Gateways/HuaweiGatewayTest.php index cade24d..e62a6f9 100644 --- a/tests/Gateways/HuaweiGatewayTest.php +++ b/tests/Gateways/HuaweiGatewayTest.php @@ -23,7 +23,7 @@ class HuaweiGatewayTest extends TestCase /** * 测试 发送华为短信 */ - public function testSend() + public function test_send() { $config = [ 'endpoint' => 'mock-endpoint', @@ -49,7 +49,7 @@ public function testSend() ->with( 'post', \Mockery::on(function ($endpoint) use ($config) { - return $config['endpoint'].'/sms/batchSendSms/v1' === $endpoint; + return $endpoint === $config['endpoint'].'/sms/batchSendSms/v1'; }), \Mockery::on(function ($params) use ($expectedParams) { ksort($params['form_params']); @@ -84,7 +84,7 @@ public function testSend() /** * 测试 自定义签名通道. */ - public function testMultiFrom() + public function test_multi_from() { $config = [ 'endpoint' => 'mock-endpoint', @@ -111,7 +111,7 @@ public function testMultiFrom() ->with( 'post', \Mockery::on(function ($endpoint) use ($config) { - return $config['endpoint'].'/sms/batchSendSms/v1' === $endpoint; + return $endpoint === $config['endpoint'].'/sms/batchSendSms/v1'; }), \Mockery::on(function ($params) use ($expectedParams) { ksort($params['form_params']); @@ -152,7 +152,7 @@ public function testMultiFrom() * * @throws \ReflectionException */ - public function testGetEndpoint() + public function test_get_endpoint() { $method = new \ReflectionMethod(HuaweiGateway::class, 'getEndpoint'); $method->setAccessible(true); @@ -160,7 +160,7 @@ public function testGetEndpoint() $gateway = \Mockery::mock(HuaweiGateway::class.'[request]', [[]])->shouldAllowMockingProtectedMethods(); $defaultEndpoint = 'https://api.rtc.huaweicloud.com:10443/sms/batchSendSms/v1'; - $this->assertSame($defaultEndpoint, $method->invoke($gateway, new Config())); + $this->assertSame($defaultEndpoint, $method->invoke($gateway, new Config)); $config = new Config([ 'endpoint' => 'mock-endpoint', diff --git a/tests/Gateways/HuaxinGatewayTest.php b/tests/Gateways/HuaxinGatewayTest.php index 7bcc811..13c2bf4 100644 --- a/tests/Gateways/HuaxinGatewayTest.php +++ b/tests/Gateways/HuaxinGatewayTest.php @@ -20,7 +20,7 @@ class HuaxinGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'user_id' => 'mock-user-id', diff --git a/tests/Gateways/HuyiGatewayTest.php b/tests/Gateways/HuyiGatewayTest.php index 881ec50..1cdc4a9 100644 --- a/tests/Gateways/HuyiGatewayTest.php +++ b/tests/Gateways/HuyiGatewayTest.php @@ -20,7 +20,7 @@ class HuyiGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'api_id' => 'mock-api-id', diff --git a/tests/Gateways/JuheGatewayTest.php b/tests/Gateways/JuheGatewayTest.php index bd41ac3..9a028a2 100644 --- a/tests/Gateways/JuheGatewayTest.php +++ b/tests/Gateways/JuheGatewayTest.php @@ -20,7 +20,7 @@ class JuheGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'app_key' => 'mock-key', diff --git a/tests/Gateways/KingttoGatewayTest.php b/tests/Gateways/KingttoGatewayTest.php index b06d9d4..977bdaa 100644 --- a/tests/Gateways/KingttoGatewayTest.php +++ b/tests/Gateways/KingttoGatewayTest.php @@ -20,7 +20,7 @@ class KingttoGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'userid' => 'mock-id', diff --git a/tests/Gateways/LuosimaoGatewayTest.php b/tests/Gateways/LuosimaoGatewayTest.php index be02b52..8e408a4 100644 --- a/tests/Gateways/LuosimaoGatewayTest.php +++ b/tests/Gateways/LuosimaoGatewayTest.php @@ -20,7 +20,7 @@ class LuosimaoGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'api_key' => 'mock-api-key', diff --git a/tests/Gateways/MaapGatewayTest.php b/tests/Gateways/MaapGatewayTest.php index c63f123..6e3a3de 100644 --- a/tests/Gateways/MaapGatewayTest.php +++ b/tests/Gateways/MaapGatewayTest.php @@ -20,7 +20,7 @@ class MaapGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'cpcode' => 'mock-cpcode', diff --git a/tests/Gateways/ModuyunGatewayTest.php b/tests/Gateways/ModuyunGatewayTest.php index d4d1748..4a972f5 100644 --- a/tests/Gateways/ModuyunGatewayTest.php +++ b/tests/Gateways/ModuyunGatewayTest.php @@ -20,7 +20,7 @@ class ModuyunGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'accesskey' => 'mock-accesskey', diff --git a/tests/Gateways/NowcnGatewaysTest.php b/tests/Gateways/NowcnGatewaysTest.php index 1fe2ce8..1d9e523 100644 --- a/tests/Gateways/NowcnGatewaysTest.php +++ b/tests/Gateways/NowcnGatewaysTest.php @@ -11,7 +11,7 @@ class NowcnGatewaysTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'key' => '1', @@ -23,7 +23,7 @@ public function testSend() $gateway->shouldReceive('request')->with( 'get', \Mockery::on(function ($api) { - return 0 === strpos($api, NowcnGateway::ENDPOINT_URL); + return strpos($api, NowcnGateway::ENDPOINT_URL) === 0; }), \Mockery::on(function ($params) { return true; diff --git a/tests/Gateways/QcloudGatewayTest.php b/tests/Gateways/QcloudGatewayTest.php index c3ebde8..4a301d9 100644 --- a/tests/Gateways/QcloudGatewayTest.php +++ b/tests/Gateways/QcloudGatewayTest.php @@ -20,7 +20,7 @@ class QcloudGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'sdk_app_id' => 'mock-sdk-app-id', @@ -90,7 +90,7 @@ public function testSend() $gateway->send(new PhoneNumber(18888888888), $message, $config); } - public function testSendWithPartialErrors() + public function test_send_with_partial_errors() { $config = [ 'sdk_app_id' => 'mock-sdk-app-id', @@ -102,22 +102,22 @@ public function testSendWithPartialErrors() $gateway = \Mockery::mock(QcloudGateway::class.'[request]', [$config])->shouldAllowMockingProtectedMethods(); $gateway->shouldReceive('request') - ->andReturn([ - 'Response' => [ - 'SendStatusSet' => [ - [ - 'SerialNo' => '2028:f825e6b16e23f73f4123', - 'PhoneNumber' => '8618888888888', - 'Fee' => 1, - 'SessionContext' => '', - 'Code' => 'InvalidParameterValue.TemplateParameterFormatError', - 'Message' => 'Verification code template parameter format error', - 'IsoCode' => 'CN', - ], + ->andReturn([ + 'Response' => [ + 'SendStatusSet' => [ + [ + 'SerialNo' => '2028:f825e6b16e23f73f4123', + 'PhoneNumber' => '8618888888888', + 'Fee' => 1, + 'SessionContext' => '', + 'Code' => 'InvalidParameterValue.TemplateParameterFormatError', + 'Message' => 'Verification code template parameter format error', + 'IsoCode' => 'CN', ], ], - 'RequestId' => '0dc99542-c61a-4a16-9545-ec8ec202c543', - ])->once(); + ], + 'RequestId' => '0dc99542-c61a-4a16-9545-ec8ec202c543', + ])->once(); $message = new Message([ 'template' => 'template-id', diff --git a/tests/Gateways/QiniuGatewayTest.php b/tests/Gateways/QiniuGatewayTest.php index 84a661a..260b764 100644 --- a/tests/Gateways/QiniuGatewayTest.php +++ b/tests/Gateways/QiniuGatewayTest.php @@ -20,7 +20,7 @@ class QiniuGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'secret_key' => 'mock-secrey-key', diff --git a/tests/Gateways/RongheyunGatewayTest.php b/tests/Gateways/RongheyunGatewayTest.php index 0a02764..54240e4 100644 --- a/tests/Gateways/RongheyunGatewayTest.php +++ b/tests/Gateways/RongheyunGatewayTest.php @@ -20,7 +20,7 @@ class RongheyunGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'username' => 'mock-username', diff --git a/tests/Gateways/SendcloudGatewayTest.php b/tests/Gateways/SendcloudGatewayTest.php index e2339c8..c83652a 100644 --- a/tests/Gateways/SendcloudGatewayTest.php +++ b/tests/Gateways/SendcloudGatewayTest.php @@ -20,7 +20,7 @@ class SendcloudGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'sms_user' => 'mock-user', @@ -51,8 +51,7 @@ public function testSend() && $params['phone'] == $expected['phone'] && $params['vars'] == $expected['vars'] && $params['signature'] == $expectedSignature - && !isset($params['timestamp']) - ; + && ! isset($params['timestamp']); })) ->andReturn([ 'message' => '操作成功', @@ -87,7 +86,7 @@ public function testSend() $gateway->send(new PhoneNumber(18188888888), $message, $config); } - public function testTimestampConfig() + public function test_timestamp_config() { $config = [ 'sms_user' => 'mock-user', @@ -98,7 +97,7 @@ public function testTimestampConfig() $gateway->shouldReceive('post') ->with(sprintf(SendcloudGateway::ENDPOINT_TEMPLATE, 'send'), \Mockery::on(function ($params) { - return isset($params['timestamp']) && 13 == strlen($params['timestamp']) && $params['timestamp'] <= time() * 1000; + return isset($params['timestamp']) && strlen($params['timestamp']) == 13 && $params['timestamp'] <= time() * 1000; }))->andReturn([ 'message' => '操作成功', 'result' => true, diff --git a/tests/Gateways/SmsbaoGatewayTest.php b/tests/Gateways/SmsbaoGatewayTest.php index 207556b..ce8b6d8 100644 --- a/tests/Gateways/SmsbaoGatewayTest.php +++ b/tests/Gateways/SmsbaoGatewayTest.php @@ -25,7 +25,7 @@ */ class SmsbaoGatewayTest extends TestCase { - public function testSendWithSMS() + public function test_send_with_sms() { $config = [ 'user' => 'mock-user', @@ -60,7 +60,7 @@ public function testSendWithSMS() $gateway->send(new PhoneNumber(18188888888), $message, $config); } - public function testSendWithWSMS() + public function test_send_with_wsms() { $config = [ 'user' => 'mock-user', diff --git a/tests/Gateways/SubmailGatewayTest.php b/tests/Gateways/SubmailGatewayTest.php index e07be6e..f03f1c9 100644 --- a/tests/Gateways/SubmailGatewayTest.php +++ b/tests/Gateways/SubmailGatewayTest.php @@ -20,7 +20,7 @@ class SubmailGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'app_id' => 'mock-app-id', @@ -63,7 +63,7 @@ public function testSend() $gateway->send(new PhoneNumber(18188888888), $message, $config); } - public function testContentSend() + public function test_content_send() { $config = [ 'app_id' => 'mock-app-id', @@ -104,7 +104,7 @@ public function testContentSend() $gateway->send(new PhoneNumber(18188888888), $message, $config); } - public function testProject() + public function test_project() { $config = [ 'app_id' => 'mock-app-id', @@ -137,7 +137,7 @@ public function testProject() ], $gateway->send(new PhoneNumber(18188888888), $message, $config)); } - public function testEndpointChina() + public function test_endpoint_china() { $config = [ 'app_id' => 'mock-app-id', @@ -170,7 +170,7 @@ public function testEndpointChina() ], $gateway->send(new PhoneNumber(18188888888, 86), $message, $config)); } - public function testEndpointInternational() + public function test_endpoint_international() { $config = [ 'app_id' => 'mock-app-id', diff --git a/tests/Gateways/TinreeGatewayTest.php b/tests/Gateways/TinreeGatewayTest.php index 73e70b2..ce628c4 100644 --- a/tests/Gateways/TinreeGatewayTest.php +++ b/tests/Gateways/TinreeGatewayTest.php @@ -20,7 +20,7 @@ class TinreeGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'accesskey' => 'mock-accesskey', diff --git a/tests/Gateways/TwilioGatewayTest.php b/tests/Gateways/TwilioGatewayTest.php index 860e7f8..7f13c2a 100644 --- a/tests/Gateways/TwilioGatewayTest.php +++ b/tests/Gateways/TwilioGatewayTest.php @@ -19,7 +19,7 @@ class TwilioGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'account_sid' => 'mock-api-account-sid', diff --git a/tests/Gateways/UcloudGatewayTest.php b/tests/Gateways/UcloudGatewayTest.php index 361c3e0..e086f18 100644 --- a/tests/Gateways/UcloudGatewayTest.php +++ b/tests/Gateways/UcloudGatewayTest.php @@ -23,7 +23,7 @@ */ class UcloudGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'private_key' => '', // 私钥 @@ -37,7 +37,7 @@ public function testSend() $gateway->shouldReceive('request')->with( 'get', \Mockery::on(function ($api) { - return 0 === strpos($api, UcloudGateway::ENDPOINT_URL); + return strpos($api, UcloudGateway::ENDPOINT_URL) === 0; }), \Mockery::on(function ($params) { return true; @@ -70,7 +70,7 @@ public function testSend() $gateway->send(new PhoneNumber(18888888888), $message, $config); } - public function testSignContent() + public function test_sign_content() { $defaultSigContent = 'default_sig_content'; @@ -88,7 +88,7 @@ public function testSignContent() $gateway->shouldReceive('request')->with( 'get', \Mockery::on(function ($api) { - return 0 === strpos($api, UcloudGateway::ENDPOINT_URL); + return strpos($api, UcloudGateway::ENDPOINT_URL) === 0; }), \Mockery::on(function ($params) { return true; diff --git a/tests/Gateways/Ue35GatewayTest.php b/tests/Gateways/Ue35GatewayTest.php index 06d7e95..4d909c6 100644 --- a/tests/Gateways/Ue35GatewayTest.php +++ b/tests/Gateways/Ue35GatewayTest.php @@ -20,7 +20,7 @@ class Ue35GatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'debug' => false, @@ -33,18 +33,18 @@ public function testSend() $gateway->shouldReceive('request')->with( 'get', \Mockery::on(function ($api) { - return 0 === strpos($api, Ue35Gateway::getEndpointUri()); + return strpos($api, Ue35Gateway::getEndpointUri()) === 0; }), \Mockery::on(function ($params) { return true; }) ) - ->andReturn([ - 'errorcode' => Ue35Gateway::SUCCESS_CODE, - ], [ - 'errorcode' => 100, - 'message' => 'error', - ])->twice(); + ->andReturn([ + 'errorcode' => Ue35Gateway::SUCCESS_CODE, + ], [ + 'errorcode' => 100, + 'message' => 'error', + ])->twice(); $message = new Message(['content' => 'content']); $config = new Config($config); diff --git a/tests/Gateways/VolcengineGatewayTest.php b/tests/Gateways/VolcengineGatewayTest.php index e0403fd..e187e29 100644 --- a/tests/Gateways/VolcengineGatewayTest.php +++ b/tests/Gateways/VolcengineGatewayTest.php @@ -20,7 +20,7 @@ class VolcengineGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'access_key_id' => 'mock_access_key_id', diff --git a/tests/Gateways/WeiqucloudGatewayTest.php b/tests/Gateways/WeiqucloudGatewayTest.php index 59652b2..b46f7f7 100644 --- a/tests/Gateways/WeiqucloudGatewayTest.php +++ b/tests/Gateways/WeiqucloudGatewayTest.php @@ -20,7 +20,7 @@ class WeiqucloudGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'userId' => 'mock-user-id', @@ -39,7 +39,6 @@ public function testSend() 'action' => 'sendhy', ]; - // 成功响应的数据结构 $successResponse = [ 'code' => 200, @@ -47,8 +46,8 @@ public function testSend() 'status' => 'Success', 'taskID' => 'mock-task-id', 'remainPoint' => 100, - 'message' => '发送成功' - ] + 'message' => '发送成功', + ], ]; // 失败响应的数据结构 @@ -58,8 +57,8 @@ public function testSend() 'status' => 'Failed', 'message' => '账户余额不足', 'remainPoint' => 0, - 'taskID' => 'mock-task-id-failed' - ] + 'taskID' => 'mock-task-id-failed', + ], ]; $gateway->shouldReceive('postJson') @@ -81,4 +80,4 @@ public function testSend() $gateway->send(new PhoneNumber(18188888888), $message, $config); } -} \ No newline at end of file +} diff --git a/tests/Gateways/YidongmasblackGatewayTest.php b/tests/Gateways/YidongmasblackGatewayTest.php index e502616..0881fad 100644 --- a/tests/Gateways/YidongmasblackGatewayTest.php +++ b/tests/Gateways/YidongmasblackGatewayTest.php @@ -20,7 +20,7 @@ class YidongmasblackGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'ecName' => 'mock-ec-name', diff --git a/tests/Gateways/YunpianGatewayTest.php b/tests/Gateways/YunpianGatewayTest.php index 567b882..a892eaa 100644 --- a/tests/Gateways/YunpianGatewayTest.php +++ b/tests/Gateways/YunpianGatewayTest.php @@ -20,7 +20,7 @@ class YunpianGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'api_key' => 'mock-api-key', @@ -66,7 +66,7 @@ public function testSend() $gateway->send(new PhoneNumber(18188888888), $message, $config); } - public function testDefaultSignature() + public function test_default_signature() { $config = [ 'api_key' => 'mock-api-key', diff --git a/tests/Gateways/YuntongxunGatewayTest.php b/tests/Gateways/YuntongxunGatewayTest.php index 522b2e8..99d55d8 100644 --- a/tests/Gateways/YuntongxunGatewayTest.php +++ b/tests/Gateways/YuntongxunGatewayTest.php @@ -20,7 +20,7 @@ class YuntongxunGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'debug' => false, @@ -34,7 +34,7 @@ public function testSend() $gateway->shouldReceive('request')->with( 'post', \Mockery::on(function ($api) { - return 0 === strpos($api, 'https://app.cloopen.com:8883/2013-12-26/Accounts/mock-account-sid/SMS/TemplateSMS?sig='); + return strpos($api, 'https://app.cloopen.com:8883/2013-12-26/Accounts/mock-account-sid/SMS/TemplateSMS?sig=') === 0; }), \Mockery::on(function ($params) { return $params['json'] == [ @@ -42,15 +42,15 @@ public function testSend() 'templateId' => 5589, 'appId' => 'mock-app-id', 'datas' => ['mock-data-1', 'mock-data-2'], - ] && 'application/json' == $params['headers']['Accept'] - && 'application/json;charset=utf-8' == $params['headers']['Content-Type']; + ] && $params['headers']['Accept'] == 'application/json' + && $params['headers']['Content-Type'] == 'application/json;charset=utf-8'; }) ) - ->andReturn([ - 'statusCode' => YuntongxunGateway::SUCCESS_CODE, - ], [ - 'statusCode' => 100, - ])->twice(); + ->andReturn([ + 'statusCode' => YuntongxunGateway::SUCCESS_CODE, + ], [ + 'statusCode' => 100, + ])->twice(); $message = new Message(['data' => ['mock-data-1', 'mock-data-2'], 'template' => 5589]); $config = new Config($config); @@ -67,7 +67,7 @@ public function testSend() } // 国际短信 - public function testSendIntl() + public function test_send_intl() { $config = [ 'debug' => false, @@ -81,15 +81,15 @@ public function testSendIntl() $gateway->shouldReceive('request')->with( 'post', \Mockery::on(function ($api) { - return 0 === strpos($api, 'https://app.cloopen.com:8883/v2/account/mock-account-sid/international/send?sig='); + return strpos($api, 'https://app.cloopen.com:8883/v2/account/mock-account-sid/international/send?sig=') === 0; }), \Mockery::on(function ($params) { return $params['json'] == [ 'appId' => 'mock-app-id', 'mobile' => '006018188888888', 'content' => '容联云国际短信测试', - ] && 'application/json' == $params['headers']['Accept'] - && 'application/json;charset=utf-8' == $params['headers']['Content-Type']; + ] && $params['headers']['Accept'] == 'application/json' + && $params['headers']['Content-Type'] == 'application/json;charset=utf-8'; }) )->andReturn([ 'statusCode' => YuntongxunGateway::SUCCESS_CODE, diff --git a/tests/Gateways/YunxinGatewayTest.php b/tests/Gateways/YunxinGatewayTest.php index f01288d..4c783a6 100755 --- a/tests/Gateways/YunxinGatewayTest.php +++ b/tests/Gateways/YunxinGatewayTest.php @@ -20,7 +20,7 @@ class YunxinGatewayTest extends TestCase { - public function testSendWithSendCode() + public function test_send_with_send_code() { $config = [ 'app_key' => 'mock-app-key', @@ -72,7 +72,7 @@ public function testSendWithSendCode() $gateway->send($phone, $message, $config); } - public function testSendWithVerifyCode() + public function test_send_with_verify_code() { $config = [ 'app_key' => 'mock-app-key', @@ -123,7 +123,7 @@ public function testSendWithVerifyCode() $gateway->send($phone, $message, $config); } - public function testSendWithTemplateMsg() + public function test_send_with_template_msg() { $config = [ 'app_key' => 'mock-app-key', @@ -178,7 +178,7 @@ public function testSendWithTemplateMsg() $gateway->send($phone, $message, $config); } - public function testBuildEndpoint() + public function test_build_endpoint() { $config = [ 'app_key' => 'mock-app-key', @@ -201,7 +201,7 @@ public function testBuildEndpoint() ); } - public function testBuildHeaders() + public function test_build_headers() { $config = [ 'app_key' => 'mock-app-key', @@ -223,7 +223,7 @@ public function testBuildHeaders() $this->assertSame($checkSum, $headers['CheckSum']); } - public function testBuildSendCodeParams() + public function test_build_send_code_params() { $config = [ 'app_key' => 'mock-app-key', @@ -259,7 +259,7 @@ public function testBuildSendCodeParams() ], $method->invoke($gateway, $phone, $message, $config)); } - public function testBuildVerifyCodeParams() + public function test_build_verify_code_params() { $config = [ 'app_key' => 'mock-app-key', diff --git a/tests/Gateways/YunzhixunGatewayTest.php b/tests/Gateways/YunzhixunGatewayTest.php index fa270ad..72e02e2 100755 --- a/tests/Gateways/YunzhixunGatewayTest.php +++ b/tests/Gateways/YunzhixunGatewayTest.php @@ -20,7 +20,7 @@ class YunzhixunGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'sid' => 'mock-sid', @@ -65,7 +65,7 @@ public function testSend() $this->assertSame('mock-result', $gateway->send($phone, $message, $config)); } - public function testSendWithBatch() + public function test_send_with_batch() { $config = [ 'sid' => 'mock-sid', @@ -112,7 +112,7 @@ public function testSendWithBatch() $this->assertSame('mock-result', $gateway->send($phone, $message, $config)); } - public function testBuildEndpoint() + public function test_build_endpoint() { $config = [ 'sid' => 'mock-sid', @@ -141,7 +141,7 @@ public function testBuildEndpoint() ); } - public function testBuildParams() + public function test_build_params() { $config = [ 'sid' => 'mock-sid', @@ -190,7 +190,7 @@ public function testBuildParams() ], $method->invoke($gateway, $phone, $message, $config)); } - public function testExecute() + public function test_execute() { $config = [ 'sid' => 'mock-sid', diff --git a/tests/Gateways/ZzyunGatewayTest.php b/tests/Gateways/ZzyunGatewayTest.php index e2f1c8f..0073b15 100644 --- a/tests/Gateways/ZzyunGatewayTest.php +++ b/tests/Gateways/ZzyunGatewayTest.php @@ -20,7 +20,7 @@ class ZzyunGatewayTest extends TestCase { - public function testSend() + public function test_send() { $config = [ 'user_id' => 'mock-user_id', diff --git a/tests/PhoneNumberTest.php b/tests/PhoneNumberTest.php index fbf5fdd..23aafc7 100644 --- a/tests/PhoneNumberTest.php +++ b/tests/PhoneNumberTest.php @@ -20,7 +20,7 @@ */ class PhoneNumberTest extends TestCase { - public function testOnlyNumber() + public function test_only_number() { $n = new PhoneNumber(18888888888); $this->assertSame(18888888888, $n->getNumber()); @@ -30,7 +30,7 @@ public function testOnlyNumber() $this->assertSame('18888888888', \strval($n)); } - public function testDiffCode() + public function test_diff_code() { $n = new PhoneNumber(18888888888, 68); $this->assertSame(68, $n->getIDDCode()); @@ -42,13 +42,13 @@ public function testDiffCode() $this->assertSame(68, $n->getIDDCode()); } - public function testJsonEncode() + public function test_json_encode() { $n = new PhoneNumber(18888888888, 68); $this->assertSame(json_encode(['number' => $n->getUniversalNumber()]), \json_encode(['number' => $n])); } - public function testInternationalFormat() + public function test_international_format() { // Test international format with + $n = new PhoneNumber('+8618888888888'); @@ -58,7 +58,7 @@ public function testInternationalFormat() $this->assertSame('008618888888888', $n->getZeroPrefixedNumber()); } - public function testInternationalFormatWithoutPlus() + public function test_international_format_without_plus() { // Test international format starting with 00 $n = new PhoneNumber('008618888888888'); @@ -67,7 +67,7 @@ public function testInternationalFormatWithoutPlus() $this->assertSame('+8618888888888', $n->getUniversalNumber()); } - public function testDifferentCountries() + public function test_different_countries() { // Test US number $n = new PhoneNumber('+1 650 253 0000'); @@ -85,7 +85,7 @@ public function testDifferentCountries() $this->assertSame('+441174960123', $n->getUniversalNumber()); } - public function testChineseMainlandCheck() + public function test_chinese_mainland_check() { $n = new PhoneNumber(18888888888); $this->assertTrue($n->inChineseMainland()); diff --git a/tests/Support/ConfigTest.php b/tests/Support/ConfigTest.php index a79508f..d696d73 100644 --- a/tests/Support/ConfigTest.php +++ b/tests/Support/ConfigTest.php @@ -16,7 +16,7 @@ class ConfigTest extends TestCase { - public function testConfig() + public function test_config() { $config = new Config([ 'foo' => 'bar', diff --git a/tests/Traits/HasHttpRequestTest.php b/tests/Traits/HasHttpRequestTest.php index 638001d..2be9b33 100644 --- a/tests/Traits/HasHttpRequestTest.php +++ b/tests/Traits/HasHttpRequestTest.php @@ -19,16 +19,16 @@ class HasHttpRequestTest extends TestCase { - public function testRequest() + public function test_request() { $object = \Mockery::mock(DummyClassForHasHttpRequestTrait::class) - ->shouldAllowMockingProtectedMethods(); + ->shouldAllowMockingProtectedMethods(); $mockBaseOptions = ['base_uri' => 'https://mock-base-options']; $mockResponse = \Mockery::mock(ResponseInterface::class); $mockHttpClient = \Mockery::mock(Client::class); $object->expects()->getHttpClient($mockBaseOptions) - ->andReturn($mockHttpClient) - ->once(); + ->andReturn($mockHttpClient) + ->once(); $object->expects()->getBaseOptions()->andReturn($mockBaseOptions); $object->expects()->unwrapResponse($mockResponse)->andReturn('unwrapped-api-result'); @@ -39,10 +39,10 @@ public function testRequest() $this->assertSame('unwrapped-api-result', $object->request('get', 'mock-endpoint', $options)); } - public function testGet() + public function test_get() { $object = \Mockery::mock(DummyClassForHasHttpRequestTrait::class) - ->shouldAllowMockingProtectedMethods(); + ->shouldAllowMockingProtectedMethods(); $object->expects()->request('get', 'mock-endpoint', [ 'headers' => ['Content-Type' => 'Mock-Content-Type'], 'query' => ['foo' => 'bar'], @@ -54,7 +54,7 @@ public function testGet() $this->assertSame('mock-result', $response); } - public function testPost() + public function test_post() { $object = \Mockery::mock(DummyClassForHasHttpRequestTrait::class) ->shouldAllowMockingProtectedMethods(); @@ -69,11 +69,11 @@ public function testPost() $this->assertSame('mock-result', $response); } - public function testGetBaseOptions() + public function test_get_base_options() { $object = \Mockery::mock(DummyClassForHasHttpRequestTrait::class) - ->makePartial() - ->shouldAllowMockingProtectedMethods(); + ->makePartial() + ->shouldAllowMockingProtectedMethods(); $object->shouldReceive('getBaseOptions')->withAnyArgs()->passthru(); $this->assertSame('http://mock-uri', $object->getBaseOptions()['base_uri']); @@ -81,15 +81,15 @@ public function testGetBaseOptions() // timeout overwrite $object = \Mockery::mock(DummyTimeoutClassForHasHttpRequestTrait::class) - ->makePartial() - ->shouldAllowMockingProtectedMethods(); + ->makePartial() + ->shouldAllowMockingProtectedMethods(); $object->shouldReceive('getBaseOptions')->withAnyArgs()->passthru(); $this->assertSame('http://mock-uri', $object->getBaseOptions()['base_uri']); $this->assertSame(30.0, $object->getBaseOptions()['timeout']); } - public function testUnwrapResponseWithJsonResponse() + public function test_unwrap_response_with_json_response() { $object = \Mockery::mock(DummyClassForHasHttpRequestTrait::class) ->makePartial() @@ -102,7 +102,7 @@ public function testUnwrapResponseWithJsonResponse() $this->assertSame($body, $object->unwrapResponse($response)); } - public function testUnwrapResponseWithXMLResponse() + public function test_unwrap_response_with_xml_response() { $object = \Mockery::mock(DummyClassForHasHttpRequestTrait::class) ->makePartial() @@ -118,7 +118,7 @@ public function testUnwrapResponseWithXMLResponse() $this->assertSame(['foo' => 'hello', 'bar' => 'world'], $object->unwrapResponse($response)); } - public function testUnwrapResponseWithUnsupportedResponse() + public function test_unwrap_response_with_unsupported_response() { $object = \Mockery::mock(DummyClassForHasHttpRequestTrait::class) ->makePartial()