Skip to content

Commit b172eeb

Browse files
authored
Add code style GH workflow (#131)
1 parent e76ad4b commit b172eeb

16 files changed

+151
-245
lines changed

.github/workflows/code-style.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Code Style
2+
3+
on: [push]
4+
5+
jobs:
6+
php-cs-fixer:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v2
12+
with:
13+
ref: ${{ github.head_ref }}
14+
15+
- name: Run PHP CS Fixer
16+
uses: docker://oskarstark/php-cs-fixer-ga
17+
18+
- name: Commit changes
19+
uses: stefanzweifel/git-auto-commit-action@v4
20+
with:
21+
commit_message: Apply PHP CS Fixer changes
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
build
33
composer.phar
44
composer.lock
5+
.php-cs-fixer.php
6+
.php-cs-fixer.cache
57
.phpunit.result.cache

.php-cs-fixer.dist.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()->in(__DIR__);
4+
5+
$config = new PhpCsFixer\Config();
6+
$config->setRiskyAllowed(true)
7+
->setRules([
8+
'@PhpCsFixer' => true,
9+
])
10+
->setFinder($finder);
11+
12+
return $config;

src/Exceptions/CouldNotSendNotification.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ class CouldNotSendNotification extends Exception
1313
/**
1414
* Thrown when there's a bad request and an error is responded.
1515
*
16-
* @param ClientException $exception
17-
*
1816
* @return static
1917
*/
2018
public static function telegramRespondedWithAnError(ClientException $exception): self
2119
{
22-
if (! $exception->hasResponse()) {
20+
if (!$exception->hasResponse()) {
2321
return new static('Telegram responded with an error but no response body found');
2422
}
2523

src/Telegram.php

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@ class Telegram
1717
/** @var HttpClient HTTP Client */
1818
protected $http;
1919

20-
/** @var string|null Telegram Bot API Token. */
20+
/** @var null|string Telegram Bot API Token. */
2121
protected $token;
2222

2323
/** @var string Telegram Bot API Base URI */
2424
protected $apiBaseUri;
2525

2626
/**
27-
* @param string|null $token
28-
* @param HttpClient|null $httpClient
29-
* @param string|null $apiBaseUri
27+
* @param null|string $token
28+
* @param null|string $apiBaseUri
3029
*/
3130
public function __construct($token = null, HttpClient $httpClient = null, $apiBaseUri = null)
3231
{
@@ -37,8 +36,6 @@ public function __construct($token = null, HttpClient $httpClient = null, $apiBa
3736

3837
/**
3938
* Token getter.
40-
*
41-
* @return string
4239
*/
4340
public function getToken(): string
4441
{
@@ -48,8 +45,6 @@ public function getToken(): string
4845
/**
4946
* Token setter.
5047
*
51-
* @param string $token
52-
*
5348
* @return $this
5449
*/
5550
public function setToken(string $token): self
@@ -61,8 +56,6 @@ public function setToken(string $token): self
6156

6257
/**
6358
* API Base URI getter.
64-
*
65-
* @return string
6659
*/
6760
public function getApiBaseUri(): string
6861
{
@@ -72,8 +65,6 @@ public function getApiBaseUri(): string
7265
/**
7366
* API Base URI setter.
7467
*
75-
* @param string $apiBaseUri
76-
*
7768
* @return $this
7869
*/
7970
public function setApiBaseUri(string $apiBaseUri): self
@@ -83,21 +74,9 @@ public function setApiBaseUri(string $apiBaseUri): self
8374
return $this;
8475
}
8576

86-
/**
87-
* Get HttpClient.
88-
*
89-
* @return HttpClient
90-
*/
91-
protected function httpClient(): HttpClient
92-
{
93-
return $this->http;
94-
}
95-
9677
/**
9778
* Set HTTP Client.
9879
*
99-
* @param HttpClient $http
100-
*
10180
* @return $this
10281
*/
10382
public function setHttpClient(HttpClient $http): self
@@ -122,13 +101,9 @@ public function setHttpClient(HttpClient $http): self
122101
* ];
123102
* </code>
124103
*
125-
* @link https://core.telegram.org/bots/api#sendmessage
126-
*
127-
* @param array $params
104+
* @see https://core.telegram.org/bots/api#sendmessage
128105
*
129106
* @throws CouldNotSendNotification
130-
*
131-
* @return ResponseInterface|null
132107
*/
133108
public function sendMessage(array $params): ?ResponseInterface
134109
{
@@ -138,13 +113,7 @@ public function sendMessage(array $params): ?ResponseInterface
138113
/**
139114
* Send File as Image or Document.
140115
*
141-
* @param array $params
142-
* @param string $type
143-
* @param bool $multipart
144-
*
145116
* @throws CouldNotSendNotification
146-
*
147-
* @return ResponseInterface|null
148117
*/
149118
public function sendFile(array $params, string $type, bool $multipart = false): ?ResponseInterface
150119
{
@@ -154,11 +123,7 @@ public function sendFile(array $params, string $type, bool $multipart = false):
154123
/**
155124
* Send a Poll.
156125
*
157-
* @param array $params
158-
*
159126
* @throws CouldNotSendNotification
160-
*
161-
* @return ResponseInterface|null
162127
*/
163128
public function sendPoll(array $params): ?ResponseInterface
164129
{
@@ -168,27 +133,25 @@ public function sendPoll(array $params): ?ResponseInterface
168133
/**
169134
* Send a Location.
170135
*
171-
* @param array $params
172-
*
173136
* @throws CouldNotSendNotification
174-
*
175-
* @return ResponseInterface|null
176137
*/
177138
public function sendLocation(array $params): ?ResponseInterface
178139
{
179140
return $this->sendRequest('sendLocation', $params);
180141
}
181142

143+
/**
144+
* Get HttpClient.
145+
*/
146+
protected function httpClient(): HttpClient
147+
{
148+
return $this->http;
149+
}
150+
182151
/**
183152
* Send an API request and return response.
184153
*
185-
* @param string $endpoint
186-
* @param array $params
187-
* @param bool $multipart
188-
*
189154
* @throws CouldNotSendNotification
190-
*
191-
* @return ResponseInterface|null
192155
*/
193156
protected function sendRequest(string $endpoint, array $params, bool $multipart = false): ?ResponseInterface
194157
{

src/TelegramChannel.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace NotificationChannels\Telegram;
44

5-
use Illuminate\Support\Collection;
65
use Illuminate\Contracts\Events\Dispatcher;
76
use Illuminate\Notifications\Events\NotificationFailed;
87
use Illuminate\Notifications\Notification;
@@ -25,9 +24,6 @@ class TelegramChannel
2524

2625
/**
2726
* Channel constructor.
28-
*
29-
* @param Telegram $telegram
30-
* @param Dispatcher $dispatcher
3127
*/
3228
public function __construct(Telegram $telegram, Dispatcher $dispatcher)
3329
{
@@ -38,11 +34,9 @@ public function __construct(Telegram $telegram, Dispatcher $dispatcher)
3834
/**
3935
* Send the given notification.
4036
*
41-
* @param mixed $notifiable
42-
* @param Notification $notification
37+
* @param mixed $notifiable
4338
*
4439
* @throws CouldNotSendNotification
45-
* @return null|array
4640
*/
4741
public function send($notifiable, Notification $notification): ?array
4842
{
@@ -130,11 +124,6 @@ public function send($notifiable, Notification $notification): ?array
130124

131125
/**
132126
* Chunk the given string into an array of strings.
133-
*
134-
* @param string $value
135-
* @param int $limit
136-
*
137-
* @return array
138127
*/
139128
public function chunk(string $value, int $limit = 4096): array
140129
{
@@ -146,7 +135,7 @@ public function chunk(string $value, int $limit = 4096): array
146135
$limit = 4096;
147136
}
148137

149-
$output = explode("%#TGMSG#%", wordwrap($value, $limit, '%#TGMSG#%'));
138+
$output = explode('%#TGMSG#%', wordwrap($value, $limit, '%#TGMSG#%'));
150139

151140
// Fallback for when the string is too long and wordwrap doesn't cut it.
152141
if (count($output) <= 1) {

0 commit comments

Comments
 (0)