Skip to content

Commit 8d6641b

Browse files
calchenStyleCIBot
authored andcommittedDec 30, 2019
Apply fixes from StyleCI
1 parent c807730 commit 8d6641b

16 files changed

+107
-113
lines changed
 

‎config/dingtalk_robot.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
'access_token' => env('DINGTALK_ROBOT_ACCESS_TOKEN', ''),
88

99
// 请求的超时时间
10-
'timeout' => env('DINGTALK_ROBOT_TIMEOUT', 2.0)
11-
]
12-
];
10+
'timeout' => env('DINGTALK_ROBOT_TIMEOUT', 2.0),
11+
],
12+
];

‎src/DingtalkRobot.php

+19-15
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,25 @@
55
use Calchen\LaravelDingtalkRobot\Exception\Exception;
66
use Calchen\LaravelDingtalkRobot\Exception\HttpException;
77
use Calchen\LaravelDingtalkRobot\Exception\InvalidConfigurationException;
8-
use GuzzleHttp\Client;
98
use Calchen\LaravelDingtalkRobot\Message\Message;
9+
use GuzzleHttp\Client;
1010

1111
/**
12-
* 钉钉群消息机器 API
12+
* 钉钉群消息机器 API.
1313
*
1414
* Class DingtalkRobot
15-
* @package Calchen\LaravelDingtalkRobot
1615
*/
1716
class DingtalkRobot
1817
{
1918
protected $config;
2019
/**
2120
* @var string
2221
*/
23-
protected $accessToken = "";
22+
protected $accessToken = '';
2423
/**
2524
* @var string
2625
*/
27-
protected $robotUrl = "https://oapi.dingtalk.com/robot/send";
26+
protected $robotUrl = 'https://oapi.dingtalk.com/robot/send';
2827

2928
/**
3029
* 消息对象
@@ -42,12 +41,13 @@ public function __construct()
4241
}
4342

4443
/**
45-
* 指定机器人名称,默认为 default
44+
* 指定机器人名称,默认为 default.
4645
*
4746
* @param string $name
4847
*
49-
* @return $this
5048
* @throws \Exception
49+
*
50+
* @return $this
5151
*/
5252
public function robot($name = 'default'): self
5353
{
@@ -68,18 +68,20 @@ public function robot($name = 'default'): self
6868
*
6969
* @param Message $message
7070
*
71-
* @return $this
7271
* @throws \Exception
72+
*
73+
* @return $this
7374
*/
7475
public function setMessage(Message $message): self
7576
{
7677
$this->message = $message;
7778
$this->robot($message->getRobot());
79+
7880
return $this;
7981
}
8082

8183
/**
82-
* 获取 message 对象的内容
84+
* 获取 message 对象的内容.
8385
*
8486
* @return array
8587
*/
@@ -89,7 +91,7 @@ public function getMessage(): array
8991
}
9092

9193
/**
92-
* 获取附带 access_token 的 webhook Url
94+
* 获取附带 access_token 的 webhook Url.
9395
*
9496
* @return string
9597
*/
@@ -99,10 +101,11 @@ protected function getRobotUrl(): string
99101
}
100102

101103
/**
102-
* 发起请求,返回的内容与直接调用钉钉接口返回的内容一致
104+
* 发起请求,返回的内容与直接调用钉钉接口返回的内容一致.
103105
*
104-
* @return bool|string
105106
* @throws Exception
107+
*
108+
* @return bool|string
106109
*/
107110
public function send(): string
108111
{
@@ -118,15 +121,16 @@ public function send(): string
118121
$response = $client->post(
119122
$this->getRobotUrl(),
120123
[
121-
'json' => $this->message->getMessage(),
124+
'json' => $this->message->getMessage(),
122125
'headers' => [
123126
'Content-Type' => 'application/json',
124-
]
127+
],
125128
]
126129
);
130+
127131
return $response->getBody()->getContents();
128132
} catch (Exception $e) {
129133
throw new HttpException($e->getMessage(), $e->getCode(), $e);
130134
}
131135
}
132-
}
136+
}

‎src/DingtalkRobotChannel.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
use Illuminate\Notifications\Notification;
77

88
/**
9-
* 自定义的钉钉群机器人消息发送渠道
9+
* 自定义的钉钉群机器人消息发送渠道.
1010
*
1111
* Class DingtalkRobotChannel
12-
* @package Calchen\LaravelDingtalkRobot
1312
*/
1413
class DingtalkRobotChannel
1514
{
@@ -32,4 +31,4 @@ public function send($notifiable, Notification $notification)
3231
$ding = new DingtalkRobot();
3332
$ding->setMessage($message)->send();
3433
}
35-
}
34+
}

