Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
calchen authored and StyleCIBot committed Dec 30, 2019
1 parent c807730 commit 8d6641b
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 113 deletions.
6 changes: 3 additions & 3 deletions config/dingtalk_robot.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
'access_token' => env('DINGTALK_ROBOT_ACCESS_TOKEN', ''),

// 请求的超时时间
'timeout' => env('DINGTALK_ROBOT_TIMEOUT', 2.0)
]
];
'timeout' => env('DINGTALK_ROBOT_TIMEOUT', 2.0),
],
];
34 changes: 19 additions & 15 deletions src/DingtalkRobot.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@
use Calchen\LaravelDingtalkRobot\Exception\Exception;
use Calchen\LaravelDingtalkRobot\Exception\HttpException;
use Calchen\LaravelDingtalkRobot\Exception\InvalidConfigurationException;
use GuzzleHttp\Client;
use Calchen\LaravelDingtalkRobot\Message\Message;
use GuzzleHttp\Client;

/**
* 钉钉群消息机器 API
* 钉钉群消息机器 API.
*
* Class DingtalkRobot
* @package Calchen\LaravelDingtalkRobot
*/
class DingtalkRobot
{
protected $config;
/**
* @var string
*/
protected $accessToken = "";
protected $accessToken = '';
/**
* @var string
*/
protected $robotUrl = "https://oapi.dingtalk.com/robot/send";
protected $robotUrl = 'https://oapi.dingtalk.com/robot/send';

/**
* 消息对象
Expand All @@ -42,12 +41,13 @@ public function __construct()
}

/**
* 指定机器人名称,默认为 default
* 指定机器人名称,默认为 default.
*
* @param string $name
*
* @return $this
* @throws \Exception
*
* @return $this
*/
public function robot($name = 'default'): self
{
Expand All @@ -68,18 +68,20 @@ public function robot($name = 'default'): self
*
* @param Message $message
*
* @return $this
* @throws \Exception
*
* @return $this
*/
public function setMessage(Message $message): self
{
$this->message = $message;
$this->robot($message->getRobot());

return $this;
}

/**
* 获取 message 对象的内容
* 获取 message 对象的内容.
*
* @return array
*/
Expand All @@ -89,7 +91,7 @@ public function getMessage(): array
}

/**
* 获取附带 access_token 的 webhook Url
* 获取附带 access_token 的 webhook Url.
*
* @return string
*/
Expand All @@ -99,10 +101,11 @@ protected function getRobotUrl(): string
}

/**
* 发起请求,返回的内容与直接调用钉钉接口返回的内容一致
* 发起请求,返回的内容与直接调用钉钉接口返回的内容一致.
*
* @return bool|string
* @throws Exception
*
* @return bool|string
*/
public function send(): string
{
Expand All @@ -118,15 +121,16 @@ public function send(): string
$response = $client->post(
$this->getRobotUrl(),
[
'json' => $this->message->getMessage(),
'json' => $this->message->getMessage(),
'headers' => [
'Content-Type' => 'application/json',
]
],
]
);

return $response->getBody()->getContents();
} catch (Exception $e) {
throw new HttpException($e->getMessage(), $e->getCode(), $e);
}
}
}
}
5 changes: 2 additions & 3 deletions src/DingtalkRobotChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
use Illuminate\Notifications\Notification;

/**
* 自定义的钉钉群机器人消息发送渠道
* 自定义的钉钉群机器人消息发送渠道.
*
* Class DingtalkRobotChannel
* @package Calchen\LaravelDingtalkRobot
*/
class DingtalkRobotChannel
{
Expand All @@ -32,4 +31,4 @@ public function send($notifiable, Notification $notification)
$ding = new DingtalkRobot();
$ding->setMessage($message)->send();
}
}
}
11 changes: 5 additions & 6 deletions src/DingtalkRobotNoticeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Laravel\Lumen\Application as LumenApplication;

/**
* DingNotice SDK 的 ServiceProvider 只支持 Laravel
* DingNotice SDK 的 ServiceProvider 只支持 Laravel.
*/
class DingtalkRobotNoticeServiceProvider extends ServiceProvider
{
Expand All @@ -22,20 +22,19 @@ public function boot()
}

/**
* 处理配置项
* 处理配置项.
*
* @return void
*/
protected function setupConfig(): void
{
$source = realpath($raw = __DIR__ . '/../config/dingtalk_robot.php') ?: $raw;
$source = realpath($raw = __DIR__.'/../config/dingtalk_robot.php') ?: $raw;

if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
$this->publishes([
$source => config_path('dingtalk_robot.php')
$source => config_path('dingtalk_robot.php'),
]);
}
elseif ($this->app instanceof LumenApplication) {
} elseif ($this->app instanceof LumenApplication) {
$this->app->configure('dingtalk_robot');
}

Expand Down
5 changes: 2 additions & 3 deletions src/Exceptions/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
namespace Calchen\LaravelDingtalkRobot\Exception;

/**
* 异常基类
* 异常基类.
*
* Class Exception
* @package Calchen\LaravelDingtalkRobot\Exception
*/
class Exception extends \Exception
{
//
}
}
5 changes: 2 additions & 3 deletions src/Exceptions/HttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
namespace Calchen\LaravelDingtalkRobot\Exception;

