Skip to content

Commit 8e7c987

Browse files
authored
Merge pull request #58 from cslant/v2.0
Refactor Event class and improve architecture with caching and logging
2 parents 021e80b + dd53969 commit 8e7c987

34 files changed

Lines changed: 644 additions & 382 deletions

.github/workflows/phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
matrix:
1212
os: [ ubuntu-latest ]
13-
php: [ '8.1', '8.2', '8.3' ]
13+
php: [ '8.4', '8.5' ]
1414

1515
steps:
1616
- uses: actions/checkout@v6

.github/workflows/setup_test.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ jobs:
99
strategy:
1010
matrix:
1111
os: [ ubuntu-latest ]
12-
php: [ '8.1', '8.2', '8.3' ]
13-
laravel: [ 11.*, 10.*, 9.* ]
12+
php: [ '8.4', '8.5' ]
13+
laravel: [ 12.*, 11.* ]
1414
include:
15-
- laravel: 11.*
16-
testbench: 9.*
17-
- laravel: 10.*
18-
testbench: 8.*
19-
exclude:
20-
- laravel: 11.*
21-
php: 8.1
15+
- laravel: 12.*
16+
php: 8.4
17+
- laravel: 12.*
18+
php: 8.5
2219
steps:
2320
- name: Setup PHP
2421
uses: shivammathur/setup-php@v2

.scrutinizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build:
77
override: [ php-scrutinizer-run ]
88
environment:
99
php:
10-
version: 8.2
10+
version: 8.3
1111

1212
checks:
1313
php:

common/helpers.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @return string|null
1212
*/
13-
function tgn_singularity(string $word): string|null
13+
function tgn_singularity(string $word): ?string
1414
{
1515
static $singular_rules = [
1616
'/(quiz)zes$/i' => '$1',
@@ -56,7 +56,7 @@ function tgn_singularity(string $word): string|null
5656
*/
5757
function tgn_snake_case(string $string): string
5858
{
59-
$string = preg_replace('/\s+/', '_', $string);
59+
$string = preg_replace('/\s+/', '_', $string) ?? $string;
6060

6161
return strtolower($string);
6262
}
@@ -100,7 +100,7 @@ function tgn_convert_event_name(string $event): string
100100
*/
101101
function tgn_convert_action_name(string $action): string
102102
{
103-
return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $action));
103+
return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $action) ?? $action);
104104
}
105105
}
106106

@@ -128,28 +128,26 @@ function config(string $string): mixed
128128
*
129129
* @return null|string
130130
*/
131-
function view(string $partialPath, array $data = []): null|string
131+
function view(string $partialPath, array $data = []): ?string
132132
{
133133
$content = (new ConfigHelper())->getTemplateData(
134134
$partialPath,
135135
$data
136136
);
137137

138-
return $content ?: null;
138+
return $content !== '' ? $content : null;
139139
}
140140
}
141141
}
142142

143143
if (!function_exists('tgn_view')) {
144144
/**
145-
* Get view template
145+
* Get view template from the correct source (Laravel Blade or standalone PHP).
146146
*
147-
* @param string $partialPath
148-
* @param array $data
149-
*
150-
* @noinspection PhpMissingReturnTypeInspection
147+
* @param string $partialPath Dot-notation template path
148+
* @param array<string, mixed> $data Variables to pass to the template
151149
*/
152-
function tgn_view(string $partialPath, array $data = [])
150+
function tgn_view(string $partialPath, array $data = []): mixed
153151
{
154152
if (class_exists('Illuminate\Foundation\Application')) {
155153
$partialPath = config('telegram-git-notifier.view.namespace') . '::' . $partialPath;

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"php": "^8.4|^8.5",
4343
"eleirbag89/telegrambotphp": "^1.4",
4444
"guzzlehttp/guzzle": "^7.8",
45+
"psr/log": "^3.0",
4546
"symfony/http-foundation": "^7.0",
4647
"vlucas/phpdotenv": "^5.6"
4748
},

config/jsons/github-events.json

100644100755
File mode changed.

config/jsons/gitlab-events.json

100644100755
File mode changed.

config/jsons/tgn-settings.json

100644100755
File mode changed.

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ parameters:
44
- src
55
- config
66
tmpDir: build/phpstan
7-
checkMissingIterableValueType: false

src/Bot.php

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

33
namespace CSlant\TelegramGitNotifier;
44

5-
use CSlant\TelegramGitNotifier\Constants\EventConstant;
5+
use CSlant\TelegramGitNotifier\Enums\Platform;
66
use CSlant\TelegramGitNotifier\Exceptions\ConfigFileException;
77
use CSlant\TelegramGitNotifier\Interfaces\BotInterface;
88
use CSlant\TelegramGitNotifier\Models\Event;
@@ -39,12 +39,12 @@ class Bot implements BotInterface
3939
* @throws ConfigFileException
4040
*/
4141
public function __construct(
42-
Telegram $telegram = null,
42+
?Telegram $telegram = null,
4343
?string $chatBotId = null,
44-
Event $event = null,
45-
?string $platform = EventConstant::DEFAULT_PLATFORM,
44+
?Event $event = null,
45+
?string $platform = Platform::DEFAULT,
4646
?string $platformFile = null,
47-
Setting $setting = null,
47+
?Setting $setting = null,
4848
?string $settingFile = null,
4949
) {
5050
$this->event = $event ?? new Event();
@@ -61,7 +61,7 @@ public function __construct(
6161

6262
public function validateSettingFile(): void
6363
{
64-
if (empty($this->setting->getSettingFile())) {
64+
if ($this->setting->getSettingFile() === '') {
6565
throw ConfigFileException::settingFile($this->setting->getSettingFile());
6666
}
6767
}

0 commit comments

Comments
 (0)