‎src/DingtalkRobotNoticeServiceProvider.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Laravel\Lumen\Application as LumenApplication;
88

99
/**
10-
* DingNotice SDK 的 ServiceProvider 只支持 Laravel
10+
* DingNotice SDK 的 ServiceProvider 只支持 Laravel.
1111
*/
1212
class DingtalkRobotNoticeServiceProvider extends ServiceProvider
1313
{
@@ -22,20 +22,19 @@ public function boot()
2222
}
2323

2424
/**
25-
* 处理配置项
25+
* 处理配置项.
2626
*
2727
* @return void
2828
*/
2929
protected function setupConfig(): void
3030
{
31-
$source = realpath($raw = __DIR__ . '/../config/dingtalk_robot.php') ?: $raw;
31+
$source = realpath($raw = __DIR__.'/../config/dingtalk_robot.php') ?: $raw;
3232

3333
if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
3434
$this->publishes([
35-
$source => config_path('dingtalk_robot.php')
35+
$source => config_path('dingtalk_robot.php'),
3636
]);
37-
}
38-
elseif ($this->app instanceof LumenApplication) {
37+
} elseif ($this->app instanceof LumenApplication) {
3938
$this->app->configure('dingtalk_robot');
4039
}
4140

‎src/Exceptions/Exception.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
namespace Calchen\LaravelDingtalkRobot\Exception;
44

55
/**
6-
* 异常基类
6+
* 异常基类.
77
*
88
* Class Exception
9-
* @package Calchen\LaravelDingtalkRobot\Exception
109
*/
1110
class Exception extends \Exception
1211
{
1312
//
14-
}
13+
}

‎src/Exceptions/HttpException.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
namespace Calchen\LaravelDingtalkRobot\Exception;
44

55
/**
6-
* Http 请求异常
6+
* Http 请求异常.
77
*
88
* Class HttpException
9-
* @package Calchen\LaravelDingtalkRobot\Exception
109
*/
1110
class HttpException extends Exception
1211
{
1312
//
14-
}
13+
}

‎src/Exceptions/InvalidArgumentException.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
namespace Calchen\LaravelDingtalkRobot\Exception;
44

55
/**
6-
* 入参异常
6+
* 入参异常.
77
*
88
* Class InvalidArgumentException
9-
* @package Calchen\LaravelDingtalkRobot\Exception
109
*/
1110
class InvalidArgumentException extends Exception
1211
{
1312
//
14-
}
13+
}

‎src/Exceptions/InvalidConfigurationException.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
namespace Calchen\LaravelDingtalkRobot\Exception;
44

55
/**
6-
* 配置文件异常
6+
* 配置文件异常.
77
*
88
* Class InvalidConfigurationException
9-
* @package Calchen\LaravelDingtalkRobot\Exception
109
*/
1110
class InvalidConfigurationException extends Exception
1211
{
1312
//
14-
}
13+
}

‎src/Message/ActionCardMessage.php

+19-18
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
use Calchen\LaravelDingtalkRobot\Exception\InvalidConfigurationException;
66

77
/**
8-
* ActionCard类型,包含整体跳转和独立跳转
8+
* ActionCard类型,包含整体跳转和独立跳转.
99
*
1010
* Class DingtalkActionCardMessage
11-
* @package Calchen\LaravelDingtalkRobot
1211
*/
1312
class ActionCardMessage extends Message
1413
{
@@ -32,19 +31,19 @@ public function __construct(string $title, string $text, int $hideAvatar = 0, in
3231
*/
3332
const HIDE_AVATAR_VALUES = [
3433
0, // 按钮竖直排列
35-
1 // 按钮横向排列
34+
1, // 按钮横向排列
3635
];
3736

3837
/**
3938
* btnOrientation 的值
4039
*/
4140
const BTN_ORIENTATION_VALUES = [
4241
0, // 正常发消息者头像
43-
1 // 隐藏发消息者头像
42+
1, // 隐藏发消息者头像
4443
];
4544

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

6564
$this->message = [
66-
'msgtype' => 'actionCard',
65+
'msgtype' => 'actionCard',
6766
'actionCard' => [
68-
'title' => $title,
69-
'text' => $text,
70-
'hideAvatar' => $hideAvatar,
71-
'btnOrientation' => $btnOrientation
72-
]
67+
'title' => $title,
68+
'text' => $text,
69+
'hideAvatar' => $hideAvatar,
70+
'btnOrientation' => $btnOrientation,
71+
],
7372
];
7473
}
7574