/**
* Http 请求异常
* Http 请求异常.
*
* Class HttpException
* @package Calchen\LaravelDingtalkRobot\Exception
*/
class HttpException extends Exception
{
//
}
}
5 changes: 2 additions & 3 deletions src/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
namespace Calchen\LaravelDingtalkRobot\Exception;

/**
* 入参异常
* 入参异常.
*
* Class InvalidArgumentException
* @package Calchen\LaravelDingtalkRobot\Exception
*/
class InvalidArgumentException extends Exception
{
//
}
}
5 changes: 2 additions & 3 deletions src/Exceptions/InvalidConfigurationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
namespace Calchen\LaravelDingtalkRobot\Exception;

/**
* 配置文件异常
* 配置文件异常.
*
* Class InvalidConfigurationException
* @package Calchen\LaravelDingtalkRobot\Exception
*/
class InvalidConfigurationException extends Exception
{
//
}
}
37 changes: 19 additions & 18 deletions src/Message/ActionCardMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
use Calchen\LaravelDingtalkRobot\Exception\InvalidConfigurationException;

/**
* ActionCard类型,包含整体跳转和独立跳转
* ActionCard类型,包含整体跳转和独立跳转.
*
* Class DingtalkActionCardMessage
* @package Calchen\LaravelDingtalkRobot
*/
class ActionCardMessage extends Message
{
Expand All @@ -32,19 +31,19 @@ public function __construct(string $title, string $text, int $hideAvatar = 0, in
*/
const HIDE_AVATAR_VALUES = [
0, // 按钮竖直排列
1 // 按钮横向排列
1, // 按钮横向排列
];

/**
* btnOrientation 的值
*/
const BTN_ORIENTATION_VALUES = [
0, // 正常发消息者头像
1 // 隐藏发消息者头像
1, // 隐藏发消息者头像
];

/**
* ActionCard 的整体跳转和独立跳转两种类型中 title text hideAvatar btnOrientation 都是共同拥有的
* ActionCard 的整体跳转和独立跳转两种类型中 title text hideAvatar btnOrientation 都是共同拥有的.
*
* @param string $title 首屏会话透出的展示内容
* @param string $text markdown 格式的消息
Expand All @@ -56,25 +55,25 @@ public function __construct(string $title, string $text, int $hideAvatar = 0, in
public function setMessage(string $title, string $text, int $hideAvatar = 0, int $btnOrientation = 0): void
{
if (array_search($hideAvatar, self::HIDE_AVATAR_VALUES) === false) {
throw new InvalidConfigurationException("hideAvatar value can only be 0 or 1");
throw new InvalidConfigurationException('hideAvatar value can only be 0 or 1');
}
if (array_search($btnOrientation, self::BTN_ORIENTATION_VALUES) === false) {
throw new InvalidConfigurationException("btnOrientation value can only be 0 or 1");
throw new InvalidConfigurationException('btnOrientation value can only be 0 or 1');
}

$this->message = [
'msgtype' => 'actionCard',
'msgtype' => 'actionCard',
'actionCard' => [
'title' => $title,
'text' => $text,
'hideAvatar' => $hideAvatar,
'btnOrientation' => $btnOrientation
]
'title' => $title,
'text' => $text,
'hideAvatar' => $hideAvatar,
'btnOrientation' => $btnOrientation,
],
];
}

/**
* 设置整体跳转类型参数
* 设置整体跳转类型参数.
*
* @param string $singleTitle 单个按钮的方案。(设置此项和singleURL后btns无效。)
* @param string $singleUrl 点击singleTitle按钮触发的URL
Expand All @@ -85,11 +84,12 @@ public function setSingle(string $singleTitle, string $singleUrl): self
{
$this->message['actionCard']['singleTitle'] = $singleTitle;
$this->message['actionCard']['singleURL'] = $singleUrl;

return $this;
}

/**
* 设置独立跳转类型按钮参数
* 设置独立跳转类型按钮参数.
*
* @param string $title 按钮方案
* @param string $actionUrl 点击按钮触发的URL
Expand All @@ -99,9 +99,10 @@ public function setSingle(string $singleTitle, string $singleUrl): self
public function addButton(string $title, string $actionUrl): self
{
$this->message['actionCard']['btns'][] = [
'title' => $title,
'actionURL' => $actionUrl
'title' => $title,
'actionURL' => $actionUrl,
];

return $this;
}
}
}
17 changes: 7 additions & 10 deletions src/Message/FeedCardMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,20 @@ class FeedCardMessage extends Message
public function __construct()
{
$this->setMessage();

}

/**
*
*/
public function setMessage(): void
{
$this->message = [
'feedCard' => [
'links' => []
'links' => [],
],
'msgtype' => 'feedCard'
'msgtype' => 'feedCard',
];
}

/**
* 增加链接
* 增加链接.
*
* @param string $title 单条信息文本
* @param string $messageUrl 点击单条信息到跳转链接
Expand All @@ -38,10 +34,11 @@ public function setMessage(): void
public function addLink(string $title, string $messageUrl, string $picUrl): self
{
$this->message['feedCard']['links'][] = [
'title' => $title,
'title' => $title,
'messageURL' => $messageUrl,
'picURL' => $picUrl
'picURL' => $picUrl,
];

return $this;
}
}
}
Loading

0 comments on commit 8d6641b

Please sign in to comment.