Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
[ci skip] [skip ci]
  • Loading branch information
melihovv authored and StyleCIBot committed Mar 7, 2020
1 parent 13133a7 commit 779177b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 52 deletions.
12 changes: 6 additions & 6 deletions src/LogViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function getLogsFromCurrentFile()

preg_match_all($pattern, $fileContent, $rows);

if (!is_array($rows) || count($rows) === 0) {
if (! is_array($rows) || count($rows) === 0) {
return [];
}

Expand All @@ -100,12 +100,12 @@ public function getLogsFromCurrentFile()
foreach ($rows as $row) {
preg_match(
"/^\\[($datePattern)\\].*?(\\w+)\\."
. '([A-Z]+): (.*?)( in .*?:[0-9]+)?$/',
.'([A-Z]+): (.*?)( in .*?:[0-9]+)?$/',
$row,
$matches
);

if (!isset($matches[4])) {
if (! isset($matches[4])) {
continue;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ public function getLogsFromCurrentFile()
*/
public function getCurrentDirectoryContent()
{
$content = File::glob($this->currentDir . DIRECTORY_SEPARATOR . '*');
$content = File::glob($this->currentDir.DIRECTORY_SEPARATOR.'*');

$content = array_map(function ($item) {
return (object) [
Expand Down Expand Up @@ -267,7 +267,7 @@ public function setCurrentFile($file)
*/
protected function checkIfPathInBaseDir($path)
{
if (!Str::startsWith($path, $this->baseDir)) {
if (! Str::startsWith($path, $this->baseDir)) {
throw new InvalidArgumentException(
"Passed directory is not in base directory $this->baseDir"
);
Expand Down Expand Up @@ -305,7 +305,7 @@ public function getRelativePathToCurrentDirectoryParent()
return DIRECTORY_SEPARATOR;
}

$path = realpath($this->currentDir . DIRECTORY_SEPARATOR . '..');
$path = realpath($this->currentDir.DIRECTORY_SEPARATOR.'..');

return $this->getPathRelativeToBaseDir($path) ?: DIRECTORY_SEPARATOR;
}
Expand Down
7 changes: 3 additions & 4 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
const CONFIG_PATH = __DIR__ . '/../config/log-viewer.php';
const CONFIG_PATH = __DIR__.'/../config/log-viewer.php';

const VIEWS_PATH = __DIR__ . '/../views';
const VIEWS_PATH = __DIR__.'/../views';

public function boot()
{
Expand All @@ -19,8 +19,7 @@ public function boot()
], 'config');

$this->publishes([
self::VIEWS_PATH =>
resource_path('views/vendor/log-viewer'),
self::VIEWS_PATH => resource_path('views/vendor/log-viewer'),
], 'views');
}

Expand Down
18 changes: 9 additions & 9 deletions tests/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function tearDown(): void
}

/** @test */
function it_shows_logs_page_when_there_are_no_log_files()
public function it_shows_logs_page_when_there_are_no_log_files()
{
$this->visit('/logs')
->assertResponseOk()
Expand All @@ -62,7 +62,7 @@ function it_shows_logs_page_when_there_are_no_log_files()
}

/** @test */
function it_shows_logs_page_when_there_are_log_files()
public function it_shows_logs_page_when_there_are_log_files()
{
File::put($this->getBaseDir().'/laravel.log', '
[2017-01-04 05:22:25] production.ERROR: hello1 in Main.php:48
Expand All @@ -84,7 +84,7 @@ function it_shows_logs_page_when_there_are_log_files()
}

/** @test */
function it_shows_logs_page_with_selected_log_file()
public function it_shows_logs_page_with_selected_log_file()
{
File::put($this->getBaseDir().'/laravel.log', '
[2017-01-04 05:22:24] testing.INFO: hello1 in Main.php:48
Expand All @@ -110,7 +110,7 @@ function it_shows_logs_page_with_selected_log_file()
}

/** @test */
function it_shows_logs_page_inside_specified_directory()
public function it_shows_logs_page_inside_specified_directory()
{
File::put($this->getBaseDir().'/laravel.log', '
[2017-01-04 05:22:24] testing.INFO: hello1 in Main.php:48
Expand All @@ -132,7 +132,7 @@ function it_shows_logs_page_inside_specified_directory()
}

/** @test */
function it_shows_logs_page_with_selected_log_file_inside_specified_directory()
public function it_shows_logs_page_with_selected_log_file_inside_specified_directory()
{
File::put($this->getBaseDir().'/laravel.log', '
[2017-01-04 05:22:24] testing.INFO: hello1 in Main.php:48
Expand All @@ -159,7 +159,7 @@ function it_shows_logs_page_with_selected_log_file_inside_specified_directory()
}

/** @test */
function it_deletes_specified_file()
public function it_deletes_specified_file()
{
File::makeDirectory($this->getBaseDir().'/directory1');
File::put($this->getBaseDir().'/directory1/laravel3.log', '');
Expand All @@ -172,7 +172,7 @@ function it_deletes_specified_file()
}

/** @test */
function it_downloads_specified_file()
public function it_downloads_specified_file()
{
File::makeDirectory($this->getBaseDir().'/directory1');
File::put($this->getBaseDir().'/directory1/laravel3.log', '');
Expand All @@ -196,7 +196,7 @@ private function rawRequest($method, $uri, $parameters = [], $cookies = [], $fil
}

/** @test */
function it_does_not_show_file_which_exceed_size_limit_in_config()
public function it_does_not_show_file_which_exceed_size_limit_in_config()
{
$this->app['config']->set('log-viewer.max_file_size', 10);
File::put($this->getBaseDir().'/laravel3.log', str_repeat('A', 11));
Expand All @@ -209,7 +209,7 @@ function it_does_not_show_file_which_exceed_size_limit_in_config()
}

/** @test */
function it_does_not_show_files_outside_base_directory()
public function it_does_not_show_files_outside_base_directory()
{
File::put($this->getBaseDir().'/../some-secret-file', 'SECRET!!!');

Expand Down
66 changes: 33 additions & 33 deletions tests/LogViewerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ protected function getEnvironmentSetUp($app)

private function getBaseDir(): string
{
return __DIR__ . DIRECTORY_SEPARATOR . 'logs';
return __DIR__.DIRECTORY_SEPARATOR.'logs';
}

protected function setUp() : void
protected function setUp(): void
{
parent::setUp();

File::makeDirectory($this->getBaseDir());
}

protected function tearDown() : void
protected function tearDown(): void
{
parent::tearDown();

Expand All @@ -58,7 +58,7 @@ public function get_logs_from_current_file(
callable $setupCb,
callable $assertCb
) {
File::put($this->getBaseDir() . '/laravel.log', '');
File::put($this->getBaseDir().'/laravel.log', '');

$setupCb($this);

Expand Down Expand Up @@ -93,7 +93,7 @@ function ($testcase, $logs) {
'success' => [
function ($testcase) {
LogViewerFacade::setCurrentFile('/laravel.log');
\File::append($this->getBaseDir() . '/laravel.log', <<<'HERE'
\File::append($this->getBaseDir().'/laravel.log', <<<'HERE'
[2017-01-04 05:21:25] local.INFO: hi
not match
[2017-01-04 05:22:25] production.ERROR: ho in Main.php:48
Expand Down Expand Up @@ -153,25 +153,25 @@ function () {
],
'dir with files and subdir' => [
function () {
\File::put($this->getBaseDir() . '/log1.txt', '');
\File::put($this->getBaseDir() . '/log2.txt', '');
\File::makeDirectory($this->getBaseDir() . '/subfolder');
\File::put($this->getBaseDir().'/log1.txt', '');
\File::put($this->getBaseDir().'/log2.txt', '');
\File::makeDirectory($this->getBaseDir().'/subfolder');
},
[
(object) [
'path' => DIRECTORY_SEPARATOR . 'log1.txt',
'path' => DIRECTORY_SEPARATOR.'log1.txt',
'name' => 'log1.txt',
'isFile' => true,
'isDir' => false,
],
(object) [
'path' => DIRECTORY_SEPARATOR . 'log2.txt',
'path' => DIRECTORY_SEPARATOR.'log2.txt',
'name' => 'log2.txt',
'isFile' => true,
'isDir' => false,
],
(object) [
'path' => DIRECTORY_SEPARATOR . 'subfolder',
'path' => DIRECTORY_SEPARATOR.'subfolder',
'name' => 'subfolder',
'isFile' => false,
'isDir' => true,
Expand Down Expand Up @@ -205,19 +205,19 @@ public function setCurrentDirectoryProvider()
return [
'success' => [
function ($testcase) {
\File::makeDirectory($this->getBaseDir() . '/subfolder');
\File::makeDirectory($this->getBaseDir().'/subfolder');
},
'/subfolder',
function ($testcase) {
$testcase->assertEquals(
$this->getBaseDir() . DIRECTORY_SEPARATOR . 'subfolder',
$this->getBaseDir().DIRECTORY_SEPARATOR.'subfolder',
LogViewerFacade::getCurrentDirectory()
);
},
],
'directory is not inside base directory' => [
function ($testcase) {
$baseDir = $this->getBaseDir() . DIRECTORY_SEPARATOR . 'newBaseDir';
$baseDir = $this->getBaseDir().DIRECTORY_SEPARATOR.'newBaseDir';
\File::makeDirectory($baseDir);
LogViewerFacade::setBaseDirectory($baseDir);

Expand Down Expand Up @@ -261,12 +261,12 @@ public function setCurrentFileProvider()
return [
'success' => [
function ($testcase) {
File::put($this->getBaseDir() . '/log.txt', '');
File::put($this->getBaseDir().'/log.txt', '');
},
'/log.txt',
function ($testcase) {
$testcase->assertEquals(
$this->getBaseDir() . DIRECTORY_SEPARATOR . 'log.txt',
$this->getBaseDir().DIRECTORY_SEPARATOR.'log.txt',
LogViewerFacade::getCurrentFile()
);
$testcase->assertEquals(
Expand All @@ -277,25 +277,25 @@ function ($testcase) {
],
'current directory must be directory of current file' => [
function ($testcase) {
File::makeDirectory($this->getBaseDir() . '/subfolder');
File::put($this->getBaseDir() . '/subfolder/log.txt', '');
File::makeDirectory($this->getBaseDir().'/subfolder');
File::put($this->getBaseDir().'/subfolder/log.txt', '');
},
'/subfolder/log.txt',
function ($testcase) {
$testcase->assertEquals(
$this->getBaseDir() . DIRECTORY_SEPARATOR . 'subfolder'
. DIRECTORY_SEPARATOR . 'log.txt',
$this->getBaseDir().DIRECTORY_SEPARATOR.'subfolder'
.DIRECTORY_SEPARATOR.'log.txt',
LogViewerFacade::getCurrentFile()
);
$testcase->assertEquals(
$this->getBaseDir() . DIRECTORY_SEPARATOR . 'subfolder',
$this->getBaseDir().DIRECTORY_SEPARATOR.'subfolder',
LogViewerFacade::getCurrentDirectory()
);
},
],
'file is not inside base directory' => [
function ($testcase) {
$baseDir = $this->getBaseDir() . DIRECTORY_SEPARATOR . 'newBaseDir';
$baseDir = $this->getBaseDir().DIRECTORY_SEPARATOR.'newBaseDir';
File::makeDirectory($baseDir);
LogViewerFacade::setBaseDirectory($baseDir);

Expand All @@ -321,21 +321,21 @@ function ($testcase) {
/** @test */
public function get_current_file_relative_to_base_dir()
{
File::put($this->getBaseDir() . '/laravel.log', '');
File::put($this->getBaseDir().'/laravel.log', '');
LogViewerFacade::setCurrentFile('/laravel.log');
$this->assertEquals(
DIRECTORY_SEPARATOR . 'laravel.log',
DIRECTORY_SEPARATOR.'laravel.log',
LogViewerFacade::getCurrentFileRelativeToBaseDir()
);
}

/** @test */
public function get_current_directory_relative_to_base_dir()
{
File::makeDirectory($this->getBaseDir() . '/subdir');
File::makeDirectory($this->getBaseDir().'/subdir');
LogViewerFacade::setCurrentDirectory('/subdir');
$this->assertEquals(
DIRECTORY_SEPARATOR . 'subdir',
DIRECTORY_SEPARATOR.'subdir',
LogViewerFacade::getCurrentDirectoryRelativeToBaseDir()
);
}
Expand Down Expand Up @@ -365,7 +365,7 @@ function ($testcase) {
],
'cur dir does not equals base dir: subdir' => [
function ($testcase) {
File::makeDirectory($this->getBaseDir() . '/subdir');
File::makeDirectory($this->getBaseDir().'/subdir');
LogViewerFacade::setCurrentDirectory('/subdir');

$testcase->assertEquals(
Expand All @@ -376,11 +376,11 @@ function ($testcase) {
],
'cur dir does not equals base dir: subsubdir' => [
function ($testcase) {
File::makeDirectory($this->getBaseDir() . '/subdir/subsubdir', 0755, true);
File::makeDirectory($this->getBaseDir().'/subdir/subsubdir', 0755, true);
LogViewerFacade::setCurrentDirectory('/subdir/subsubdir');

$testcase->assertEquals(
DIRECTORY_SEPARATOR . 'subdir',
DIRECTORY_SEPARATOR.'subdir',
LogViewerFacade::getRelativePathToCurrentDirectoryParent()
);
},
Expand Down Expand Up @@ -409,7 +409,7 @@ function ($testcase) {
],
'false' => [
function ($testcase) {
File::makeDirectory($this->getBaseDir() . '/subdir');
File::makeDirectory($this->getBaseDir().'/subdir');
LogViewerFacade::setCurrentDirectory('/subdir');

$testcase->assertFalse(LogViewerFacade::isCurrentDirectoryBase());
Expand Down Expand Up @@ -448,7 +448,7 @@ function ($testcase, $dirs) {
],
'current directory is one level down of base directory' => [
function ($testcase) {
File::makeDirectory($this->getBaseDir() . '/subdir');
File::makeDirectory($this->getBaseDir().'/subdir');
LogViewerFacade::setCurrentDirectory('/subdir');
},
function ($testcase, $dirs) {
Expand All @@ -459,13 +459,13 @@ function ($testcase, $dirs) {
],
'current directory is two level down of base directory' => [
function ($testcase) {
File::makeDirectory($this->getBaseDir() . '/subdir/subsubdir', 0755, true);
File::makeDirectory($this->getBaseDir().'/subdir/subsubdir', 0755, true);
LogViewerFacade::setCurrentDirectory('/subdir/subsubdir');
},
function ($testcase, $dirs) {
$testcase->assertEquals([
DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR . 'subdir',
DIRECTORY_SEPARATOR.'subdir',
], $dirs);
},
],
Expand Down

0 comments on commit 779177b

Please sign in to comment.