diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index edeab77..6980298 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,46 +1,165 @@ - true, + 'array_syntax' => ['syntax' => 'short'], + 'binary_operator_spaces' => [ + 'default' => 'single_space', + 'operators' => ['=>' => null], + ], + 'blank_line_after_namespace' => true, + 'blank_line_after_opening_tag' => true, + 'blank_line_before_statement' => [ + 'statements' => ['return'], + ], + 'braces' => true, + 'cast_spaces' => true, + 'class_attributes_separation' => [ + 'elements' => [ + 'const' => 'one', + 'method' => 'one', + 'property' => 'one', + 'trait_import' => 'none', + ], + ], + 'class_definition' => [ + 'multi_line_extends_each_single_line' => true, + 'single_item_single_line' => true, + 'single_line' => true, + ], + 'concat_space' => [ + 'spacing' => 'none', + ], + 'constant_case' => ['case' => 'lower'], + 'declare_equal_normalize' => true, + 'elseif' => true, + 'encoding' => true, + 'full_opening_tag' => true, + 'fully_qualified_strict_types' => true, // added by Shift + 'function_declaration' => true, + 'function_typehint_space' => true, + 'general_phpdoc_tag_rename' => true, + 'heredoc_to_nowdoc' => true, + 'include' => true, + 'increment_style' => ['style' => 'post'], + 'indentation_type' => true, + 'linebreak_after_opening_tag' => true, + 'line_ending' => true, + 'lowercase_cast' => true, + 'lowercase_keywords' => true, + 'lowercase_static_reference' => true, // added from Symfony + 'magic_method_casing' => true, // added from Symfony + 'magic_constant_casing' => true, + 'method_argument_space' => [ + 'on_multiline' => 'ignore', + ], + 'multiline_whitespace_before_semicolons' => [ + 'strategy' => 'no_multi_line', + ], + 'native_function_casing' => true, + 'no_alias_functions' => true, + 'no_extra_blank_lines' => [ + 'tokens' => [ + 'extra', + 'throw', + 'use', + ], + ], + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_closing_tag' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => [ + 'use' => 'echo', + ], + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_short_bool_cast' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_around_offset' => [ + 'positions' => ['inside', 'outside'], + ], + 'no_spaces_inside_parenthesis' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_whitespace' => true, + 'no_trailing_whitespace_in_comment' => true, + 'no_unneeded_control_parentheses' => [ + 'statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield'], + ], + 'no_unreachable_default_argument_value' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'normalize_index_brace' => true, + 'not_operator_with_successor_space' => true, + 'object_operator_without_whitespace' => true, + 'ordered_imports' => ['sort_algorithm' => 'alpha'], + 'psr_autoloading' => true, + 'phpdoc_indent' => true, + 'phpdoc_inline_tag_normalizer' => true, + 'phpdoc_no_access' => true, + 'phpdoc_no_package' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_scalar' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_summary' => false, + 'phpdoc_to_comment' => false, // override to preserve user preference + 'phpdoc_tag_type' => true, + 'phpdoc_trim' => true, + 'phpdoc_types' => true, + 'phpdoc_var_without_name' => true, + 'self_accessor' => true, + 'short_scalar_cast' => true, + 'simplified_null_return' => false, // disabled as "risky" + 'single_blank_line_at_eof' => true, + 'single_blank_line_before_namespace' => true, + 'single_class_element_per_statement' => [ + 'elements' => ['const', 'property'], + ], + 'single_import_per_statement' => true, + 'single_line_after_imports' => true, + 'single_line_comment_style' => [ + 'comment_types' => ['hash'], + ], + 'single_quote' => true, + 'space_after_semicolon' => true, + 'standardize_not_equals' => true, + 'switch_case_semicolon_to_colon' => true, + 'switch_case_space' => true, + 'ternary_operator_spaces' => true, + 'trailing_comma_in_multiline' => ['elements' => ['arrays']], + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'visibility_required' => [ + 'elements' => ['method', 'property'], + ], + 'whitespace_after_comma_in_array' => true, +]; + + +$finder = Finder::create() ->in([ __DIR__ . '/app', __DIR__ . '/config', - __DIR__ . '/database/factories', - __DIR__ . '/database/seeders', + __DIR__ . '/database', + __DIR__ . '/resources', __DIR__ . '/routes', __DIR__ . '/tests', - ]); - -$config = new PhpCsFixer\Config(); + ]) + ->name('*.php') + ->notName('*.blade.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true); -return $config +return (new Config) + ->setFinder($finder) + ->setRules($rules) ->setRiskyAllowed(true) - ->setRules([ - '@PhpCsFixer:risky' => true, - 'blank_line_after_opening_tag' => false, - 'linebreak_after_opening_tag' => false, - 'phpdoc_types_order' => [ - 'null_adjustment' => 'always_last', - 'sort_algorithm' => 'none', - ], - 'no_superfluous_phpdoc_tags' => false, - 'global_namespace_import' => [ - 'import_classes' => true, - 'import_constants' => true, - 'import_functions' => true, - ], - 'php_unit_test_case_static_method_calls' => [ - 'call_type' => 'this' - ], - 'phpdoc_align' => [ - 'align' => 'left', - ], - 'not_operator_with_successor_space' => true, - 'blank_line_after_namespace' => true, - 'date_time_immutable' => true, - 'declare_parentheses' => true, - 'final_public_method_for_abstract_class' => true, - 'mb_str_functions' => true, - 'simplified_if_return' => false, - 'simplified_null_return' => false, - ]) - ->setFinder($finder); + ->setUsingCache(true); diff --git a/app/Http/Controllers/Api/SquidAllowedIpController.php b/app/Http/Controllers/Api/SquidAllowedIpController.php index 31fd3af..b2c49b3 100644 --- a/app/Http/Controllers/Api/SquidAllowedIpController.php +++ b/app/Http/Controllers/Api/SquidAllowedIpController.php @@ -14,19 +14,22 @@ class SquidAllowedIpController extends Controller { - public function search(SearchRequest $request,SearchAction $action) : SquidAllowedIpCollection{ + public function search(SearchRequest $request, SearchAction $action) : SquidAllowedIpCollection + { $query = $request->searchSquidAllowedIp(); return new SquidAllowedIpCollection($action($query)); } - public function create(CreateRequest $request,CreateAction $action) : SquidAllowedIpResource{ + public function create(CreateRequest $request, CreateAction $action) : SquidAllowedIpResource + { $squidAllowedIp = $request->createSquidAllowedIp(); return new SquidAllowedIpResource($action($squidAllowedIp)); } - public function destroy(DestroyRequest $request,DestroyAction $action): SquidAllowedIpResource{ + public function destroy(DestroyRequest $request, DestroyAction $action): SquidAllowedIpResource + { $squidAllowedIp = $request->destroySquidAllowedIp(); return new SquidAllowedIpResource($action($squidAllowedIp)); diff --git a/app/Http/Controllers/Api/SquidUserController.php b/app/Http/Controllers/Api/SquidUserController.php index 95893a5..6086f45 100644 --- a/app/Http/Controllers/Api/SquidUserController.php +++ b/app/Http/Controllers/Api/SquidUserController.php @@ -16,25 +16,29 @@ class SquidUserController extends Controller { - public function search(SearchRequest $request, SearchAction $action) : SquidUserCollection{ + public function search(SearchRequest $request, SearchAction $action) : SquidUserCollection + { $query = $request->searchSquidUser(); return new SquidUserCollection($action($query)); } - public function create(CreateRequest $request, CreateAction $action) : SquidUserResource{ + public function create(CreateRequest $request, CreateAction $action) : SquidUserResource + { $user = $request->createSquidUser(); return new SquidUserResource($action($user)); } - public function modify(ModifyRequest $request, ModifyAction $action) : SquidUserResource{ + public function modify(ModifyRequest $request, ModifyAction $action) : SquidUserResource + { $user = $request->modifySquidUser(); return new SquidUserResource($action($user)); } - public function destroy(DestroyRequest $request, DestroyAction $action) : SquidUserResource{ + public function destroy(DestroyRequest $request, DestroyAction $action) : SquidUserResource + { $user = $request->destroySquidUser(); return new SquidUserResource($action($user)); diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index ab47356..927cb42 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -3,38 +3,42 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; -use App\Http\Requests\User\SearchRequest; use App\Http\Requests\User\CreateRequest; use App\Http\Requests\User\DestroyRequest; use App\Http\Requests\User\ModifyRequest; +use App\Http\Requests\User\SearchRequest; use App\Http\Resources\UserCollection; use App\Http\Resources\UserResource; -use App\UseCases\User\SearchAction; use App\UseCases\User\CreateAction; use App\UseCases\User\DestroyAction; use App\UseCases\User\ModifyAction; +use App\UseCases\User\SearchAction; class UserController extends Controller { - public function search(SearchRequest $request, SearchAction $action) : UserCollection{ + public function search(SearchRequest $request, SearchAction $action) : UserCollection + { $query = $request->searchUser(); return new UserCollection($action($query)); } - public function create(CreateRequest $request, CreateAction $action) : UserResource{ + public function create(CreateRequest $request, CreateAction $action) : UserResource + { $user = $request->createUser(); return new UserResource($action($user)); } - public function modify(ModifyRequest $request, ModifyAction $action) : UserResource{ + public function modify(ModifyRequest $request, ModifyAction $action) : UserResource + { $user = $request->modifyUser(); return new UserResource($action($user)); } - public function destroy(DestroyRequest $request, DestroyAction $action) : UserResource{ + public function destroy(DestroyRequest $request, DestroyAction $action) : UserResource + { $user = $request->destroyUser(); return new UserResource($action($user)); diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index f79a992..2920a23 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -3,8 +3,8 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; -use App\Providers\RouteServiceProvider; use App\Models\User; +use App\Providers\RouteServiceProvider; use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; diff --git a/app/Http/Controllers/Gui/SquidAllowedIpController.php b/app/Http/Controllers/Gui/SquidAllowedIpController.php index 30eff10..bd35dc7 100644 --- a/app/Http/Controllers/Gui/SquidAllowedIpController.php +++ b/app/Http/Controllers/Gui/SquidAllowedIpController.php @@ -12,23 +12,29 @@ class SquidAllowedIpController extends Controller { - public function search(SearchRequest $request,SearchAction $action){ - return view('squidallowedips.search',[ - 'ips'=>$action($request->searchSquidAllowedIp()) + public function search(SearchRequest $request, SearchAction $action) + { + return view('squidallowedips.search', [ + 'ips'=>$action($request->searchSquidAllowedIp()), ]); } - public function creator(){ + public function creator() + { return view('squidallowedips.creator'); } - public function create(CreateRequest $request,CreateAction $action){ + public function create(CreateRequest $request, CreateAction $action) + { $action($request->createSquidAllowedIp()); - return redirect()->route('ip.search',$request->user()->id); + + return redirect()->route('ip.search', $request->user()->id); } - public function destroy(DestroyRequest $request,DestroyAction $action){ + public function destroy(DestroyRequest $request, DestroyAction $action) + { $action($request->destroySquidAllowedIp()); - return redirect()->route('ip.search',$request->user()->id); + + return redirect()->route('ip.search', $request->user()->id); } } diff --git a/app/Http/Controllers/Gui/SquidUserController.php b/app/Http/Controllers/Gui/SquidUserController.php index 635bc67..df48f74 100644 --- a/app/Http/Controllers/Gui/SquidUserController.php +++ b/app/Http/Controllers/Gui/SquidUserController.php @@ -19,45 +19,55 @@ class SquidUserController extends Controller { private $squidUserService; - public function __construct(SquidUserService $squidUserService){ + public function __construct(SquidUserService $squidUserService) + { $this->squidUserService = $squidUserService; } - public function search(SearchRequest $request,SearchAction $action){ - return view('squidusers.search',[ - 'users'=>$action($request->searchSquidUser()) + public function search(SearchRequest $request, SearchAction $action) + { + return view('squidusers.search', [ + 'users'=>$action($request->searchSquidUser()), ]); } - public function creator(){ + public function creator() + { return view('squidusers.creator'); } - public function editor(ReadRequest $request){ + public function editor(ReadRequest $request) + { $squidUser = $this->squidUserService->getById($request->route()->parameter('id')); - return view('squidusers.editor',[ + + return view('squidusers.editor', [ 'id'=>$squidUser->id, 'user'=>$squidUser->user, 'password'=>$squidUser->password, 'fullname'=>$squidUser->fullname, 'comment'=>$squidUser->comment, - 'enabled'=>$squidUser->enabled + 'enabled'=>$squidUser->enabled, ]); } - public function modify(ModifyRequest $request,ModifyAction $action){ + public function modify(ModifyRequest $request, ModifyAction $action) + { $action($request->modifySquidUser()); - return redirect()->route('squiduser.search',$request->user()->id); - } + return redirect()->route('squiduser.search', $request->user()->id); + } - public function create(CreateRequest $request,CreateAction $action){ + public function create(CreateRequest $request, CreateAction $action) + { $action($request->createSquidUser()); - return redirect()->route('squiduser.search',$request->user()->id); + + return redirect()->route('squiduser.search', $request->user()->id); } - public function destroy(DestroyRequest $request,DestroyAction $action){ + public function destroy(DestroyRequest $request, DestroyAction $action) + { $action($request->destroySquidUser()); - return redirect()->route('squiduser.search',$request->user()->id); + + return redirect()->route('squiduser.search', $request->user()->id); } } diff --git a/app/Http/Controllers/Gui/UserController.php b/app/Http/Controllers/Gui/UserController.php index 9741fbd..fb07b8d 100644 --- a/app/Http/Controllers/Gui/UserController.php +++ b/app/Http/Controllers/Gui/UserController.php @@ -19,41 +19,52 @@ class UserController extends Controller { private $user; - public function __construct(UserService $user){ + public function __construct(UserService $user) + { $this->user = $user; } - public function create(CreateRequest $request,CreateAction $action){ + public function create(CreateRequest $request, CreateAction $action) + { $action($request->createUser()); + return redirect()->route('user.search'); } - public function modify(ModifyRequest $request,ModifyAction $action){ + public function modify(ModifyRequest $request, ModifyAction $action) + { $action($request->modifyUser()); + return redirect()->route('user.search'); } - public function editor(ReadRequest $request){ + public function editor(ReadRequest $request) + { $user = $this->user->getById($request->route()->parameter('id')); - return view('users.editor',[ + + return view('users.editor', [ 'id'=>$user->id, 'name'=>$user->name, - 'email'=>$user->email + 'email'=>$user->email, ]); } - public function creator(){ + public function creator() + { return view('users.creator'); } - public function destroy(DestroyRequest $request,DestroyAction $action){ + public function destroy(DestroyRequest $request, DestroyAction $action) + { $action($request->destroyUser()); + return back(); } - public function search(SearchRequest $request,SearchAction $action){ - return view('users.search',[ - 'users'=>$action($request->searchUser()) + public function search(SearchRequest $request, SearchAction $action) + { + return view('users.search', [ + 'users'=>$action($request->searchUser()), ]); } } diff --git a/app/Http/Requests/SquidAllowedIp/CreateRequest.php b/app/Http/Requests/SquidAllowedIp/CreateRequest.php index 21dc1f8..0cb8e6f 100644 --- a/app/Http/Requests/SquidAllowedIp/CreateRequest.php +++ b/app/Http/Requests/SquidAllowedIp/CreateRequest.php @@ -15,7 +15,8 @@ class CreateRequest extends FormRequest */ public function authorize(Gate $gate) { - $auth = $gate->allows('create-squid-allowed-ip',$this->route()->parameter('user_id')); + $auth = $gate->allows('create-squid-allowed-ip', $this->route()->parameter('user_id')); + return $auth; } @@ -27,7 +28,7 @@ public function authorize(Gate $gate) public function rules() { return [ - 'ip'=>'required|ip|unique:squid_allowed_ips' + 'ip'=>'required|ip|unique:squid_allowed_ips', ]; } @@ -35,6 +36,7 @@ public function createSquidAllowedIp() : SquidAllowedIp { $squidAllowedIp = new SquidAllowedIp($this->validated()); $squidAllowedIp->user_id = $this->route()->parameter('user_id'); + return $squidAllowedIp; } } diff --git a/app/Http/Requests/SquidAllowedIp/DestroyRequest.php b/app/Http/Requests/SquidAllowedIp/DestroyRequest.php index dfabe06..50d9963 100644 --- a/app/Http/Requests/SquidAllowedIp/DestroyRequest.php +++ b/app/Http/Requests/SquidAllowedIp/DestroyRequest.php @@ -14,9 +14,9 @@ class DestroyRequest extends FormRequest * * @return bool */ - public function authorize(Gate $gate,SquidAllowedIpService $squidAllowedIpService) + public function authorize(Gate $gate, SquidAllowedIpService $squidAllowedIpService) { - return $gate->allows('destroy-squid-allowed-ip',$squidAllowedIpService->getById($this->route()->parameter('id'))); + return $gate->allows('destroy-squid-allowed-ip', $squidAllowedIpService->getById($this->route()->parameter('id'))); } /** @@ -31,9 +31,10 @@ public function rules() ]; } - public function destroySquidAllowedIp() : SquidAllowedIp{ - $ip = SquidAllowedIp::query()->where('id','=',$this->route()->parameter('id'))->first(); + public function destroySquidAllowedIp() : SquidAllowedIp + { + $ip = SquidAllowedIp::query()->where('id', '=', $this->route()->parameter('id'))->first(); + return $ip; } - } diff --git a/app/Http/Requests/SquidAllowedIp/SearchRequest.php b/app/Http/Requests/SquidAllowedIp/SearchRequest.php index 9adbb4a..e185b8b 100644 --- a/app/Http/Requests/SquidAllowedIp/SearchRequest.php +++ b/app/Http/Requests/SquidAllowedIp/SearchRequest.php @@ -14,7 +14,7 @@ class SearchRequest extends FormRequest */ public function authorize(Gate $gate) { - return $gate->allows('search-squid-allowed-ip',$this->route()->parameter('user_id')); + return $gate->allows('search-squid-allowed-ip', $this->route()->parameter('user_id')); } /** @@ -25,12 +25,14 @@ public function authorize(Gate $gate) public function rules() { return [ - 'per'=>'digits_between:1,100' + 'per'=>'digits_between:1,100', ]; } - public function searchSquidAllowedIp(){ - $validated = $this->validated(); + public function searchSquidAllowedIp() + { + $validated = $this->validated(); + return $validated; } } diff --git a/app/Http/Requests/SquidUser/CreateRequest.php b/app/Http/Requests/SquidUser/CreateRequest.php index 7140c9a..2a86bfb 100644 --- a/app/Http/Requests/SquidUser/CreateRequest.php +++ b/app/Http/Requests/SquidUser/CreateRequest.php @@ -15,15 +15,16 @@ class CreateRequest extends FormRequest */ public function authorize(Gate $gate) { - $auth = $gate->allows('create-squid-user',$this->route()->parameter('user_id')); + $auth = $gate->allows('create-squid-user', $this->route()->parameter('user_id')); + return $auth; } protected function prepareForValidation() { - if(empty($this->enabled)){ + if (empty($this->enabled)) { $this->merge([ - 'enabled'=>0 + 'enabled'=>0, ]); } } @@ -40,7 +41,7 @@ public function rules() 'password'=>['required', 'string', 'min:8'], 'enabled'=>'filled|digits_between:0,1', 'fullname'=>'nullable', - 'comment'=>'nullable' + 'comment'=>'nullable', ]; } @@ -48,6 +49,7 @@ public function createSquidUser() : SquidUser { $squidUser = new SquidUser($this->validated()); $squidUser->user_id = $this->route()->parameter('user_id'); + return $squidUser; } } diff --git a/app/Http/Requests/SquidUser/DestroyRequest.php b/app/Http/Requests/SquidUser/DestroyRequest.php index 2727d60..eb2d17e 100644 --- a/app/Http/Requests/SquidUser/DestroyRequest.php +++ b/app/Http/Requests/SquidUser/DestroyRequest.php @@ -14,11 +14,12 @@ class DestroyRequest extends FormRequest * * @return bool */ - public function authorize(Gate $gate,SquidUserService $squidUserService) + public function authorize(Gate $gate, SquidUserService $squidUserService) { - $auth = $gate->allows('destroy-squid-user', + $auth = $gate->allows('destroy-squid-user', $squidUserService->getById($this->route()->parameter('id')) ); + return $auth; } @@ -34,8 +35,10 @@ public function rules() ]; } - public function destroySquidUser() : SquidUser{ - $squidUser = SquidUser::query()->where('id','=',$this->route()->parameter('id'))->first(); + public function destroySquidUser() : SquidUser + { + $squidUser = SquidUser::query()->where('id', '=', $this->route()->parameter('id'))->first(); + return $squidUser; } } diff --git a/app/Http/Requests/SquidUser/ModifyRequest.php b/app/Http/Requests/SquidUser/ModifyRequest.php index 8dd28c5..51c7292 100644 --- a/app/Http/Requests/SquidUser/ModifyRequest.php +++ b/app/Http/Requests/SquidUser/ModifyRequest.php @@ -14,20 +14,20 @@ class ModifyRequest extends FormRequest * * @return bool */ - public function authorize(Gate $gate,SquidUserService $squidUserService) + public function authorize(Gate $gate, SquidUserService $squidUserService) { - $auth = $gate->allows('modify-squid-user', + $auth = $gate->allows('modify-squid-user', $squidUserService->getById($this->route()->parameter('id')) ); + return $auth; } - protected function prepareForValidation() { - if(empty($this->enabled)){ + if (empty($this->enabled)) { $this->merge([ - 'enabled'=>0 + 'enabled'=>0, ]); } } @@ -44,13 +44,15 @@ public function rules() 'password'=>['required', 'string', 'min:8'], 'enabled'=>'filled|digits_between:0,1', 'fullname'=>'nullable', - 'comment'=>'nullable' + 'comment'=>'nullable', ]; } - public function modifySquidUser() : SquidUser{ + public function modifySquidUser() : SquidUser + { $squidUser = new SquidUser($this->validated()); $squidUser->id = $this->route()->parameter('id'); + return $squidUser; } } diff --git a/app/Http/Requests/SquidUser/ReadRequest.php b/app/Http/Requests/SquidUser/ReadRequest.php index 39dfbec..d10ab0f 100644 --- a/app/Http/Requests/SquidUser/ReadRequest.php +++ b/app/Http/Requests/SquidUser/ReadRequest.php @@ -13,11 +13,12 @@ class ReadRequest extends FormRequest * * @return bool */ - public function authorize(Gate $gate,SquidUserService $squidUserService) + public function authorize(Gate $gate, SquidUserService $squidUserService) { - $auth = $gate->allows('modify-squid-user', + $auth = $gate->allows('modify-squid-user', $squidUserService->getById($this->route()->parameter('id')) ); + return $auth; } diff --git a/app/Http/Requests/SquidUser/SearchRequest.php b/app/Http/Requests/SquidUser/SearchRequest.php index 2b033e7..2223dee 100644 --- a/app/Http/Requests/SquidUser/SearchRequest.php +++ b/app/Http/Requests/SquidUser/SearchRequest.php @@ -14,7 +14,8 @@ class SearchRequest extends FormRequest */ public function authorize(Gate $gate) { - $auth = $gate->allows('search-squid-user',$this->route()->parameter('user_id')); + $auth = $gate->allows('search-squid-user', $this->route()->parameter('user_id')); + return $auth; } @@ -30,8 +31,10 @@ public function rules() ]; } - public function searchSquidUser(): array{ + public function searchSquidUser(): array + { $validated = $this->validated(); + return $validated; } } diff --git a/app/Http/Requests/User/CreateRequest.php b/app/Http/Requests/User/CreateRequest.php index aa905f6..6dacf85 100644 --- a/app/Http/Requests/User/CreateRequest.php +++ b/app/Http/Requests/User/CreateRequest.php @@ -3,8 +3,8 @@ namespace App\Http\Requests\User; use App\Models\User; -use Illuminate\Foundation\Http\FormRequest; use Illuminate\Contracts\Auth\Access\Gate; +use Illuminate\Foundation\Http\FormRequest; class CreateRequest extends FormRequest { @@ -15,7 +15,8 @@ class CreateRequest extends FormRequest */ public function authorize(Gate $gate) : bool { - $auth = $gate->allows('create-user'); + $auth = $gate->allows('create-user'); + return $auth; } diff --git a/app/Http/Requests/User/DestroyRequest.php b/app/Http/Requests/User/DestroyRequest.php index 057e9be..69148b3 100644 --- a/app/Http/Requests/User/DestroyRequest.php +++ b/app/Http/Requests/User/DestroyRequest.php @@ -10,7 +10,8 @@ class DestroyRequest extends FormRequest { public function authorize(Gate $gate) { - $auth = $gate->allows('destroy-user',$this->route()->parameter('id')); + $auth = $gate->allows('destroy-user', $this->route()->parameter('id')); + return $auth; } @@ -26,10 +27,10 @@ public function rules() ]; } - public function destroyUser(): User { - $user = User::query()->where('id','=',$this->route()->parameter('id'))->first(); + $user = User::query()->where('id', '=', $this->route()->parameter('id'))->first(); + return $user; } } diff --git a/app/Http/Requests/User/ModifyRequest.php b/app/Http/Requests/User/ModifyRequest.php index 93506d6..4537284 100644 --- a/app/Http/Requests/User/ModifyRequest.php +++ b/app/Http/Requests/User/ModifyRequest.php @@ -10,7 +10,8 @@ class ModifyRequest extends FormRequest { public function authorize(Gate $gate) : bool { - $auth = $gate->allows('modify-user',$this->route()->parameter('id')); + $auth = $gate->allows('modify-user', $this->route()->parameter('id')); + return $auth; } @@ -19,7 +20,7 @@ public function rules() return [ 'name'=>'filled', 'email'=>'filled|unique:users,email,'.$this->route()->parameter('id').',id', - 'password'=>['string', 'min:8','filled'], + 'password'=>['string', 'min:8', 'filled'], ]; } @@ -27,6 +28,7 @@ public function modifyUser(): User { $user = new User($this->validated()); $user->id = $this->route()->parameter('id'); + return $user; } } diff --git a/app/Http/Requests/User/ReadRequest.php b/app/Http/Requests/User/ReadRequest.php index 3b0ea2d..8a2d250 100644 --- a/app/Http/Requests/User/ReadRequest.php +++ b/app/Http/Requests/User/ReadRequest.php @@ -14,7 +14,8 @@ class ReadRequest extends FormRequest */ public function authorize(Gate $gate) { - $auth = $gate->allows('search-user'); + $auth = $gate->allows('search-user'); + return $auth; } diff --git a/app/Http/Requests/User/SearchRequest.php b/app/Http/Requests/User/SearchRequest.php index b9c8792..72967ee 100644 --- a/app/Http/Requests/User/SearchRequest.php +++ b/app/Http/Requests/User/SearchRequest.php @@ -15,7 +15,8 @@ class SearchRequest extends FormRequest */ public function authorize(Gate $gate) { - $auth = $gate->allows('search-user'); + $auth = $gate->allows('search-user'); + return $auth; } @@ -31,8 +32,10 @@ public function rules() ]; } - public function searchUser(): array{ - $validated = $this->validated(); + public function searchUser(): array + { + $validated = $this->validated(); + return $validated; } } diff --git a/app/Http/Resources/SquidAllowedIpCollection.php b/app/Http/Resources/SquidAllowedIpCollection.php index b28ed35..898bae4 100644 --- a/app/Http/Resources/SquidAllowedIpCollection.php +++ b/app/Http/Resources/SquidAllowedIpCollection.php @@ -8,6 +8,7 @@ class SquidAllowedIpCollection extends ResourceCollection { public $collects = SquidAllowedIpResource::class; + /** * Transform the resource collection into an array. * @@ -17,7 +18,7 @@ class SquidAllowedIpCollection extends ResourceCollection public function toArray($request) { return [ - 'data'=>$this->collection + 'data'=>$this->collection, ]; } } diff --git a/app/Http/Resources/SquidAllowedIpResource.php b/app/Http/Resources/SquidAllowedIpResource.php index 55c80e3..0793300 100644 --- a/app/Http/Resources/SquidAllowedIpResource.php +++ b/app/Http/Resources/SquidAllowedIpResource.php @@ -17,7 +17,7 @@ public function toArray($request) { return [ 'id'=> $this->resource->id, - 'ip'=>$this->resource->ip + 'ip'=>$this->resource->ip, ]; } } diff --git a/app/Http/Resources/SquidUserResource.php b/app/Http/Resources/SquidUserResource.php index 1b54068..8cabd57 100644 --- a/app/Http/Resources/SquidUserResource.php +++ b/app/Http/Resources/SquidUserResource.php @@ -21,7 +21,7 @@ public function toArray($request) 'password'=>$this->resource->password, 'enabled'=>$this->resource->enabled, 'fullname'=>$this->resource->fullname, - 'comment'=>$this->resource->comment + 'comment'=>$this->resource->comment, ]; } } diff --git a/app/Models/Scopes/SquidUserScope.php b/app/Models/Scopes/SquidUserScope.php index 57f5232..e9dc7d8 100644 --- a/app/Models/Scopes/SquidUserScope.php +++ b/app/Models/Scopes/SquidUserScope.php @@ -22,5 +22,4 @@ public function apply(Builder $builder, Model $model) $builder->where('user_id', '=', Auth::user()->id); } } - } diff --git a/app/Models/SquidAllowedIp.php b/app/Models/SquidAllowedIp.php index 65127e6..5301d75 100644 --- a/app/Models/SquidAllowedIp.php +++ b/app/Models/SquidAllowedIp.php @@ -18,4 +18,9 @@ protected static function booted() { static::addGlobalScope(new SquidUserScope()); } + + public function laravel_user() + { + return $this->belongsTo(User::class, 'user_id'); + } } diff --git a/app/Models/SquidUser.php b/app/Models/SquidUser.php index de22916..248cef4 100644 --- a/app/Models/SquidUser.php +++ b/app/Models/SquidUser.php @@ -15,11 +15,16 @@ class SquidUser extends Model 'password', 'enabled', 'fullname', - 'comment' + 'comment', ]; protected static function booted() { static::addGlobalScope(new SquidUserScope()); } + + public function laravel_user() + { + return $this->belongsTo(User::class, 'user_id'); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 4fa15ff..b4f4123 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -43,7 +43,8 @@ class User extends Authenticatable 'email_verified_at' => 'datetime', ]; - public function setPasswordAttribute($value){ + public function setPasswordAttribute($value) + { $this->attributes['password'] = Hash::needsRehash($value) ? Hash::make($value) : $value; } } diff --git a/app/Policies/AllowedIpPolicy.php b/app/Policies/AllowedIpPolicy.php index 32fee33..ddfc007 100644 --- a/app/Policies/AllowedIpPolicy.php +++ b/app/Policies/AllowedIpPolicy.php @@ -20,40 +20,42 @@ public function __construct() // } - public function search(User $user,string $toSpecifiedUserId){ - if($user->is_administrator === 1){ + public function search(User $user, string $toSpecifiedUserId) + { + if ($user->is_administrator === 1) { return true; } - if(strcmp((string)$user->id,$toSpecifiedUserId) === 0){ + if (strcmp((string) $user->id, $toSpecifiedUserId) === 0) { return true; } return false; } - public function create(User $user,string $toSpecifiedUserId){ - if($user->is_administrator === 1){ + public function create(User $user, string $toSpecifiedUserId) + { + if ($user->is_administrator === 1) { return true; } - if(strcmp((string)$user->id,$toSpecifiedUserId) === 0){ + if (strcmp((string) $user->id, $toSpecifiedUserId) === 0) { return true; } return false; } - public function destroy(User $user,SquidAllowedIp $squidAllowedIp){ - if($user->is_administrator === 1){ + public function destroy(User $user, SquidAllowedIp $squidAllowedIp) + { + if ($user->is_administrator === 1) { return true; } - if(strcmp((string)$user->id,(string)$squidAllowedIp->user_id) === 0){ + if (strcmp((string) $user->id, (string) $squidAllowedIp->user_id) === 0) { return true; } return false; } - } diff --git a/app/Policies/SquidUserPolicy.php b/app/Policies/SquidUserPolicy.php index 9c6e38c..4f14e68 100644 --- a/app/Policies/SquidUserPolicy.php +++ b/app/Policies/SquidUserPolicy.php @@ -20,48 +20,52 @@ public function __construct() // } - public function search(User $user,string $toSpecifiedUserId){ - if($user->is_administrator === 1){ + public function search(User $user, string $toSpecifiedUserId) + { + if ($user->is_administrator === 1) { return true; } - if(strcmp((string)$user->id,$toSpecifiedUserId) === 0){ + if (strcmp((string) $user->id, $toSpecifiedUserId) === 0) { return true; } return false; } - public function create(User $user,string $toSpecifiedUserId){ - if($user->is_administrator === 1){ + public function create(User $user, string $toSpecifiedUserId) + { + if ($user->is_administrator === 1) { return true; } - if(strcmp((string)$user->id,$toSpecifiedUserId) === 0){ + if (strcmp((string) $user->id, $toSpecifiedUserId) === 0) { return true; } return false; } - public function modify(User $user,SquidUser $squidUser){ - if($user->is_administrator === 1){ + public function modify(User $user, SquidUser $squidUser) + { + if ($user->is_administrator === 1) { return true; } - if(strcmp((string)$user->id,(string)$squidUser->user_id) === 0){ + if (strcmp((string) $user->id, (string) $squidUser->user_id) === 0) { return true; } return false; } - public function destroy(User $user,SquidUser $squidUser){ - if($user->is_administrator === 1){ + public function destroy(User $user, SquidUser $squidUser) + { + if ($user->is_administrator === 1) { return true; } - if(strcmp((string)$user->id,(string)$squidUser->user_id) === 0){ + if (strcmp((string) $user->id, (string) $squidUser->user_id) === 0) { return true; } diff --git a/app/Policies/UserPolicy.php b/app/Policies/UserPolicy.php index 38b990f..fad0bbc 100644 --- a/app/Policies/UserPolicy.php +++ b/app/Policies/UserPolicy.php @@ -19,26 +19,31 @@ public function __construct() // } - public function create(User $user){ + public function create(User $user) + { return $user->is_administrator === 1; } - public function modify(User $user,string $updateUserId){ - if($user->is_administrator === 1){ + public function modify(User $user, string $updateUserId) + { + if ($user->is_administrator === 1) { return true; } - if(strcmp((string)$user->id,$updateUserId) === 0){ + if (strcmp((string) $user->id, $updateUserId) === 0) { return true; } + return false; } - public function destroy(User $user){ + public function destroy(User $user) + { return $user->is_administrator === 1; } - public function search(User $user){ + public function search(User $user) + { return $user->is_administrator === 1; } } diff --git a/app/Services/SquidAllowedIpService.php b/app/Services/SquidAllowedIpService.php index 9b0e4bc..d9b6a64 100644 --- a/app/Services/SquidAllowedIpService.php +++ b/app/Services/SquidAllowedIpService.php @@ -1,12 +1,15 @@ where('id', '=', $id)->first(); - public function getById($id) : SquidAllowedIp{ - $ip = SquidAllowedIp::query()->where('id','=',$id)->first(); return $ip ?? new SquidAllowedIp(); } } diff --git a/app/Services/SquidUserService.php b/app/Services/SquidUserService.php index 40a35db..191b950 100644 --- a/app/Services/SquidUserService.php +++ b/app/Services/SquidUserService.php @@ -1,12 +1,15 @@ where('id', '=', $id)->first(); - public function getById($id) : SquidUser{ - $su = SquidUser::query()->where('id','=',$id)->first(); return $su ?? new SquidUser(); } } diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 39ec3a5..b5553db 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -1,12 +1,15 @@ where('id', '=', $id)->first(); - public function getById($id) : User{ - $user = User::query()->where('id','=',$id)->first(); return $user ?? new User(); } } diff --git a/app/UseCases/AllowedIp/CreateAction.php b/app/UseCases/AllowedIp/CreateAction.php index 4c9a0ff..2034847 100644 --- a/app/UseCases/AllowedIp/CreateAction.php +++ b/app/UseCases/AllowedIp/CreateAction.php @@ -1,10 +1,12 @@ exists); diff --git a/app/UseCases/AllowedIp/DestroyAction.php b/app/UseCases/AllowedIp/DestroyAction.php index c2a9037..2e55534 100644 --- a/app/UseCases/AllowedIp/DestroyAction.php +++ b/app/UseCases/AllowedIp/DestroyAction.php @@ -1,14 +1,17 @@ exists); $squidAllowedIp->delete(); + return $squidAllowedIp; } } diff --git a/app/UseCases/AllowedIp/ModifyAction.php b/app/UseCases/AllowedIp/ModifyAction.php index 91d7ff9..69f262f 100644 --- a/app/UseCases/AllowedIp/ModifyAction.php +++ b/app/UseCases/AllowedIp/ModifyAction.php @@ -1,11 +1,12 @@ with('laravel_user') ->simplePaginate($query['per'] ?? 100) - ->withQueryString() - ; + ->withQueryString(); return $ips; } diff --git a/app/UseCases/SquidUser/CreateAction.php b/app/UseCases/SquidUser/CreateAction.php index 689c455..36e0754 100644 --- a/app/UseCases/SquidUser/CreateAction.php +++ b/app/UseCases/SquidUser/CreateAction.php @@ -1,14 +1,17 @@ exists); $user->save(); + return $user; } } diff --git a/app/UseCases/SquidUser/DestroyAction.php b/app/UseCases/SquidUser/DestroyAction.php index e69ea8b..d19885f 100644 --- a/app/UseCases/SquidUser/DestroyAction.php +++ b/app/UseCases/SquidUser/DestroyAction.php @@ -1,14 +1,17 @@ exists); $squidUser->delete(); + return $squidUser; } } diff --git a/app/UseCases/SquidUser/ModifyAction.php b/app/UseCases/SquidUser/ModifyAction.php index d60c96c..073e624 100644 --- a/app/UseCases/SquidUser/ModifyAction.php +++ b/app/UseCases/SquidUser/ModifyAction.php @@ -1,20 +1,23 @@ where('id','=',$squidUser->id)->first(); + $modifyUser = SquidUser::query()->where('id', '=', $squidUser->id)->first(); assert($modifyUser->exists); $modifyUser->fill($squidUser->getAttributes()); $modifyUser->save(); + return $modifyUser; } } diff --git a/app/UseCases/SquidUser/SearchAction.php b/app/UseCases/SquidUser/SearchAction.php index b9b308e..0d1052a 100644 --- a/app/UseCases/SquidUser/SearchAction.php +++ b/app/UseCases/SquidUser/SearchAction.php @@ -1,17 +1,18 @@ with('laravel_user') ->simplePaginate($query['per'] ?? 100) - ->withQueryString() - ; + ->withQueryString(); return $squidUsers; - } } diff --git a/app/UseCases/User/CreateAction.php b/app/UseCases/User/CreateAction.php index 8556afc..120ab28 100644 --- a/app/UseCases/User/CreateAction.php +++ b/app/UseCases/User/CreateAction.php @@ -1,14 +1,17 @@ exists); $user->save(); + return $user; } } diff --git a/app/UseCases/User/DestroyAction.php b/app/UseCases/User/DestroyAction.php index 9326703..00ed89c 100644 --- a/app/UseCases/User/DestroyAction.php +++ b/app/UseCases/User/DestroyAction.php @@ -1,10 +1,12 @@ exists); $countAdministrator = User::query() - ->where('id','<>',$destroyUser->id) - ->where('is_administrator','=',1) - ->count() - ; + ->where('id', '<>', $destroyUser->id) + ->where('is_administrator', '=', 1) + ->count(); //disable locked out. assert($countAdministrator !== 0); $destroyUser->delete(); + return $destroyUser; } } diff --git a/app/UseCases/User/ModifyAction.php b/app/UseCases/User/ModifyAction.php index 7ed7f4b..30a6e8f 100644 --- a/app/UseCases/User/ModifyAction.php +++ b/app/UseCases/User/ModifyAction.php @@ -1,10 +1,12 @@ id !== null); - $updateUser = User::query()->where('id','=',$user->id)->first(); + $updateUser = User::query()->where('id', '=', $user->id)->first(); assert($updateUser->exists); $updateUser->fill($user->getAttributes()); $updateUser->save(); + return $updateUser; } } diff --git a/app/UseCases/User/SearchAction.php b/app/UseCases/User/SearchAction.php index 3918511..87e9281 100644 --- a/app/UseCases/User/SearchAction.php +++ b/app/UseCases/User/SearchAction.php @@ -1,17 +1,17 @@ simplePaginate($query['per'] ?? 100) - ->withQueryString() - ; + ->withQueryString(); return $users; - } } diff --git a/database/factories/SquidAllowedIpFactory.php b/database/factories/SquidAllowedIpFactory.php index 4220732..70fa8fb 100644 --- a/database/factories/SquidAllowedIpFactory.php +++ b/database/factories/SquidAllowedIpFactory.php @@ -17,7 +17,7 @@ class SquidAllowedIpFactory extends Factory public function definition() { return [ - 'ip'=>$this->faker->ipv4 + 'ip'=>$this->faker->ipv4, ]; } } diff --git a/database/factories/SquidUserFactory.php b/database/factories/SquidUserFactory.php index baad4d1..d3c9b49 100644 --- a/database/factories/SquidUserFactory.php +++ b/database/factories/SquidUserFactory.php @@ -22,7 +22,7 @@ public function definition() 'password' => Str::random(10), 'enabled'=>1, 'fullname'=>$this->faker->name(), - 'comment'=> Str::random(20) + 'comment'=> Str::random(20), ]; } } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 3e50b30..1a88b2c 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2014_10_12_100000_create_password_resets_table.php b/database/migrations/2014_10_12_100000_create_password_resets_table.php index fcacb80..440f474 100644 --- a/database/migrations/2014_10_12_100000_create_password_resets_table.php +++ b/database/migrations/2014_10_12_100000_create_password_resets_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php index 1719198..262db10 100644 --- a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php +++ b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php index c7378d0..704391f 100644 --- a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php +++ b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_03_04_165752_create_squid_users_table.php b/database/migrations/2022_03_04_165752_create_squid_users_table.php index 531ea69..284e259 100644 --- a/database/migrations/2022_03_04_165752_create_squid_users_table.php +++ b/database/migrations/2022_03_04_165752_create_squid_users_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_03_10_174340_create_squid_allowed_ips_table.php b/database/migrations/2022_03_10_174340_create_squid_allowed_ips_table.php index 2f6889b..4f53365 100644 --- a/database/migrations/2022_03_10_174340_create_squid_allowed_ips_table.php +++ b/database/migrations/2022_03_10_174340_create_squid_allowed_ips_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * @@ -21,7 +20,7 @@ public function up() $table->dateTime('updated_at')->nullable()->default(null); $table->unique([ 'user_id', - 'ip' + 'ip', ]); }); } diff --git a/database/seeders/CreateAdministratorSeeder.php b/database/seeders/CreateAdministratorSeeder.php index 69e236a..fe6e219 100644 --- a/database/seeders/CreateAdministratorSeeder.php +++ b/database/seeders/CreateAdministratorSeeder.php @@ -30,8 +30,8 @@ public function run() $user = Auth::loginUsingId($aUser->id); $token = $user->createToken('token1'); - echo "Email: ".$email.PHP_EOL; - echo "Password: ".$password.PHP_EOL; - echo "Token: ".$token->plainTextToken.PHP_EOL; + echo 'Email: '.$email.PHP_EOL; + echo 'Password: '.$password.PHP_EOL; + echo 'Token: '.$token->plainTextToken.PHP_EOL; } } diff --git a/resources/views/squidallowedips/search.blade.php b/resources/views/squidallowedips/search.blade.php index db51f32..7310d79 100644 --- a/resources/views/squidallowedips/search.blade.php +++ b/resources/views/squidallowedips/search.blade.php @@ -13,7 +13,7 @@