Skip to content

Commit

Permalink
Merge pull request #23 from tanhongit/main
Browse files Browse the repository at this point in the history
Add php cs fixer
  • Loading branch information
tanhongit authored Oct 31, 2023
2 parents 3dfb033 + 1af54f4 commit f6ff777
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 24 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Check & fix styling

on: [push]

jobs:
php-cs-fixer:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
uses: ramsey/composer-install@v2

- name: Run PHPStan
run: vendor/bin/phpstan --error-format=github
run: composer analyse --error-format=github
9 changes: 8 additions & 1 deletion .github/workflows/setup_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ jobs:
tests:
name: Composer setup and tests
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '8.1', '8.2' ]
laravel: [ 10.*, 9.* ]
include:
- laravel: 10.*
testbench: 8.*
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: ${{ matrix.php }}
- name: Checkout code
uses: actions/checkout@v3
- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ package-lock.json
yarn.lock

build
.php-cs-fixer.cache
38 changes: 38 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method' => 'one',
],
],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"common/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"LbilTech\\TelegramGitNotifier\\Tests\\": "tests"
}
},
"require": {
"php": "^8.1",
"eleirbag89/telegrambotphp": "^1.4",
Expand All @@ -41,10 +46,12 @@
"vlucas/phpdotenv": "^5.5"
},
"require-dev": {
"phpstan/phpstan": "^1.10.39"
"phpstan/phpstan": "^1.10.39",
"friendsofphp/php-cs-fixer": "^v3.37.1"
},
"scripts": {
"analyse": "vendor/bin/phpstan"
"analyse": "vendor/bin/phpstan",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
},
"support": {
"issues": "https://github.com/lbiltech/telegram-git-notifier/issues"
Expand Down
2 changes: 1 addition & 1 deletion src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use LbilTech\TelegramGitNotifier\Constants\EventConstant;
use LbilTech\TelegramGitNotifier\Interfaces\BotInterface;
use LbilTech\TelegramGitNotifier\Interfaces\EventInterface;
use LbilTech\TelegramGitNotifier\Interfaces\SettingInterface;
use LbilTech\TelegramGitNotifier\Interfaces\Structures\AppInterface;
use LbilTech\TelegramGitNotifier\Interfaces\EventInterface;
use LbilTech\TelegramGitNotifier\Models\Event;
use LbilTech\TelegramGitNotifier\Models\Setting;
use LbilTech\TelegramGitNotifier\Structures\App;
Expand Down
2 changes: 2 additions & 0 deletions src/Helpers/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function execConfig(string $string): mixed

$result = $result[$value];
}

return $result;
}

Expand All @@ -58,6 +59,7 @@ public function getTemplateData(string $partialPath, array $data = []): bool|str

$content = '';
ob_start();