7675
/**
77-
* 设置整体跳转类型参数
76+
* 设置整体跳转类型参数.
7877
*
7978
* @param string $singleTitle 单个按钮的方案。(设置此项和singleURL后btns无效。)
8079
* @param string $singleUrl 点击singleTitle按钮触发的URL
@@ -85,11 +84,12 @@ public function setSingle(string $singleTitle, string $singleUrl): self
8584
{
8685
$this->message['actionCard']['singleTitle'] = $singleTitle;
8786
$this->message['actionCard']['singleURL'] = $singleUrl;
87+
8888
return $this;
8989
}
9090

9191
/**
92-
* 设置独立跳转类型按钮参数
92+
* 设置独立跳转类型按钮参数.
9393
*
9494
* @param string $title 按钮方案
9595
* @param string $actionUrl 点击按钮触发的URL
@@ -99,9 +99,10 @@ public function setSingle(string $singleTitle, string $singleUrl): self
9999
public function addButton(string $title, string $actionUrl): self
100100
{
101101
$this->message['actionCard']['btns'][] = [
102-
'title' => $title,
103-
'actionURL' => $actionUrl
102+
'title' => $title,
103+
'actionURL' => $actionUrl,
104104
];
105+
105106
return $this;
106107
}
107-
}
108+
}

‎src/Message/FeedCardMessage.php

+7-10
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,20 @@ class FeedCardMessage extends Message
1010
public function __construct()
1111
{
1212
$this->setMessage();
13-
1413
}
1514

16-
/**
17-
*
18-
*/
1915
public function setMessage(): void
2016
{
2117
$this->message = [
2218
'feedCard' => [
23-
'links' => []
19+
'links' => [],
2420
],
25-
'msgtype' => 'feedCard'
21+
'msgtype' => 'feedCard',
2622
];
2723
}
2824

2925
/**
30-
* 增加链接
26+
* 增加链接.
3127
*
3228
* @param string $title 单条信息文本
3329
* @param string $messageUrl 点击单条信息到跳转链接
@@ -38,10 +34,11 @@ public function setMessage(): void
3834
public function addLink(string $title, string $messageUrl, string $picUrl): self
3935
{
4036
$this->message['feedCard']['links'][] = [
41-
'title' => $title,
37+
'title' => $title,
4238
'messageURL' => $messageUrl,
43-
'picURL' => $picUrl
39+
'picURL' => $picUrl,
4440
];
41+
4542
return $this;
4643
}
47-
}
44+
}

‎src/Message/LinkMessage.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
namespace Calchen\LaravelDingtalkRobot\Message;
44

55
/**
6-
* link类型
6+
* link类型.
77
*
88
* Class DingtalkLinkMessage
9-
* @package Calchen\LaravelDingtalkRobot
109
*/
1110
class LinkMessage extends Message
1211
{
@@ -33,12 +32,12 @@ public function setMessage(string $title, string $text, string $messageUrl, stri
3332
{
3433
$this->message = [
3534
'msgtype' => 'link',
36-
'link' => [
37-
'title' => $title,
38-
'text' => $text,
39-
'picUrl' => $picUrl,
40-
'messageUrl' => $messageUrl
41-
]
35+
'link' => [
36+
'title' => $title,
37+
'text' => $text,
38+
'picUrl' => $picUrl,
39+
'messageUrl' => $messageUrl,
40+
],
4241
];
4342
}
44-
}
43+
}

‎src/Message/MarkdownMessage.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
use Calchen\LaravelDingtalkRobot\Exception\InvalidArgumentException;
66

77
/**
8-
* markdown类型
8+
* markdown类型.
99
*
1010
* Class DingtalkMarkdownMessage
11-
* @package Calchen\LaravelDingtalkRobot
1211
*/
1312
class MarkdownMessage extends Message
1413
{
@@ -30,21 +29,22 @@ public function __construct(string $title, string $text)
3029
public function setMessage(string $title, string $text): void
3130
{
3231
$this->message = [
33-
'msgtype' => 'markdown',
32+
'msgtype' => 'markdown',
3433
'markdown' => [
3534
'title' => $title,
36-
'text' => $text
37-
]
35+
'text' => $text,
36+
],
3837
];
3938
}
4039

4140
/**
42-
* 通过手机号码指定“被@人列表”
41+
* 通过手机号码指定“被@人列表”.
4342
*
4443
* @param string|array $mobiles 被@人的手机号(在text内容里要有@手机号)
4544
*
46-
* @return MarkdownMessage
4745
* @throws InvalidArgumentException
46+
*
47+
* @return MarkdownMessage
4848
*/
4949
public function at($mobiles): self
5050
{
@@ -56,8 +56,8 @@ public function at($mobiles): self
5656

5757
$this->at = [
5858
'at' => [
59-
'atMobiles' => $mobiles
60-
]
59+
'atMobiles' => $mobiles,
60+
],
6161
];
6262

