From 332897e31681dd5232a80cb42a1a8f2c437d193c Mon Sep 17 00:00:00 2001 From: Roberson Faria Date: Tue, 23 Nov 2021 14:52:14 -0300 Subject: [PATCH] fix phpcs --- composer.json | 7 ++- composer.lock | 58 ++++++++++++++++++++- routes/web.php | 3 +- src/Console/Scheduling/Schedule.php | 3 +- src/Http/Controllers/ScheduleController.php | 30 +++++------ src/Http/Middleware/Authenticate.php | 2 +- src/Http/Services/CommandService.php | 5 +- src/Models/Schedule.php | 11 ++-- src/View/Helpers.php | 5 +- tests/Unit/PhpUnitDatabaseTest.php | 1 - tests/Unit/ScheduleCommandsTest.php | 7 ++- 11 files changed, 94 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index c8f4946..6728ede 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ }, "require-dev": { "phpunit/phpunit": "^8.5", - "orchestra/testbench": "^5.20" + "orchestra/testbench": "^5.20", + "squizlabs/php_codesniffer": "^3.6" }, "authors": [ { @@ -34,6 +35,10 @@ ] } }, + "scripts": { + "phpcs": "./vendor/bin/phpcs .", + "tests": "./vendor/bin/phpunit ./tests" + }, "minimum-stability": "dev", "prefer-stable": true } diff --git a/composer.lock b/composer.lock index 9d9e584..ea3df44 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d8265e01bce658f399c4564db68c2b1b", + "content-hash": "c18a85355a62cfd054dc49e8d602b371", "packages": [ { "name": "brick/math", @@ -5867,6 +5867,62 @@ }, "time": "2016-10-03T07:35:21+00:00" }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.6.1", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "f268ca40d54617c6e06757f83f699775c9b3ff2e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/f268ca40d54617c6e06757f83f699775c9b3ff2e", + "reference": "f268ca40d54617c6e06757f83f699775c9b3ff2e", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2021-10-11T04:00:11+00:00" + }, { "name": "symfony/yaml", "version": "v5.3.11", diff --git a/routes/web.php b/routes/web.php index a67fb93..b07dd02 100644 --- a/routes/web.php +++ b/routes/web.php @@ -5,7 +5,7 @@ Route::post('/{schedule}/status/{status}', 'ScheduleController@status') ->name(config('database-schedule.route.name', 'database-schedule') . '.status'); -Route::get('/', function() { +Route::get('/', function () { return redirect()->route(config('database-schedule.route.name', 'database-schedule') . '.index'); }); @@ -36,4 +36,3 @@ $schedule = app(config('database-schedule.model')); return $schedule::onlyTrashed()->find($id); }); - diff --git a/src/Console/Scheduling/Schedule.php b/src/Console/Scheduling/Schedule.php index 99833a2..9cec433 100644 --- a/src/Console/Scheduling/Schedule.php +++ b/src/Console/Scheduling/Schedule.php @@ -1,5 +1,4 @@ storeOutput(); - if($task->environments) { + if ($task->environments) { $event->environments(explode(',', $task->environments)); } diff --git a/src/Http/Controllers/ScheduleController.php b/src/Http/Controllers/ScheduleController.php index e2eb991..903b5ca 100644 --- a/src/Http/Controllers/ScheduleController.php +++ b/src/Http/Controllers/ScheduleController.php @@ -19,14 +19,14 @@ public function index() $schedule = app(config('database-schedule.model')); $schedules = $schedule::query(); - $orderBy = request()->input('orderBy') - ?? session()->get(Schedule::SESSION_KEY_ORDER_BY) - ?? config('database-schedule.default_ordering', 'created_at'); - $direction = request()->input('direction') - ?? session()->get(Schedule::SESSION_KEY_DIRECTION) - ?? config('database-schedule.default_ordering_direction', 'DESC'); - - session()->put(Schedule::SESSION_KEY_ORDER_BY, $orderBy); + $orderBy = request()->input('orderBy') + ?? session()->get(Schedule::SESSION_KEY_ORDER_BY) + ?? config('database-schedule.default_ordering', 'created_at'); + $direction = request()->input('direction') + ?? session()->get(Schedule::SESSION_KEY_DIRECTION) + ?? config('database-schedule.default_ordering_direction', 'DESC'); + + session()->put(Schedule::SESSION_KEY_ORDER_BY, $orderBy); session()->put(Schedule::SESSION_KEY_DIRECTION, $direction); foreach (session()->get(Schedule::SESSION_KEY_FILTERS, []) as $column => $value) { @@ -41,24 +41,24 @@ public function index() } else if ($column === 'command') { // also search in job descriptions: $schedules->where(function ($query) use ($value) { - $query->orWhere('command', 'like', '%'.$value.'%'); + $query->orWhere('command', 'like', '%' . $value . '%'); $commands = (new CommandService())->get()->filter(function ($command) use ($value) { return false !== stristr($command->description, $value); })->pluck('name'); foreach ($commands as $command) { - $query->orWhere('command', 'like', '%'.$command .'%'); + $query->orWhere('command', 'like', '%' . $command . '%'); } }); } else if ($value) { - $schedules->where($column, 'like', '%'.$value.'%'); + $schedules->where($column, 'like', '%' . $value . '%'); } } - $schedules = $schedules - ->orderBy($orderBy, $direction) - ->paginate(config('database-schedule.per_page', 10)); + $schedules = $schedules + ->orderBy($orderBy, $direction) + ->paginate(config('database-schedule.per_page', 10)); return view('schedule::index')->with(compact('schedules', 'orderBy', 'direction')); } @@ -218,7 +218,7 @@ public function restore(Schedule $schedule) public function filterReset() { - session()->forget(Schedule::SESSION_KEY_ORDER_BY); + session()->forget(Schedule::SESSION_KEY_ORDER_BY); session()->forget(Schedule::SESSION_KEY_DIRECTION); session()->forget(Schedule::SESSION_KEY_FILTERS); diff --git a/src/Http/Middleware/Authenticate.php b/src/Http/Middleware/Authenticate.php index f3156c4..ee222b6 100644 --- a/src/Http/Middleware/Authenticate.php +++ b/src/Http/Middleware/Authenticate.php @@ -8,7 +8,7 @@ class Authenticate { public function handle($request, $next) { - if(config('database-schedule.restricted_access')) { + if (config('database-schedule.restricted_access')) { $guard = config('database-schedule.guard', 'web'); if (Gate::check('viewDatabaseSchedule', [$request->user($guard)])) { return $next($request); diff --git a/src/Http/Services/CommandService.php b/src/Http/Services/CommandService.php index dcfddef..97fad99 100644 --- a/src/Http/Services/CommandService.php +++ b/src/Http/Services/CommandService.php @@ -46,9 +46,8 @@ private function getOptions($command): object 'withValue' => [], 'withoutValue' => [] ]; - foreach ($command->getDefinition()->getOptions() as $option) - { - if($option->acceptValue()) { + foreach ($command->getDefinition()->getOptions() as $option) { + if ($option->acceptValue()) { $options->withValue[] = (object)[ 'name' => $option->getName(), 'default' => $option->getDefault(), diff --git a/src/Models/Schedule.php b/src/Models/Schedule.php index 749a7a2..55400e9 100644 --- a/src/Models/Schedule.php +++ b/src/Models/Schedule.php @@ -79,7 +79,6 @@ public function histories() return $this->hasMany(ScheduleHistory::class, 'schedule_id', 'id'); } - public function scopeInactive($query) { return $query->where('status', false); @@ -95,11 +94,11 @@ public function getArguments(): array $arguments = []; foreach (($this->params ?? []) as $argument => $value) { - if(empty($value['value'])) { + if (empty($value['value'])) { continue; } if (isset($value["type"]) && $value['type'] === 'function') { - $arguments[$argument] = (string) $value['value'](); + $arguments[$argument] = (string)$value['value'](); } else { $arguments[$argument] = $value['value']; } @@ -112,13 +111,13 @@ public function getOptions(): array { $options = []; foreach (($this->options ?? []) as $option => $value) { - if(is_array($value) && ($value['value'] ?? null) === null) { + if (is_array($value) && ($value['value'] ?? null) === null) { continue; } $option = '--' . $option; - if(is_array($value)) { + if (is_array($value)) { if (isset($value["type"]) && $value['type'] === 'function') { - $options[$option] = (string) $value['value'](); + $options[$option] = (string)$value['value'](); } else { $options[$option] = $value['value']; } diff --git a/src/View/Helpers.php b/src/View/Helpers.php index 2cfa80c..fb04e3f 100644 --- a/src/View/Helpers.php +++ b/src/View/Helpers.php @@ -58,7 +58,7 @@ public static function buildFilter(): HtmlString $filters = session()->get(Schedule::SESSION_KEY_FILTERS); foreach (static::getColumns() as $column) { - switch($column) { + switch ($column) { case 'arguments': $content = ''; break; @@ -99,7 +99,8 @@ public static function buildFilter(): HtmlString '', $js, $filters[$column] ?? '', - $column); + $column + ); break; } diff --git a/tests/Unit/PhpUnitDatabaseTest.php b/tests/Unit/PhpUnitDatabaseTest.php index 803c73f..8d9b582 100644 --- a/tests/Unit/PhpUnitDatabaseTest.php +++ b/tests/Unit/PhpUnitDatabaseTest.php @@ -13,5 +13,4 @@ public function testDatabaseAndFactoryWorks() $this->assertEquals(2, Schedule::all()->count()); } - } diff --git a/tests/Unit/ScheduleCommandsTest.php b/tests/Unit/ScheduleCommandsTest.php index 5a7e20d..fce2837 100644 --- a/tests/Unit/ScheduleCommandsTest.php +++ b/tests/Unit/ScheduleCommandsTest.php @@ -40,8 +40,7 @@ public function testRunInspireCommand() ]); - - $this->mock(\Illuminate\Console\Scheduling\Schedule::class, function (Mockery\MockInterface $mock){ + $this->mock(\Illuminate\Console\Scheduling\Schedule::class, function (Mockery\MockInterface $mock) { $mock->shouldReceive('command') ->once() ->with('inspire', []) @@ -100,7 +99,7 @@ public function testRunInspireWithOptionsBoolean() ->create([ 'command' => 'inspire', 'options' => [ - "argDisabledTrue"=>"on" + "argDisabledTrue" => "on" ] ]); @@ -114,4 +113,4 @@ public function testRunInspireWithOptionsBoolean() $scheduleService = app(\RobersonFaria\DatabaseSchedule\Console\Scheduling\Schedule::class); $scheduleService->execute(); } -} \ No newline at end of file +}