Skip to content

Commit 6442214

Browse files
authored
Merge pull request #1 from laravel-admin-extensions/analysis-87QeMj
Apply fixes from StyleCI
2 parents 33a159a + 6005f4f commit 6442214

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

src/BootExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ public static function import()
4040

4141
parent::createPermission('Logs', 'ext.log-viewer', 'logs*');
4242
}
43-
}
43+
}

src/LogController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99

1010
class LogController extends Controller
1111
{
12-
public function index($file = null, Request $request)
12+
public function index($file, Request $request)
1313
{
1414
return Admin::content(function (Content $content) use ($file, $request) {
15-
1615
$offset = $request->get('offset');
1716

1817
$viewer = new LogViewer($file);
@@ -26,11 +25,10 @@ public function index($file = null, Request $request)
2625
'prevUrl' => $viewer->getPrevPageUrl(),
2726
'nextUrl' => $viewer->getNextPageUrl(),
2827
'filePath' => $viewer->getFilePath(),
29-
'size' => static::bytesToHuman($viewer->getFilesize())
28+
'size' => static::bytesToHuman($viewer->getFilesize()),
3029
]));
3130

3231
$content->header($viewer->getFilePath());
33-
3432
});
3533
}
3634

@@ -53,6 +51,6 @@ protected static function bytesToHuman($bytes)
5351
$bytes /= 1024;
5452
}
5553

56-
return round($bytes, 2) . ' ' . $units[$i];
54+
return round($bytes, 2).' '.$units[$i];
5755
}
58-
}
56+
}

src/LogViewer.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use Encore\Admin\Extension;
66

77
/**
8-
* Class LogViewer
9-
* @package Encore\Admin\LogViewer
8+
* Class LogViewer.
109
*/
1110
class LogViewer extends Extension
1211
{
@@ -66,16 +65,16 @@ public function __construct($file = null)
6665
/**
6766
* Get file path by giving log file name.
6867
*
69-
* @return string
70-
*
7168
* @throws \Exception
69+
*
70+
* @return string
7271
*/
7372
public function getFilePath()
7473
{
7574
if (!$this->filePath) {
7675
$path = sprintf(storage_path('logs/%s'), $this->file);
7776

78-
if (! file_exists($path)) {
77+
if (!file_exists($path)) {
7978
throw new \Exception('log not exists!');
8079
}
8180

@@ -105,7 +104,7 @@ public function getFilesize()
105104
public function getLogFiles($count = 20)
106105
{
107106
$files = glob(storage_path('logs/*'));
108-
$files = array_combine($files, array_map("filemtime", $files));
107+
$files = array_combine($files, array_map('filemtime', $files));
109108
arsort($files);
110109

111110
$files = array_map('basename', array_keys($files));
@@ -163,21 +162,24 @@ public function getNextPageUrl()
163162
* @param int $seek
164163
* @param int $lines
165164
* @param int $buffer
165+
*
166166
* @return array
167167
*
168168
* @see http://www.geekality.net/2011/05/28/php-tail-tackling-large-files/
169169
*/
170170
public function fetch($seek = 0, $lines = 20, $buffer = 4096)
171171
{
172-
$f = fopen($this->filePath, "rb");
172+
$f = fopen($this->filePath, 'rb');
173173

174174
if ($seek) {
175175
fseek($f, abs($seek));
176176
} else {
177177
fseek($f, 0, SEEK_END);
178178
}
179179

180-
if(fread($f, 1) != "\n") $lines -= 1;
180+
if (fread($f, 1) != "\n") {
181+
$lines -= 1;
182+
}
181183
fseek($f, -1, SEEK_CUR);
182184

183185
// 从前往后读,上一页
@@ -187,28 +189,27 @@ public function fetch($seek = 0, $lines = 20, $buffer = 4096)
187189

188190
$this->pageOffset['start'] = ftell($f);
189191

190-
while(!feof($f) && $lines >= 0) {
192+
while (!feof($f) && $lines >= 0) {
191193
$output = $output.($chunk = fread($f, $buffer));
192194
$lines -= substr_count($chunk, "\n[20");
193195
}
194196

195197
$this->pageOffset['end'] = ftell($f);
196198

197-
while($lines++ < 0) {
198-
$strpos = strrpos($output, "\n[20")+1;
199+
while ($lines++ < 0) {
200+
$strpos = strrpos($output, "\n[20") + 1;
199201
$_ = mb_strlen($output, '8bit') - $strpos;
200202
$output = substr($output, 0, $strpos);
201203
$this->pageOffset['end'] -= $_;
202204
}
203205

204-
// 从后往前读,下一页
206+
// 从后往前读,下一页
205207
} else {
206-
207208
$output = '';
208209

209210
$this->pageOffset['end'] = ftell($f);
210211

211-
while(ftell($f) > 0 && $lines >= 0) {
212+
while (ftell($f) > 0 && $lines >= 0) {
212213
$offset = min(ftell($f), $buffer);
213214
fseek($f, -$offset, SEEK_CUR);
214215
$output = ($chunk = fread($f, $offset)).$output;
@@ -218,7 +219,7 @@ public function fetch($seek = 0, $lines = 20, $buffer = 4096)
218219

219220
$this->pageOffset['start'] = ftell($f);
220221

221-
while($lines++ < 0) {
222+
while ($lines++ < 0) {
222223
$strpos = strpos($output, "\n[20") + 1;
223224
$output = substr($output, $strpos);
224225
$this->pageOffset['start'] += $strpos;
@@ -233,14 +234,14 @@ public function fetch($seek = 0, $lines = 20, $buffer = 4096)
233234
/**
234235
* Get tail logs in log file.
235236
*
236-
* @param integer $seek
237+
* @param int $seek
237238
*
238239
* @return array
239240
*/
240241
public function tail($seek)
241242
{
242243
// Open the file
243-
$f = fopen($this->filePath, "rb");
244+
$f = fopen($this->filePath, 'rb');
244245

245246
if (!$seek) {
246247
// Jump to last character
@@ -272,11 +273,12 @@ public function tail($seek)
272273
* Render table row.
273274
*
274275
* @param $log
276+
*
275277
* @return string
276278
*/
277279
protected function renderTableRow($log)
278280
{
279-
$color = LogViewer::$levelColors[$log['level']] ?? 'black';
281+
$color = self::$levelColors[$log['level']] ?? 'black';
280282

281283
$index = uniqid();
282284

@@ -304,13 +306,13 @@ protected function renderTableRow($log)
304306
</tr>
305307
$trace
306308
TPL;
307-
308309
}
309310

310311
/**
311312
* Parse raw log text to array.
312313
*
313314
* @param $raw
315+
*
314316
* @return array
315317
*/
316318
protected function parseLog($raw)

src/LogViewerServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ public function boot()
1212

1313
LogViewer::boot();
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)