Skip to content

Commit

Permalink
fix phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
robersonfaria committed Nov 23, 2021
1 parent ab0b854 commit 332897e
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 38 deletions.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"orchestra/testbench": "^5.20"
"orchestra/testbench": "^5.20",
"squizlabs/php_codesniffer": "^3.6"
},
"authors": [
{
Expand All @@ -34,6 +35,10 @@
]
}
},
"scripts": {
"phpcs": "./vendor/bin/phpcs .",
"tests": "./vendor/bin/phpunit ./tests"
},
"minimum-stability": "dev",
"prefer-stable": true
}
58 changes: 57 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down Expand Up @@ -36,4 +36,3 @@
$schedule = app(config('database-schedule.model'));
return $schedule::onlyTrashed()->find($id);
});

3 changes: 1 addition & 2 deletions src/Console/Scheduling/Schedule.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace RobersonFaria\DatabaseSchedule\Console\Scheduling;

use RobersonFaria\DatabaseSchedule\Http\Services\ScheduleService;
Expand Down Expand Up @@ -52,7 +51,7 @@ private function dispatch($task)
//ensure output is being captured to write history
$event->storeOutput();

if($task->environments) {
if ($task->environments) {
$event->environments(explode(',', $task->environments));
}

Expand Down
30 changes: 15 additions & 15 deletions src/Http/Controllers/ScheduleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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'));
}
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/Http/Services/CommandService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
11 changes: 5 additions & 6 deletions src/Models/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public function histories()
return $this->hasMany(ScheduleHistory::class, 'schedule_id', 'id');
}


public function scopeInactive($query)
{
return $query->where('status', false);
Expand All @@ -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'];
}
Expand All @@ -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'];
}
Expand Down
5 changes: 3 additions & 2 deletions src/View/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +99,8 @@ public static function buildFilter(): HtmlString
'<input @blur="%s" value="%s" form="schedule-filter-form" type="text" class="form-control" name="filters[%s]">',
$js,
$filters[$column] ?? '',
$column);
$column
);
break;
}

Expand Down
1 change: 0 additions & 1 deletion tests/Unit/PhpUnitDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ public function testDatabaseAndFactoryWorks()

$this->assertEquals(2, Schedule::all()->count());
}

}
7 changes: 3 additions & 4 deletions tests/Unit/ScheduleCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [])
Expand Down Expand Up @@ -100,7 +99,7 @@ public function testRunInspireWithOptionsBoolean()
->create([
'command' => 'inspire',
'options' => [
"argDisabledTrue"=>"on"
"argDisabledTrue" => "on"
]
]);

Expand All @@ -114,4 +113,4 @@ public function testRunInspireWithOptionsBoolean()
$scheduleService = app(\RobersonFaria\DatabaseSchedule\Console\Scheduling\Schedule::class);
$scheduleService->execute();
}
}
}

0 comments on commit 332897e

Please sign in to comment.