try {
extract($data, EXTR_SKIP);
require_once $viewPathFile;
Expand Down
1 change: 1 addition & 0 deletions src/Interfaces/SettingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function getEndKeyboard(string $platform, ?string $parentEvent = null): a
* @see EventSettingTrait::eventHandle()
*/
public function eventHandle(?string $callback = null, ?string $platform = null, string $platformFile = null): void;

/**
* Get the platform from callback
*
Expand Down
3 changes: 2 additions & 1 deletion src/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use GuzzleHttp\Client;
use LbilTech\TelegramGitNotifier\Constants\EventConstant;
use LbilTech\TelegramGitNotifier\Constants\NotificationConstant;
use LbilTech\TelegramGitNotifier\Interfaces\Structures\AppInterface;
use LbilTech\TelegramGitNotifier\Interfaces\EventInterface;
use LbilTech\TelegramGitNotifier\Interfaces\Structures\AppInterface;
use LbilTech\TelegramGitNotifier\Interfaces\Structures\NotificationInterface;
use LbilTech\TelegramGitNotifier\Models\Event;
use LbilTech\TelegramGitNotifier\Structures\App;
Expand Down Expand Up @@ -56,6 +56,7 @@ public function parseNotifyChatIds(): array
? explode(NotificationConstant::THREAD_ID_SEPARATOR, $threadIds)
: [];
}

return $chatThreadMapping;
}
}
17 changes: 9 additions & 8 deletions src/Structures/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public function setCurrentChatBotId(string $chatBotId = null): void
private function createTelegramBaseContent(): array
{
return [
'chat_id' => $this->chatBotId,
'chat_id' => $this->chatBotId,
'disable_web_page_preview' => true,
'parse_mode' => 'HTML'
'parse_mode' => 'HTML',
];
}

Expand Down Expand Up @@ -71,8 +71,8 @@ public function answerCallbackQuery(string $text = null, array $options = []): v
try {
$options = array_merge([
'callback_query_id' => $this->telegram->Callback_ID(),
'text' => $text,
'show_alert' => true
'text' => $text,
'show_alert' => true,
], $options);
$this->telegram->answerCallbackQuery($options);
} catch (Exception $e) {
Expand All @@ -86,7 +86,7 @@ public function editMessageText(
): void {
try {
$content = array_merge([
'text' => $text ?? $this->getCallbackTextMessage()
'text' => $text ?? $this->getCallbackTextMessage(),
], $this->setCallbackContentMessage($options));

$this->telegram->editMessageText($content);
Expand Down Expand Up @@ -114,10 +114,10 @@ public function getCallbackTextMessage(): string
public function setCallbackContentMessage(array $options = []): array
{
$content = [
'chat_id' => $this->telegram->Callback_ChatID(),
'message_id' => $this->telegram->MessageID(),
'chat_id' => $this->telegram->Callback_ChatID(),
'message_id' => $this->telegram->MessageID(),
'disable_web_page_preview' => true,
'parse_mode' => 'HTML',
'parse_mode' => 'HTML',
];

$content['reply_markup'] = $options['reply_markup']
Expand All @@ -135,6 +135,7 @@ public function getBotName(): ?string
public function getCommandMessage(): string
{
$text = $this->telegram->Text();

return str_replace('@' . $this->getBotName(), '', $text);
}
}
10 changes: 5 additions & 5 deletions src/Structures/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public function accessDenied(
string $viewTemplate = null,
): void {
$this->telegram->sendMessage([
'chat_id' => $this->chatBotId,
'text' => view(
'chat_id' => $this->chatBotId,
'text' => view(
$viewTemplate ?? config('telegram-git-notifier.view.globals.access_denied'),
['chatId' => $chatId]
),
'disable_web_page_preview' => true,
'parse_mode' => 'HTML'
'parse_mode' => 'HTML',
]);
}

Expand Down Expand Up @@ -67,7 +67,7 @@ private function setMessage(string $typeEvent): void

$viewResult = view($viewTemplate, [
'payload' => $this->payload,
'event' => tgn_convert_event_name($typeEvent),
'event' => tgn_convert_event_name($typeEvent),
]);

if ($viewResult === null) {
Expand All @@ -87,7 +87,7 @@ public function sendNotify(string $message = null, array $options = []): bool

try {
$response = $this->client->request('POST', $url, [
'form_params' => $queryParams
'form_params' => $queryParams,
]);

if ($response->getStatusCode() === 200) {
Expand Down
4 changes: 2 additions & 2 deletions src/Trait/BotSettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function setMyCommands(
?string $view = null
): void {
$this->telegram->setMyCommands([
'commands' => json_encode($menuCommand)
'commands' => json_encode($menuCommand),
]);
$this->sendMessage(
view(
Expand Down Expand Up @@ -59,7 +59,7 @@ public function settingMarkup(): array
'',
SettingConstant::SETTING_ALL_EVENTS_NOTIFY
),
]
],
];

$markup = $this->customEventMarkup($markup);
Expand Down
6 changes: 4 additions & 2 deletions src/Trait/EventSettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getEndKeyboard(
'📚 Menu',
'',
SettingConstant::SETTING_BACK_TO_MAIN_MENU
)
),
];
}

Expand Down Expand Up @@ -149,6 +149,7 @@ public function sendSettingEventMessage(
),
['reply_markup' => $this->eventMarkup(null, $platform)]
);

return true;
}

Expand All @@ -164,7 +165,7 @@ public function getEventFromCallback(?string $callback): string
return str_replace([
EventConstant::EVENT_PREFIX,
EventConstant::GITHUB_EVENT_SEPARATOR,
EventConstant::GITLAB_EVENT_SEPARATOR
EventConstant::GITLAB_EVENT_SEPARATOR,
], '', $callback);
}

Expand All @@ -186,6 +187,7 @@ public function handleEventWithActions(
),
['reply_markup' => $this->eventMarkup($event, $platform)]
);

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Trait/EventTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace LbilTech\TelegramGitNotifier\Trait;

use Symfony\Component\HttpFoundation\Request;
use LbilTech\TelegramGitNotifier\Constants\EventConstant;
use Symfony\Component\HttpFoundation\Request;

trait EventTrait
{
Expand Down
Empty file.

0 comments on commit f6ff777

Please sign in to comment.