Skip to content

Commit f4ac33d

Browse files
authored
Merge pull request #16 from amirhshokri/improve-code-styling
Improve readability with line breaks
2 parents f8cf137 + 3892700 commit f4ac33d

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

src/SendJob.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Illuminate\Queue\InteractsWithQueue;
1010
use Illuminate\Queue\SerializesModels;
1111

12-
1312
class SendJob implements ShouldQueue
1413
{
1514
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

src/TelegramBotHandler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,4 @@ protected function send(string $message, $token = null, $chatId = null, $topicId
142142
dispatch(new SendJob($url, $message, $chatId, $topicId, $this->proxy, $this->timeout))->onQueue($this->queue);
143143
}
144144
}
145-
146145
}

src/TelegramFormatter.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ public function __construct($html = true, $format = null, $dateFormat = null, $s
5353
$this->format = $format ?: self::MESSAGE_FORMAT;
5454
$this->dateFormat = $dateFormat ?: self::DATE_FORMAT;
5555
$this->separator = $separator;
56+
5657
if (is_null($tags)) {
5758
$tags = '';
5859
}
60+
5961
$this->tags = explode(',', $tags);
6062
}
6163

@@ -65,18 +67,20 @@ public function __construct($html = true, $format = null, $dateFormat = null, $s
6567
public function format($record)
6668
{
6769
$message = '';
70+
6871
if (isset($record['context']) && isset($record['context']['exception'])) {
6972
$exception = $record['context']['exception'];
73+
7074
try {
7175
$message = $this->getMessageForException($exception);
7276
} catch (\Exception $e) {
7377
//
7478
}
79+
7580
return $message;
7681
}
7782

7883
return $this->getMessageForLog($record);
79-
8084
}
8185

8286
/**
@@ -85,6 +89,7 @@ public function format($record)
8589
public function formatBatch(array $records)
8690
{
8791
$message = '';
92+
8893
foreach ($records as $record) {
8994
if (!empty($message)) {
9095
$message .= str_repeat($this->separator, 15) . "\n";
@@ -100,11 +105,13 @@ protected function getMessageForException($exception)
100105
{
101106
$severity = '';
102107
$request = app('request');
108+
103109
if (method_exists($exception, 'getSeverity')) {
104110
$severity = $this->getSeverityName($exception->getSeverity());
105111
}
106112

107113
$code = $exception->getCode();
114+
108115
if (method_exists($exception, 'getStatusCode')) {
109116
$code = $exception->getStatusCode();
110117
}
@@ -128,7 +135,6 @@ protected function getMessageForException($exception)
128135
// do noting
129136
}
130137

131-
132138
if (!is_null($request->user())) {
133139
$message .= PHP_EOL . '<b>User:</b> ' . $request->user()->id . ' / <b>Name:</b> ' . $request->user()->fullName;
134140
}
@@ -139,6 +145,7 @@ protected function getMessageForException($exception)
139145

140146
if (!empty($request->getMethod())) {
141147
$message .= PHP_EOL . '<b>Request Method:</b> ' . $request->getMethod();
148+
142149
if ($request->ajax()) {
143150
$message .= ' <b>(Ajax)</b> ';
144151
}
@@ -156,6 +163,7 @@ protected function getMessageForException($exception)
156163
protected function getTags()
157164
{
158165
$message = '';
166+
159167
foreach ($this->tags as $tag) {
160168
if (!empty($tag)) {
161169
$message .= '#' . $tag . ' ';
@@ -224,9 +232,11 @@ protected function getSeverityName($key)
224232
8192 => 'DEPRECATED',
225233
16384 => 'USER_DEPRECATED',
226234
];
235+
227236
if (isset($severities[$key])) {
228237
return $severities[$key];
229238
}
239+
230240
return '';
231241
}
232242

@@ -245,6 +255,7 @@ protected function maskSensitiveData($request): array
245255
$data = $request->except($sensitiveFields);
246256

247257
$maskedData = $request->only($sensitiveFields);
258+
248259
foreach ($maskedData as $key => &$value) {
249260
$value = '*';
250261
}

src/TopicDetector.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public function getTopicByAttribute(mixed $record): string|null
4040
return null;
4141
}
4242

43-
4443
// Route Function
4544
private function appRunningWithRequest(): bool
4645
{
@@ -64,12 +63,12 @@ private function getTopicByRoute(): string|null
6463

6564
if ($controller !== null) {
6665
$topicId = $this->getTopicIdByReflection($controller, $method);
66+
6767
if ($topicId === false) {
6868
$topicId = $this->getTopicIdByRegex($controller, $method);
6969
}
7070
}
7171

72-
7372
return $topicId;
7473
}
7574

@@ -79,6 +78,7 @@ private function appRunningWithJob(): bool
7978
if (isset($e->job) || app()->bound('queue.worker')) {
8079
return true;
8180
}
81+
8282
return false;
8383
}
8484

@@ -101,12 +101,15 @@ private function getTopicIdByJob(): string|int|null
101101
{
102102
$topicId = null;
103103
$jobClass = $this->getJobClass();
104+
104105
if ($jobClass !== null) {
105106
$topicId = $this->getTopicIdByReflection($jobClass, 'handle');
107+
106108
if ($topicId === false) {
107109
$topicId = $this->getTopicIdByRegex($jobClass, 'handle');
108110
}
109111
}
112+
110113
return $topicId;
111114
}
112115

@@ -122,6 +125,7 @@ private function getCommandClass(): string|null
122125

123126
if (str_contains($filePath, 'Console\Commands')) {
124127
$appPosition = strpos($filePath, 'app');
128+
125129
if ($appPosition !== false) {
126130
$appPath = substr($filePath, $appPosition);
127131
return str_replace(['/', 'app', '.php'], ['\\', 'App', ''], $appPath);
@@ -141,12 +145,15 @@ private function getTopicIdByCommand(): string|int|null
141145
{
142146
$topicId = null;
143147
$commandClass = $this->getCommandClass();
148+
144149
if ($commandClass !== null) {
145150
$topicId = $this->getTopicIdByReflection($commandClass, 'handle');
151+
146152
if ($topicId === false) {
147153
$topicId = $this->getTopicIdByRegex($commandClass, 'handle');
148154
}
149155
}
156+
150157
return $topicId;
151158
}
152159

@@ -167,25 +174,27 @@ private function getTopicIdByReflection(string $class, string $method): string|i
167174
} catch (\Throwable $e) {
168175

169176
}
177+
170178
return false;
171179
}
172180

173181
private function getTopicIdByRegex(string $class, string $method): string|int|null
174182
{
175183
try {
176-
177184
$filePath = base_path(str_replace('App', 'app', $class) . '.php');
178185
$fileContent = file_get_contents($filePath);
179186
$allAttributes = [];
180187

181188
// Regex to match attributes and methods
182189
$regex = '/\#\[\s*(.*?)\s*\]\s*public\s*function\s*(\w+)/';
190+
183191
if (preg_match_all($regex, $fileContent, $matches, PREG_SET_ORDER)) {
184192
foreach ($matches as $match) {
185193
$attributeString = $match[1];
186194
$methodName = $match[2];
187195

188196
$attributes = array_map('trim', explode(',', $attributeString));
197+
189198
foreach ($attributes as $attribute) {
190199
$attributeName = preg_replace('/\(.*/', '', $attribute);
191200
$allAttributes[$methodName][] = $attributeName;
@@ -207,6 +216,7 @@ private function getTopicIdByRegex(string $class, string $method): string|int|nu
207216

208217
} catch (\Throwable $e) {
209218
}
219+
210220
return null;
211221
}
212222

@@ -238,14 +248,11 @@ protected function getMainLivewireClass(): array
238248
if (!empty($rootNamespace)) {
239249
$class = '\\' . $rootNamespace . '\\' . $class;
240250
}
241-
242251
}
243252
} catch (\Throwable $exception) {
244253
//report($exception);
245254
}
246255

247256
return [$class, $method];
248-
249257
}
250-
251258
}

0 commit comments

Comments
 (0)