Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Apr 18, 2024
1 parent 73e1f27 commit ad7a43e
Show file tree
Hide file tree
Showing 72 changed files with 428 additions and 749 deletions.
39 changes: 1 addition & 38 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,7 @@

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'binary_operator_spaces' => true,
'blank_line_after_opening_tag' => true,
'compact_nullable_typehint' => true,
'declare_equal_normalize' => true,
'lowercase_cast' => true,
'lowercase_static_reference' => true,
'new_with_braces' => true,
'no_blank_lines_after_class_opening' => true,
'no_leading_import_slash' => true,
'no_whitespace_in_blank_line' => true,
'no_unused_imports' => true,
'ordered_class_elements' => [
'order' => [
'use_trait',
],
],
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'none',
],
'return_type_declaration' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_trait_insert_per_statement' => true,
'ternary_operator_spaces' => true,
'unary_operator_spaces' => true,
'visibility_required' => [
'elements' => [
// 'const',
'method',
'property',
],
],
'@Symfony' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
Expand Down
35 changes: 7 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"require-dev": {
"phpunit/phpunit": "^5.7 || ^7.5 || ^8.5.19 || ^9.5.8",
"mockery/mockery": "~1.3.3 || ^1.4.2",
"brainmaestro/composer-git-hooks": "^2.8",
"jetbrains/phpstorm-attributes": "^1.0"
"jetbrains/phpstorm-attributes": "^1.0",
"friendsofphp/php-cs-fixer": "^3.54"
},
"autoload": {
"psr-4": {
Expand All @@ -24,34 +24,13 @@
}
},
"license": "MIT",
"authors": [{
"name": "overtrue",
"email": "[email protected]"
}],
"extra": {
"hooks": {
"pre-commit": [
"composer check-style",
"composer psalm",
"composer test"
],
"pre-push": [
"composer check-style"
]
"authors": [
{
"name": "overtrue",
"email": "[email protected]"
}
},
],
"scripts": {
"post-update-cmd": [
"cghooks remove",
"cghooks add --ignore-lock",
"cghooks update"
],
"post-merge": "composer install",
"post-install-cmd": [
"cghooks remove",
"cghooks add --ignore-lock",
"cghooks update"
],
"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",
Expand Down
4 changes: 0 additions & 4 deletions src/Contracts/GatewayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ public function getName();
/**
* Send a short message.
*
* @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to
* @param \Overtrue\EasySms\Contracts\MessageInterface $message
* @param \Overtrue\EasySms\Support\Config $config
*
* @return array
*/
public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config);
Expand Down
16 changes: 5 additions & 11 deletions src/Contracts/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
interface MessageInterface
{
const TEXT_MESSAGE = 'text';
public const TEXT_MESSAGE = 'text';

const VOICE_MESSAGE = 'voice';
public const VOICE_MESSAGE = 'voice';

/**
* Return the message type.
Expand All @@ -30,29 +30,23 @@ public function getMessageType();
/**
* Return message content.
*
* @param \Overtrue\EasySms\Contracts\GatewayInterface|null $gateway
*
* @return string
*/
public function getContent(GatewayInterface $gateway = null);
public function getContent(?GatewayInterface $gateway = null);

/**
* Return the template id of message.
*
* @param \Overtrue\EasySms\Contracts\GatewayInterface|null $gateway
*
* @return string
*/
public function getTemplate(GatewayInterface $gateway = null);
public function getTemplate(?GatewayInterface $gateway = null);

/**
* Return the template data of message.
*
* @param \Overtrue\EasySms\Contracts\GatewayInterface|null $gateway
*
* @return array
*/
public function getData(GatewayInterface $gateway = null);
public function getData(?GatewayInterface $gateway = null);

/**
* Return message supported gateways.
Expand Down
2 changes: 0 additions & 2 deletions src/Contracts/StrategyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ interface StrategyInterface
/**
* Apply the strategy and return result.
*
* @param array $gateways
*
* @return array
*/
public function apply(array $gateways);
Expand Down
55 changes: 23 additions & 32 deletions src/EasySms.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class EasySms
{
/**
* @var \Overtrue\EasySms\Support\Config
* @var Config
*/
protected $config;

Expand All @@ -47,7 +47,7 @@ class EasySms
protected $gateways = [];

/**
* @var \Overtrue\EasySms\Messenger
* @var Messenger
*/
protected $messenger;

Expand All @@ -58,8 +58,6 @@ class EasySms

/**
* Constructor.
*
* @param array $config
*/
public function __construct(array $config)
{
Expand All @@ -69,14 +67,13 @@ public function __construct(array $config)
/**
* Send a message.
*
* @param string|array $to
* @param \Overtrue\EasySms\Contracts\MessageInterface|array $message
* @param array $gateways
* @param string|array $to
* @param MessageInterface|array $message
*
* @return array
*
* @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException
* @throws \Overtrue\EasySms\Exceptions\NoGatewayAvailableException
* @throws InvalidArgumentException
* @throws Exceptions\NoGatewayAvailableException
*/
public function send($to, $message, array $gateways = [])
{
Expand All @@ -96,9 +93,9 @@ public function send($to, $message, array $gateways = [])
*
* @param string|null $name
*
* @return \Overtrue\EasySms\Contracts\GatewayInterface
* @return GatewayInterface
*
* @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*/
public function gateway($name)
{
Expand All @@ -114,9 +111,9 @@ public function gateway($name)
*
* @param string|null $strategy
*
* @return \Overtrue\EasySms\Contracts\StrategyInterface
* @return StrategyInterface
*
* @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*/
public function strategy($strategy = null)
{
Expand All @@ -142,28 +139,27 @@ public function strategy($strategy = null)
/**
* Register a custom driver creator Closure.
*
* @param string $name
* @param \Closure $callback
* @param string $name
*
* @return $this
*/
public function extend($name, Closure $callback)
public function extend($name, \Closure $callback)
{
$this->customCreators[$name] = $callback;

return $this;
}

/**
* @return \Overtrue\EasySms\Support\Config
* @return Config
*/
public function getConfig()
{
return $this->config;
}

/**
* @return \Overtrue\EasySms\Messenger
* @return Messenger
*/
public function getMessenger()
{
Expand All @@ -175,11 +171,10 @@ public function getMessenger()
*
* @param string $name
*
* @throws \InvalidArgumentException
*
* @return GatewayInterface
*
* @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
protected function createGateway($name)
{
Expand Down Expand Up @@ -211,9 +206,9 @@ protected function createGateway($name)
* @param string $gateway
* @param array $config
*
* @return \Overtrue\EasySms\Contracts\GatewayInterface
* @return GatewayInterface
*
* @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*/
protected function makeGateway($gateway, $config)
{
Expand Down Expand Up @@ -247,18 +242,16 @@ protected function formatGatewayClassName($name)
*
* @param string $gateway
* @param array $config
*
* @return mixed
*/
protected function callCustomCreator($gateway, $config)
{
return \call_user_func($this->customCreators[$gateway], $config);
}

/**
* @param string|\Overtrue\EasySms\Contracts\PhoneNumberInterface $number
* @param string|PhoneNumberInterface $number
*
* @return \Overtrue\EasySms\Contracts\PhoneNumberInterface|string
* @return PhoneNumberInterface|string
*/
protected function formatPhoneNumber($number)
{
Expand All @@ -270,9 +263,9 @@ protected function formatPhoneNumber($number)
}

/**
* @param array|string|\Overtrue\EasySms\Contracts\MessageInterface $message
* @param array|string|MessageInterface $message
*
* @return \Overtrue\EasySms\Contracts\MessageInterface
* @return MessageInterface
*/
protected function formatMessage($message)
{
Expand All @@ -291,11 +284,9 @@ protected function formatMessage($message)
}

/**
* @param array $gateways
*
* @return array
*
* @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
*/
protected function formatGateways(array $gateways)
{
Expand Down
1 change: 0 additions & 1 deletion src/Exceptions/GatewayErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class GatewayErrorException extends Exception
*
* @param string $message
* @param int $code
* @param array $raw
*/
public function __construct($message, $code, array $raw = [])
{
Expand Down
11 changes: 2 additions & 9 deletions src/Exceptions/NoGatewayAvailableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Overtrue\EasySms\Exceptions;

use Throwable;

/**
* Class NoGatewayAvailableException.
*
Expand All @@ -33,11 +31,9 @@ class NoGatewayAvailableException extends Exception
/**
* NoGatewayAvailableException constructor.
*
* @param array $results
* @param int $code
* @param \Throwable|null $previous
* @param int $code
*/
public function __construct(array $results = [], $code = 0, Throwable $previous = null)
public function __construct(array $results = [], $code = 0, ?\Throwable $previous = null)
{
$this->results = $results;
$this->exceptions = \array_column($results, 'exception', 'gateway');
Expand Down Expand Up @@ -71,9 +67,6 @@ public function getExceptions()
return $this->exceptions;
}

/**
* @return mixed
*/
public function getLastException()
{
return end($this->exceptions);
Expand Down
Loading

0 comments on commit ad7a43e

Please sign in to comment.