6363
return $this;
@@ -72,10 +72,10 @@ public function atAll(): self
7272
{
7373
$this->at = [
7474
'at' => [
75-
'isAtAll' => true
76-
]
75+
'isAtAll' => true,
76+
],
7777
];
7878

7979
return $this;
8080
}
81-
}
81+
}

‎src/Message/Message.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
namespace Calchen\LaravelDingtalkRobot\Message;
44

55
/**
6-
* 机器人群消息的基类
6+
* 机器人群消息的基类.
77
*
88
* Class Message
9-
* @package Calchen\LaravelDingtalkRobot\Message
109
*/
1110
abstract class Message
1211
{
@@ -19,9 +18,8 @@ abstract class Message
1918
// 设置机器人名称,默认为 default
2019
protected $robot = 'default';
2120

22-
2321
/**
24-
* 获取消息请求的请求体内容
22+
* 获取消息请求的请求体内容.
2523
*
2624
* @return array
2725
*/
@@ -31,7 +29,7 @@ public function getMessage(): array
3129
}
3230

3331
/**
34-
* 设置接受消息的机器人名称
32+
* 设置接受消息的机器人名称.
3533
*
3634
* @param $robot
3735
*
@@ -40,16 +38,17 @@ public function getMessage(): array
4038
public function setRobot($robot): self
4139
{
4240
$this->robot = $robot;
41+
4342
return $this;
4443
}
4544

4645
/**
47-
* 获取机器人名称
46+
* 获取机器人名称.
4847
*
4948
* @return string
5049
*/
5150
public function getRobot(): string
5251
{
5352
return $this->robot;
5453
}
55-
}
54+
}

‎src/Message/TextMessage.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
use Calchen\LaravelDingtalkRobot\Exception\InvalidArgumentException;
66

77
/**
8-
* 文本类型消息
8+
* 文本类型消息.
99
*
1010
* Class DingtalkTextMessage
11-
* @package Calchen\LaravelDingtalkRobot
1211
*/
1312
class TextMessage extends Message
1413
{
@@ -29,19 +28,20 @@ public function setMessage(string $content): void
2928
{
3029
$this->message = [
3130
'msgtype' => 'text',
32-
'text' => [
33-
'content' => $content
34-
]
31+
'text' => [
32+
'content' => $content,
33+
],
3534
];
3635
}
3736

3837
/**
39-
* 通过手机号码指定“被@人列表”
38+
* 通过手机号码指定“被@人列表”.
4039
*
4140
* @param string|array $mobiles 被@人的手机号(在text内容里要有@手机号)
4241
*
43-
* @return TextMessage
4442
* @throws InvalidArgumentException
43+
*
44+
* @return TextMessage
4545
*/
4646
public function at($mobiles): self
4747
{
@@ -53,8 +53,8 @@ public function at($mobiles): self
5353

5454
$this->at = [
5555
'at' => [
56-
'atMobiles' => $mobiles
57-
]
56+
'atMobiles' => $mobiles,
57+
],
5858
];
5959

6060
return $this;
@@ -69,10 +69,10 @@ public function atAll(): self
6969
{
7070
$this->at = [
7171
'at' => [
72-
'isAtAll' => true
73-
]
72+
'isAtAll' => true,
73+
],
7474
];
7575

7676
return $this;
7777
}
78-
}
78+
}

‎src/Robot.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
/**
88
* 该类是为了方便以机器人的身份发送群消息,无其他作用
9-
* 对于其他使用了 Notifiable Trait 的类都可以用来发送消息
9+
* 对于其他使用了 Notifiable Trait 的类都可以用来发送消息.
1010
*
1111
* Class Robot
12-
* @package Calchen\LaravelDingtalkRobot
1312
*/
1413
class Robot
1514
{
@@ -38,4 +37,4 @@ public function setName(string $name): void
3837
{
3938
$this->name = $name;
4039
}
41-
}
40+
}

‎src/helpers.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
if (!function_exists('dingtalk_robot')) {
66
/**
7-
* 获取钉钉群机器人接口
7+
* 获取钉钉群机器人接口.
88
*
9-
* @return DingtalkRobot
109
* @throws Exception
10+
*
11+
* @return DingtalkRobot
1112
*/
1213
function dingtalk_robot()
1314
{
@@ -22,4 +23,4 @@ function dingtalk_robot()
2223

2324
return $dingTalk->robot($arguments[0]);
2425
}
25-
}
26+
}

0 commit comments

Comments
 (0)
Please sign in to comment.