Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ composer.lock
.subsplit
.php_cs.cache
.php-cs-fixer.cache
.pint.cache
.idea
/index.php
/config.php
Expand Down
12 changes: 0 additions & 12 deletions .php-cs-fixer.dist.php

This file was deleted.

7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preset": "laravel"
}
28 changes: 14 additions & 14 deletions src/EasySms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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));
}

Expand All @@ -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));
}

Expand All @@ -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";
}

/**
Expand All @@ -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,
];
}
Expand All @@ -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));
}
}
Expand All @@ -248,4 +248,4 @@ protected function formatGateways(array $gateways): array

return $result;
}
}
}
4 changes: 1 addition & 3 deletions src/Exceptions/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@
*
* @author overtrue <i@overtrue.me>
*/
class Exception extends \Exception
{
}
class Exception extends \Exception {}
4 changes: 2 additions & 2 deletions src/Exceptions/GatewayErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand Down
4 changes: 1 addition & 3 deletions src/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
/**
* Class InvalidArgumentException.
*/
class InvalidArgumentException extends Exception
{
}
class InvalidArgumentException extends Exception {}
5 changes: 2 additions & 3 deletions src/Exceptions/NoGatewayAvailableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -50,8 +50,7 @@ public function getResults()
}

/**
* @param string $gateway
*
* @param string $gateway
* @return mixed|null
*/
public function getException($gateway)
Expand Down
9 changes: 4 additions & 5 deletions src/Gateways/AliyunGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand All @@ -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),
Expand All @@ -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);
}

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Gateways/AliyunIntlGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand All @@ -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),
Expand All @@ -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);
}

Expand Down
12 changes: 5 additions & 7 deletions src/Gateways/AliyunrestGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,22 @@ 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);
}

return $result;
}

/**
* @param array $params
*
* @param array $params
* @return string
*/
protected function getEndpointUrl($params)
Expand All @@ -81,8 +80,7 @@ protected function getEndpointUrl($params)
}

/**
* @param array $params
*
* @param array $params
* @return string
*/
protected function generateSign($params)
Expand All @@ -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";
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/Gateways/BaiduGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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);
}

Expand All @@ -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)
Expand Down
Loading