From 079319bf7fad77247e6da4d53d84f1b51953e8de Mon Sep 17 00:00:00 2001 From: Prabeg Shakya Date: Wed, 19 Apr 2023 10:51:06 +0545 Subject: [PATCH 1/2] Add Laravel shift rules for php-cs-fixer Signed-off-by: Prabeg Shakya --- .php-cs-fixer.php | 166 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 .php-cs-fixer.php diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..d9cca8f --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,166 @@ + 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_unused_imports' => 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', + __DIR__ . '/resources', + __DIR__ . '/routes', + __DIR__ . '/tests', + ]) + ->name('*.php') + ->notName('*.blade.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +return (new Config) + ->setFinder($finder) + ->setRules($rules) + ->setRiskyAllowed(true) + ->setUsingCache(true); \ No newline at end of file From 58c53f89ae4660aac56be15e09485143f185a2c0 Mon Sep 17 00:00:00 2001 From: Prabeg Shakya Date: Wed, 19 Apr 2023 10:51:34 +0545 Subject: [PATCH 2/2] Lint fixes Signed-off-by: Prabeg Shakya --- .gitignore | 1 + app/Exceptions/Handler.php | 1 - app/Http/Controllers/AdminController.php | 42 +- app/Http/Controllers/AuthController.php | 31 +- app/Http/Controllers/ClientController.php | 19 +- app/Http/Controllers/InviteController.php | 23 +- app/Http/Controllers/ProjectController.php | 42 +- app/Http/Controllers/TimeLogController.php | 42 +- app/Http/Controllers/UserController.php | 14 +- app/Http/Kernel.php | 3 +- app/Http/Middleware/CheckProjectStatus.php | 15 +- app/Http/Middleware/CheckUserActiveStatus.php | 3 +- app/Http/Middleware/RestrictToAdmin.php | 13 +- app/Http/Middleware/VerifyCsrfToken.php | 2 +- app/Http/Requests/AddTimeLogRequest.php | 2 +- app/Http/Requests/CheckOnlyEmailRequest.php | 2 +- app/Http/Requests/EditProjectRequest.php | 3 - app/Http/Requests/EditTimeLogRequest.php | 1 - app/Http/Requests/MemberInviteRequest.php | 2 +- app/Http/Requests/PasswordResetRequest.php | 2 +- app/Http/Requests/UserLoginRequest.php | 2 +- app/Http/Requests/UserStoreRequest.php | 4 +- app/Http/Resources/AdminResource.php | 16 +- app/Http/Resources/ClientResource.php | 1 - app/Http/Resources/InviteResource.php | 2 - app/Http/Resources/ProjectResource.php | 1 - app/Http/Resources/RoleResource.php | 4 +- app/Http/Resources/TimeLogResource.php | 2 - app/Http/Resources/UserResource.php | 2 - app/Mail/InviteCreated.php | 2 - app/Mail/ReInvite.php | 1 - app/Models/InviteToken.php | 6 +- app/Models/Project.php | 8 +- app/Models/Role.php | 6 +- app/Models/TimeLog.php | 7 +- app/Models/User.php | 30 +- app/Providers/AuthServiceProvider.php | 3 +- app/Services/ClientService.php | 6 +- app/Services/InviteService.php | 25 +- app/Services/ProjectService.php | 22 +- app/Services/TimeLogService.php | 20 +- app/Services/UserService.php | 30 +- composer.json | 4 +- composer.lock | 737 ++++++++++++++++-- config/frontend.php | 2 +- config/sanctum.php | 2 +- .../2014_10_12_000000_create_users_table.php | 3 +- ...12_100000_create_password_resets_table.php | 3 +- ..._08_19_000000_create_failed_jobs_table.php | 3 +- ...01_create_personal_access_tokens_table.php | 3 +- .../2022_03_24_063305_create_roles_table.php | 3 +- ...2_03_24_111817_create_user_roles_table.php | 3 +- ...022_05_15_031617_create_projects_table.php | 3 +- ...5_15_033637_create_user_projects_table.php | 3 +- ...2022_05_25_112945_create_clients_table.php | 3 +- ...hange_role_id_type_invite_tokens_table.php | 5 +- ...2_change_client_id_type_projects_table.php | 6 +- ...id_project_id_type_user_projects_table.php | 7 +- ...d_type_project_id_type_time_logs_table.php | 7 +- ..._id_type_role_id_type_user_roles_table.php | 8 +- ...07_163357_add_column_to_projects_table.php | 5 +- ...8_152510_add_column_to_time_logs_table.php | 3 +- ...ime_end_time_column_to_time_logs_table.php | 5 +- ...ate_and_end_date_from_datetime_to_date.php | 3 +- database/seeders/CreateRolesSeeder.php | 1 - database/seeders/DatabaseSeeder.php | 1 - routes/api.php | 25 +- routes/web.php | 1 - tests/Feature/ExampleTest.php | 1 - 69 files changed, 933 insertions(+), 380 deletions(-) diff --git a/.gitignore b/.gitignore index edbabe9..b5c19d4 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ npm-debug.log yarn-error.log /.idea /.vscode +.php-cs-fixer.cache \ No newline at end of file diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 185a9fd..1c18072 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -35,7 +35,6 @@ class Handler extends ExceptionHandler public function register() { $this->reportable(function (Throwable $e) { - }); } } diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 6f1437d..6fcac29 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -3,15 +3,15 @@ namespace App\Http\Controllers; use App\Http\Requests\MemberInviteRequest; +use App\Http\Resources\AdminResource; +use App\Http\Resources\RoleResource; +use App\Models\User; use App\Models\UserRole; use App\Services\InviteService; use App\Services\UserService; use Illuminate\Http\Request; -use App\Models\User; -use Mockery\Exception; -use App\Http\Resources\AdminResource; -use App\Http\Resources\RoleResource; use Illuminate\Http\Response; +use Mockery\Exception; class AdminController extends Controller { @@ -21,30 +21,28 @@ public function deleteUser($id) $deleteStatus = UserService::checkUserIdExists($id); - if (!$deleteStatus) { + if (! $deleteStatus) { return response()->json([ - 'message' => 'User does not exist with given id' + 'message' => 'User does not exist with given id', ], Response::HTTP_NOT_FOUND); } $roles = $user->roles()->pluck('role'); if ($roles->contains('admin')) { - return response()->json([ - 'message' => 'Admin User cannot be deleted' + 'message' => 'Admin User cannot be deleted', ], 403); } if ($user->delete()) { - return response()->json([ - 'message' => 'User deleted Successfully' + 'message' => 'User deleted Successfully', ], 200); } return response()->json([ - 'message' => 'Oops Something Went Wrong' + 'message' => 'Oops Something Went Wrong', ], 403); } @@ -54,7 +52,7 @@ public function viewAllUsers() return response()->json([ 'total' => count($users), - 'users' => AdminResource::collection($users) + 'users' => AdminResource::collection($users), ], 200); } @@ -64,7 +62,7 @@ public function viewUserRole(Request $request) return response()->json([ 'total' => count($role), - 'roles' => RoleResource::collection($role) + 'roles' => RoleResource::collection($role), ], 200); } @@ -77,7 +75,7 @@ public function assignRoles(Request $request) $user = UserService::getUser($request->toArray(), $rules); $role = UserRole::create([ 'user_id' => $user['id'], - 'role_id' => $request->role_id + 'role_id' => $request->role_id, ]); $result = [ 'status' => 200, @@ -87,9 +85,10 @@ public function assignRoles(Request $request) } catch (Exception $e) { $result = [ 'status' => 404, - 'error' => $e->getMessage() + 'error' => $e->getMessage(), ]; } + return response()->json($result, $result['status']); } @@ -98,14 +97,14 @@ public function inviteOthers(MemberInviteRequest $request, InviteService $invite $validated = $request->safe()->only(['role_id', 'email', 'user_id', 'name']); $status = $inviteService->invite($validated['name'], $validated['email'], $validated['role_id'], $validated['user_id']); - if (!$status) { + if (! $status) { return response()->json([ - 'message' => 'User could not be invited' + 'message' => 'User could not be invited', ], 500); } return response()->json([ - 'message' => 'User invited successfully' + 'message' => 'User invited successfully', ], 200); } @@ -113,7 +112,7 @@ public function updateUserStatus(Request $request) { $user = User::where('id', $request->id)->first(); try { - if (!$user->activeStatus) { + if (! $user->activeStatus) { $user->activeStatus = true; } else { $user->activeStatus = false; @@ -121,14 +120,15 @@ public function updateUserStatus(Request $request) $user->save(); $result = [ 'status' => 200, - 'message' => 'User status updated' + 'message' => 'User status updated', ]; } catch (Exception $e) { $result = [ 'status' => 500, - 'error' => $e->getMessage() + 'error' => $e->getMessage(), ]; } + return response()->json($result, $result['status']); } } diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 19951c2..8742e1b 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -5,10 +5,10 @@ use App\Http\Requests\PasswordResetRequest; use App\Http\Requests\UserLoginRequest; use App\Http\Requests\UserStoreRequest; -use Illuminate\Http\Request; use App\Services\UserService; -use Mockery\Exception; use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; +use Mockery\Exception; class AuthController extends Controller { @@ -24,9 +24,10 @@ public function registerUser(UserStoreRequest $request) } catch (Exception $e) { $result = [ 'status' => 403, - 'message' => $e->getMessage() + 'message' => $e->getMessage(), ]; } + return response()->json($result, $result['status']); } @@ -42,39 +43,40 @@ public function loginUser(UserLoginRequest $request) 'access_token' => $token->plainTextToken, 'token_type' => 'Bearer', ]; - } catch (Exception $e) { $result = [ 'status' => 401, - 'error' => $e->getMessage() + 'error' => $e->getMessage(), ]; } + return response()->json($result, $result['status']); } public function logoutUser(Request $request) { $request->user()->currentAccessToken()->delete(); + return response()->json([ - 'message' => 'User logged out sucessfully' + 'message' => 'User logged out sucessfully', ], 200); - } public function forgotPass(Request $request): JsonResponse { $request->validate([ - 'email' => 'required | email' + 'email' => 'required | email', ]); $validatedForgetPass = $request->only('email'); $status = UserService::forgotPassword($validatedForgetPass); - if (!$status) { + if (! $status) { return response()->json([ - 'message' => 'User with given email address not found' + 'message' => 'User with given email address not found', ], 404); } + return response()->json([ - 'message' => 'Reset email sent successfully' + 'message' => 'Reset email sent successfully', ], 200); } @@ -82,13 +84,14 @@ public function resetPass(PasswordResetRequest $request): JsonResponse { $validatedResetPass = $request->safe()->all(); $status = UserService::resetPassword($validatedResetPass); - if (!$status) { + if (! $status) { return response()->json([ - 'message' => 'Could not reset password. Please check your token or email address' + 'message' => 'Could not reset password. Please check your token or email address', ], 404); } + return response()->json([ - 'message' => 'Password reset successfully' + 'message' => 'Password reset successfully', ], 200); } } diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index ba63c8c..56e071c 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -2,28 +2,26 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; -use App\Models\Project; +use App\Http\Requests\ClientRequest; +use App\Http\Resources\ClientResource; use App\Models\Client; -use Mockery\Exception; use App\Services\ClientService; -use App\Http\Requests\ClientRequest; use Illuminate\Http\JsonResponse; -use App\Http\Resources\ClientResource; class ClientController extends Controller { public function addActivity(ClientRequest $request): JsonResponse - { + { $validatedAddClient = $request->validated(); $result = ClientService::addProject($validatedAddClient); - if (!$result) { + if (! $result) { return response()->json([ - 'message' => 'Could not add client' + 'message' => 'Could not add client', ], 400); } + return response()->json([ - 'message' => 'Client added successfully' + 'message' => 'Client added successfully', ]); } @@ -33,8 +31,7 @@ public function viewAllClients() return response()->json([ 'total' => count($projects), - 'clients' => ClientResource::collection($projects) + 'clients' => ClientResource::collection($projects), ], 200); - } } diff --git a/app/Http/Controllers/InviteController.php b/app/Http/Controllers/InviteController.php index 9995197..514fe95 100644 --- a/app/Http/Controllers/InviteController.php +++ b/app/Http/Controllers/InviteController.php @@ -3,11 +3,10 @@ namespace App\Http\Controllers; use App\Http\Requests\CheckOnlyEmailRequest; -use App\Services\InviteService; -use Illuminate\Http\JsonResponse; -use Illuminate\Http\Request; use App\Http\Resources\InviteResource; use App\Models\InviteToken; +use App\Services\InviteService; +use Illuminate\Http\JsonResponse; class InviteController extends Controller { @@ -15,11 +14,11 @@ public function listInvitedUsers(): JsonResponse { $totaluser = InviteToken::count(); $users = InviteService::invitedList(); - + return response()->json([ 'total' => $totaluser, 'invitedUsers' => InviteResource::collection($users), - ],200); + ], 200); } public function reInvite(CheckOnlyEmailRequest $request, InviteService $inviteService): JsonResponse @@ -27,29 +26,29 @@ public function reInvite(CheckOnlyEmailRequest $request, InviteService $inviteSe $validated = $request->safe()->only(['email']); $status = $inviteService->resendInvite($validated['email']); - if (!$status) { + if (! $status) { return response()->json([ - 'message' => 'User does not exist in our database' + 'message' => 'User does not exist in our database', ], 500); } return response()->json([ - 'message' => 'User re-invited successfully' + 'message' => 'User re-invited successfully', ]); - } public function revoke($id): JsonResponse { $status = InviteService::revokeInvite($id); - if (!$status) { + if (! $status) { return response()->json([ - 'message' => 'Cannot revoke invite. User does not exist in our database' + 'message' => 'Cannot revoke invite. User does not exist in our database', ], 500); } + return response()->json([ - 'message' => 'User invite revoked successfully' + 'message' => 'User invite revoked successfully', ]); } } diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 8ff965a..d17eab0 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -2,33 +2,35 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; +use App\Http\Requests\EditProjectRequest; +use App\Http\Requests\ProjectRequest; +use App\Http\Resources\ProjectResource; use App\Models\Project; -use \Exception; use App\Services\ProjectService; -use App\Http\Requests\{ProjectRequest, EditProjectRequest}; -use Illuminate\Http\JsonResponse; -use App\Http\Resources\ProjectResource; +use Exception; use Illuminate\Database\Eloquent\ModelNotFoundException; +use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; use Illuminate\Http\Response; class ProjectController extends Controller { - public function __construct(protected ProjectService $projectService) { } + public function addActivity(ProjectRequest $request): JsonResponse { $validatedAddProject = $request->validated(); $addProjectData = ProjectService::addProject($validatedAddProject); - if (!$addProjectData) { + if (! $addProjectData) { return response()->json([ - 'message' => 'Could not create a project' + 'message' => 'Could not create a project', ], 400); } + return response()->json([ - 'message' => 'Project created successfully' + 'message' => 'Project created successfully', ]); } @@ -37,13 +39,14 @@ public function updateActivity(EditProjectRequest $request, $id) $validatedEditProject = $request->validated(); try { $updateProjectData = ProjectService::updateProject($validatedEditProject, $id); + return response()->json([ - "message" => "Project Updated Successfully", - "project" => $updateProjectData + 'message' => 'Project Updated Successfully', + 'project' => $updateProjectData, ], Response::HTTP_OK); } catch (ModelNotFoundException $e) { return response()->json([ - 'message' => "Project with this Id doesnt Exists", + 'message' => 'Project with this Id doesnt Exists', ], Response::HTTP_BAD_REQUEST); } catch (\Exception $e) { return response()->json([ @@ -56,7 +59,7 @@ public function updateProjectStatus(Request $request) { $project = Project::where('id', $request->id)->first(); try { - if (!$project->status) { + if (! $project->status) { $project->status = true; } else { $project->status = false; @@ -70,9 +73,10 @@ public function updateProjectStatus(Request $request) } catch (Exception $e) { $result = [ 'status' => 500, - 'error' => $e->getMessage() + 'error' => $e->getMessage(), ]; } + return response()->json($result, $result['status']); } @@ -80,7 +84,7 @@ public function updateBillableStatus(Request $request) { $project = Project::where('id', $request->id)->first(); try { - if (!$project->billable) { + if (! $project->billable) { $project->billable = true; } else { $project->billable = false; @@ -94,9 +98,10 @@ public function updateBillableStatus(Request $request) } catch (Exception $e) { $result = [ 'status' => 500, - 'error' => $e->getMessage() + 'error' => $e->getMessage(), ]; } + return response()->json($result, $result['status']); } @@ -104,16 +109,17 @@ public function viewAllProjects(Request $request) { $projects = Project::orderBy('updated_at', 'desc')->paginate(); if ($request['search']) { - $projects = Project::where('project_name', 'LIKE', "%" . $request['search'] . "%")->paginate(); + $projects = Project::where('project_name', 'LIKE', '%'.$request['search'].'%')->paginate(); } - return ProjectResource::collection($projects); + return ProjectResource::collection($projects); } public function deleteProject(int $id): JsonResponse { try { $this->projectService->removeProject($id); + return response()->json([], Response::HTTP_NO_CONTENT); } catch (\Exception $e) { return response()->json([ diff --git a/app/Http/Controllers/TimeLogController.php b/app/Http/Controllers/TimeLogController.php index 9ddcb69..a9dd331 100644 --- a/app/Http/Controllers/TimeLogController.php +++ b/app/Http/Controllers/TimeLogController.php @@ -4,32 +4,33 @@ use App\Http\Requests\AddTimeLogRequest; use App\Http\Requests\EditTimeLogRequest; +use App\Http\Resources\TimeLogResource; use App\Services\ProjectService; use App\Services\TimeLogService; use App\Services\UserService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use App\Http\Resources\TimeLogResource; class TimeLogController extends Controller { public function addActivity(AddTimeLogRequest $request): JsonResponse { - if (!ProjectService::checkProjectIdExists($request['project_id']) || !UserService::checkUserIdExists($request['user_id'])) { + if (! ProjectService::checkProjectIdExists($request['project_id']) || ! UserService::checkUserIdExists($request['user_id'])) { return response()->json([ - 'message' => 'Project Id or User Id does not exist' + 'message' => 'Project Id or User Id does not exist', ], 400); } $validatedAddLog = $request->validated(); $log = TimeLogService::addTimeLog($validatedAddLog); - if (!is_object($log)) { + if (! is_object($log)) { return response()->json([ - 'message' => 'Could not create a time log' + 'message' => 'Could not create a time log', ], 400); } + return response()->json([ 'message' => 'Time log created successfully', - 'log' => TimeLogResource::make($log) + 'log' => TimeLogResource::make($log), ]); } @@ -37,16 +38,16 @@ public function viewLogs(Request $request): JsonResponse { //validate if user id passed is actually do exist $status = UserService::checkUserIdExists($request->id); - if (!$status) { + if (! $status) { return response()->json([ - 'message' => 'User does not exist' + 'message' => 'User does not exist', ], 400); } // if user exists then view their logs $size = $request->size; $totals = TimeLogService::viewTotalTimeLogs($request->id); - $logs = TimeLogService::viewPaginateTimeLogs(size:(int)$size,id:(int)$request->id); + $logs = TimeLogService::viewPaginateTimeLogs(size:(int) $size, id:(int) $request->id); if (empty($logs)) { return response()->json([ 'message' => 'No logs found', @@ -56,40 +57,41 @@ public function viewLogs(Request $request): JsonResponse return response()->json([ 'message' => 'Logs found', 'total' => $totals, - 'logs' => TimeLogResource::collection($logs) + 'logs' => TimeLogResource::collection($logs), ]); } - public function editActivity(EditTimeLogRequest $request,$id): JsonResponse + public function editActivity(EditTimeLogRequest $request, $id): JsonResponse { - if (!ProjectService::checkProjectIdExists($request['project_id']) || !UserService::checkUserIdExists($request['user_id'])) { + if (! ProjectService::checkProjectIdExists($request['project_id']) || ! UserService::checkUserIdExists($request['user_id'])) { return response()->json([ - 'message' => 'Project Id or User Id does not exist' + 'message' => 'Project Id or User Id does not exist', ], 400); } $validatedEditLog = $request->validated(); $status = TimeLogService::editTimeLog($validatedEditLog, $id); - if (!$status) { + if (! $status) { return response()->json([ - 'message' => 'Time log with this id does not exist' + 'message' => 'Time log with this id does not exist', ], 400); } + return response()->json([ - 'message' => 'Time log edited successfully' + 'message' => 'Time log edited successfully', ]); - } public function removeActivity($id): JsonResponse { $status = TimeLogService::removeLog($id); - if (!$status) { + if (! $status) { return response()->json([ - 'message' => 'Time log with this id does not exist' + 'message' => 'Time log with this id does not exist', ], 400); } + return response()->json([ - 'message' => 'Time log deleted successfully' + 'message' => 'Time log deleted successfully', ]); } } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 7f4c485..2a58db4 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -2,20 +2,20 @@ namespace App\Http\Controllers; +use App\Http\Resources\UserResource; use App\Services\UserService; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Mockery\Exception; -use App\Models\User; -use App\Http\Resources\UserResource; class UserController extends Controller { public function viewMe() { $user = Auth::guard('sanctum')->user(); + return response()->json([ - 'user_details' => $user + 'user_details' => $user, ]); } @@ -36,22 +36,22 @@ public function updateMe(Request $request) 'message' => 'User password updated', 'user' => $user, ]; - } catch (Exception $e) { $result = [ 'status' => 500, - 'error' => $e->getMessage() + 'error' => $e->getMessage(), ]; } + return response()->json($result, $result['status']); } public function allUserRoles() { $allRoles = UserService::roles(); + return response()->json([ - 'UserRoles' => UserResource::collection($allRoles) + 'UserRoles' => UserResource::collection($allRoles), ]); - } } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 752f072..5a23d95 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -2,7 +2,6 @@ namespace App\Http; - use Illuminate\Foundation\Http\Kernel as HttpKernel; class Kernel extends HttpKernel @@ -41,7 +40,7 @@ class Kernel extends HttpKernel ], 'api' => [ - \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, + \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, 'throttle:api', \Illuminate\Routing\Middleware\SubstituteBindings::class, ], diff --git a/app/Http/Middleware/CheckProjectStatus.php b/app/Http/Middleware/CheckProjectStatus.php index 20b8b2d..dbb0baf 100644 --- a/app/Http/Middleware/CheckProjectStatus.php +++ b/app/Http/Middleware/CheckProjectStatus.php @@ -2,9 +2,9 @@ namespace App\Http\Middleware; +use App\Models\Project; use Closure; use Illuminate\Http\Request; -use App\Models\Project; class CheckProjectStatus { @@ -18,16 +18,17 @@ class CheckProjectStatus public function handle(Request $request, Closure $next) { $project = Project::where('id', $request->id)->first(); - if(empty($project)){ + if (empty($project)) { return response()->json([ - 'message' => 'Project does not exits' - ],403); + 'message' => 'Project does not exits', + ], 403); } - if(!$project->status) { + if (! $project->status) { return response()->json([ - 'message' => 'The project is disabled' - ],403); + 'message' => 'The project is disabled', + ], 403); } + return $next($request); } } diff --git a/app/Http/Middleware/CheckUserActiveStatus.php b/app/Http/Middleware/CheckUserActiveStatus.php index e68b678..ac31c67 100644 --- a/app/Http/Middleware/CheckUserActiveStatus.php +++ b/app/Http/Middleware/CheckUserActiveStatus.php @@ -18,9 +18,10 @@ class CheckUserActiveStatus public function handle(Request $request, Closure $next) { $user = Auth::guard('sanctum')->user(); - if(!$user->activeStatus) { + if (! $user->activeStatus) { return abort(403); } + return $next($request); } } diff --git a/app/Http/Middleware/RestrictToAdmin.php b/app/Http/Middleware/RestrictToAdmin.php index f218e63..74e7677 100644 --- a/app/Http/Middleware/RestrictToAdmin.php +++ b/app/Http/Middleware/RestrictToAdmin.php @@ -16,19 +16,20 @@ class RestrictToAdmin public function handle(Request $request, Closure $next) { $user = Auth::guard('sanctum')->user()->toArray(); - if(empty($user)){ + if (empty($user)) { return response()->json([ - 'message' => 'Please login to proceed' - ],403); + 'message' => 'Please login to proceed', + ], 403); } $roles = User::find($user['id'])->roles; foreach ($roles as $role) { - if ($role['role'] === 'admin'){ + if ($role['role'] === 'admin') { return $next($request); } } + return response()->json([ - 'message' => 'You are not authorized to access this route' - ],403); + 'message' => 'You are not authorized to access this route', + ], 403); } } diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index c9a891b..abd020f 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -12,6 +12,6 @@ class VerifyCsrfToken extends Middleware * @var array */ protected $except = [ - 'api/user/login' //need to delete this later after the project is completed + 'api/user/login', //need to delete this later after the project is completed ]; } diff --git a/app/Http/Requests/AddTimeLogRequest.php b/app/Http/Requests/AddTimeLogRequest.php index 66a0787..99a58bb 100644 --- a/app/Http/Requests/AddTimeLogRequest.php +++ b/app/Http/Requests/AddTimeLogRequest.php @@ -29,7 +29,7 @@ public function rules() 'project_id' => 'required | integer|exists:projects,id', 'billable' => 'required | boolean', 'start_date' => 'required | date_format:Y-m-d', - 'started_time'=>'required | date_format:H:i:s' + 'started_time'=>'required | date_format:H:i:s', ]; } } diff --git a/app/Http/Requests/CheckOnlyEmailRequest.php b/app/Http/Requests/CheckOnlyEmailRequest.php index ab25cd8..90a97ff 100644 --- a/app/Http/Requests/CheckOnlyEmailRequest.php +++ b/app/Http/Requests/CheckOnlyEmailRequest.php @@ -24,7 +24,7 @@ public function authorize() public function rules() { return [ - 'email' => 'required | email' + 'email' => 'required | email', ]; } } diff --git a/app/Http/Requests/EditProjectRequest.php b/app/Http/Requests/EditProjectRequest.php index 1b24968..9ebd39b 100644 --- a/app/Http/Requests/EditProjectRequest.php +++ b/app/Http/Requests/EditProjectRequest.php @@ -31,6 +31,3 @@ public function rules() ]; } } - - - diff --git a/app/Http/Requests/EditTimeLogRequest.php b/app/Http/Requests/EditTimeLogRequest.php index a1b822d..45bacfa 100644 --- a/app/Http/Requests/EditTimeLogRequest.php +++ b/app/Http/Requests/EditTimeLogRequest.php @@ -23,7 +23,6 @@ public function authorize() */ public function rules() { - return [ 'activity_name' => 'required|max:255', 'user_id' => 'required | integer|exists:users,id', diff --git a/app/Http/Requests/MemberInviteRequest.php b/app/Http/Requests/MemberInviteRequest.php index 9960c5f..ae2a481 100644 --- a/app/Http/Requests/MemberInviteRequest.php +++ b/app/Http/Requests/MemberInviteRequest.php @@ -27,7 +27,7 @@ public function rules() 'name' => 'required|regex:/^[\pL\s\-]+$/u|max:255', 'email' => 'required | email |max:255|unique:invite_tokens', 'role_id' => 'required | integer|max:255', - 'user_id' => 'required | integer' + 'user_id' => 'required | integer', ]; } } diff --git a/app/Http/Requests/PasswordResetRequest.php b/app/Http/Requests/PasswordResetRequest.php index 482afcf..158b06c 100644 --- a/app/Http/Requests/PasswordResetRequest.php +++ b/app/Http/Requests/PasswordResetRequest.php @@ -26,7 +26,7 @@ public function rules() return [ 'email' => 'required | email |max:255', 'token' => 'required', - 'password' => ['required','min:6','regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\x])(?=.*[!$#%]).*$/','confirmed'], + 'password' => ['required', 'min:6', 'regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\x])(?=.*[!$#%]).*$/', 'confirmed'], ]; } } diff --git a/app/Http/Requests/UserLoginRequest.php b/app/Http/Requests/UserLoginRequest.php index 7eabc2d..d92297e 100644 --- a/app/Http/Requests/UserLoginRequest.php +++ b/app/Http/Requests/UserLoginRequest.php @@ -25,7 +25,7 @@ public function rules() { return [ 'email' => 'required | email', - 'password' => 'required' + 'password' => 'required', ]; } } diff --git a/app/Http/Requests/UserStoreRequest.php b/app/Http/Requests/UserStoreRequest.php index a1e514f..6d845ef 100644 --- a/app/Http/Requests/UserStoreRequest.php +++ b/app/Http/Requests/UserStoreRequest.php @@ -26,8 +26,8 @@ public function rules() return [ 'name' => 'required|regex:/^[\pL\s\-]+$/u|max:255', 'email' => 'required | email|max:255', - 'password' => ['required','min:6','regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\x])(?=.*[!$#%]).*$/','confirmed'], - 'token' => 'required' + 'password' => ['required', 'min:6', 'regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\x])(?=.*[!$#%]).*$/', 'confirmed'], + 'token' => 'required', ]; } } diff --git a/app/Http/Resources/AdminResource.php b/app/Http/Resources/AdminResource.php index 0871fb2..e038634 100644 --- a/app/Http/Resources/AdminResource.php +++ b/app/Http/Resources/AdminResource.php @@ -14,12 +14,12 @@ class AdminResource extends JsonResource */ public function toArray($request) { - return [ - 'id'=>$this->id, - 'role'=> RoleResource::collection($this->roles), - 'name'=>$this->name, - 'email'=>$this->email, - 'active_status'=>$this->activeStatus, - ]; + return [ + 'id'=>$this->id, + 'role'=> RoleResource::collection($this->roles), + 'name'=>$this->name, + 'email'=>$this->email, + 'active_status'=>$this->activeStatus, + ]; } -} +} diff --git a/app/Http/Resources/ClientResource.php b/app/Http/Resources/ClientResource.php index 1b419d5..753cd54 100644 --- a/app/Http/Resources/ClientResource.php +++ b/app/Http/Resources/ClientResource.php @@ -21,6 +21,5 @@ public function toArray($request) 'client_number'=>$this->client_number, 'status'=>$this->status, ]; - } } diff --git a/app/Http/Resources/InviteResource.php b/app/Http/Resources/InviteResource.php index a43ee6d..6b2caf0 100644 --- a/app/Http/Resources/InviteResource.php +++ b/app/Http/Resources/InviteResource.php @@ -1,8 +1,6 @@ $this->id, 'role'=>$this->role, - ]; + ]; } } diff --git a/app/Http/Resources/TimeLogResource.php b/app/Http/Resources/TimeLogResource.php index d9a7a31..a1bcec3 100644 --- a/app/Http/Resources/TimeLogResource.php +++ b/app/Http/Resources/TimeLogResource.php @@ -3,7 +3,6 @@ namespace App\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; -use App\Http\Resources\ProjectResource; class TimeLogResource extends JsonResource { @@ -15,7 +14,6 @@ class TimeLogResource extends JsonResource */ public function toArray($request) { - return [ 'id'=>$this->id, 'activity_name'=>$this->activity_name, diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php index 951ee44..5acb175 100644 --- a/app/Http/Resources/UserResource.php +++ b/app/Http/Resources/UserResource.php @@ -2,7 +2,6 @@ namespace App\Http\Resources; - use Illuminate\Http\Resources\Json\JsonResource; class UserResource extends JsonResource @@ -19,6 +18,5 @@ public function toArray($request) 'id' => $this->id, 'role' => $this->role, ]; - } } diff --git a/app/Mail/InviteCreated.php b/app/Mail/InviteCreated.php index 4a09a30..d5c6e5c 100644 --- a/app/Mail/InviteCreated.php +++ b/app/Mail/InviteCreated.php @@ -3,7 +3,6 @@ namespace App\Mail; use Illuminate\Bus\Queueable; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; @@ -19,7 +18,6 @@ public function __construct($url) { // $this->url = $url; - } /** diff --git a/app/Mail/ReInvite.php b/app/Mail/ReInvite.php index a77c12c..1d4cbb6 100644 --- a/app/Mail/ReInvite.php +++ b/app/Mail/ReInvite.php @@ -3,7 +3,6 @@ namespace App\Mail; use Illuminate\Bus\Queueable; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; diff --git a/app/Models/InviteToken.php b/app/Models/InviteToken.php index 0efb125..3b0f0c2 100644 --- a/app/Models/InviteToken.php +++ b/app/Models/InviteToken.php @@ -2,10 +2,10 @@ namespace App\Models; -use Illuminate\Support\Facades\Hash; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Support\Facades\Hash; class InviteToken extends Model { @@ -24,7 +24,7 @@ class InviteToken extends Model 'token', 'invitedUserId', 'tokenExpires', - 'created_at' + 'created_at', ]; public function setTokenAttribute($token) diff --git a/app/Models/Project.php b/app/Models/Project.php index 234f70c..630854a 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -2,11 +2,11 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; class Project extends Model { @@ -28,10 +28,10 @@ public function client(): BelongsTo public function timeLogs(): HasMany { - return $this->hasMany(TimeLog::class, 'project_id',); + return $this->hasMany(TimeLog::class, 'project_id', ); } - public function users(): BelongsToMany + public function users(): BelongsToMany { return $this->belongsToMany(User::class, 'user_projects', 'project_id', 'user_id'); } diff --git a/app/Models/Role.php b/app/Models/Role.php index 739d235..43c0ecc 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -2,8 +2,8 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -13,7 +13,7 @@ class Role extends Model protected $fillable = [ 'id', - 'role' + 'role', ]; protected $hidden = [ @@ -31,7 +31,7 @@ public function users(): BelongsToMany return $this->belongsToMany(User::class, 'user_roles', 'role_id', 'user_id'); } - public function inviteTokens(): HasMany + public function inviteTokens(): HasMany { return $this->hasMany(InviteToken::class, 'role_id'); } diff --git a/app/Models/TimeLog.php b/app/Models/TimeLog.php index ebebed0..a9c84f2 100644 --- a/app/Models/TimeLog.php +++ b/app/Models/TimeLog.php @@ -2,10 +2,10 @@ namespace App\Models; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; -Use Carbon\Carbon; class TimeLog extends Model { @@ -19,8 +19,9 @@ class TimeLog extends Model 'start_date', 'end_date', 'started_time', - 'ended_time' + 'ended_time', ]; + protected $perPage = 50; public function setStartTimeAttribute($value) @@ -40,6 +41,6 @@ public function user(): BelongsTo public function project(): BelongsTo { - return $this->belongsTo(Project::class, 'project_id',); + return $this->belongsTo(Project::class, 'project_id', ); } } diff --git a/app/Models/User.php b/app/Models/User.php index 97e381f..fe8fe8d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,14 +2,13 @@ namespace App\Models; -use Laravel\Sanctum\HasApiTokens; -use Illuminate\Support\Facades\Hash; -use Illuminate\Notifications\Notifiable; -use Illuminate\Contracts\Auth\MustVerifyEmail; -use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Factories\HasFactory; -use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Notifications\Notifiable; +use Illuminate\Support\Facades\Hash; +use Laravel\Sanctum\HasApiTokens; class User extends Authenticatable { @@ -33,7 +32,7 @@ class User extends Authenticatable */ protected $hidden = [ 'password', - 'remember_token' + 'remember_token', ]; /** @@ -48,26 +47,29 @@ class User extends Authenticatable /* * Get the role that belongs to the user */ - public function roles(): BelongsToMany { + public function roles(): BelongsToMany + { return $this->belongsToMany(Role::class, 'user_roles', 'user_id', 'role_id'); } /* * Get the project that belongs to the user */ - public function projects(): BelongsToMany + public function projects(): BelongsToMany { return $this->belongsToMany(Project::class, 'user_projects', 'user_id', 'project_id'); } - public function timeLogs(): HasMany + public function timeLogs(): HasMany { return $this->hasMany(TimeLog::class, 'user_id'); - } - public function setPasswordAttribute($password){ - if(trim($password) === '') return; - $this->attributes['password'] = Hash::make($password); + public function setPasswordAttribute($password) + { + if (trim($password) === '') { + return; + } + $this->attributes['password'] = Hash::make($password); } } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 4e249df..f5519e3 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -4,7 +4,6 @@ use Illuminate\Auth\Notifications\ResetPassword; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; -use Illuminate\Support\Facades\Gate; class AuthServiceProvider extends ServiceProvider { @@ -27,7 +26,7 @@ public function boot() $this->registerPolicies(); ResetPassword::createUrlUsing(function ($user, string $token) { - return config('frontend.url') . '/reset-password?token=' . $token. '&email='.$user->email; + return config('frontend.url').'/reset-password?token='.$token.'&email='.$user->email; }); } } diff --git a/app/Services/ClientService.php b/app/Services/ClientService.php index 37b5f89..e024ea0 100644 --- a/app/Services/ClientService.php +++ b/app/Services/ClientService.php @@ -2,7 +2,6 @@ namespace App\Services; -use App\Models\Project; use App\Models\Client; class ClientService @@ -11,7 +10,10 @@ public static function addProject(array $validatedAddClient): bool { $log = Client::create($validatedAddClient); - if (!is_object($log)) return false; + if (! is_object($log)) { + return false; + } + return true; } } diff --git a/app/Services/InviteService.php b/app/Services/InviteService.php index ace8221..7383707 100644 --- a/app/Services/InviteService.php +++ b/app/Services/InviteService.php @@ -16,13 +16,14 @@ public function generateToken(): string { $random = Str::random(60); $time = Carbon::now(); - return $random . $time->toDateTimeLocalString(); + + return $random.$time->toDateTimeLocalString(); } public function invite($name, $email, $role_id, $user_id): bool { $token = $this->generateToken(); - $url = config('frontend.url') . '/register/' . $token . '?email=' . $email . '&name=' . urlencode($name); + $url = config('frontend.url').'/register/'.$token.'?email='.$email.'&name='.urlencode($name); $user = InviteToken::create([ 'name' => $name, @@ -30,11 +31,14 @@ public function invite($name, $email, $role_id, $user_id): bool 'role_id' => $role_id, 'token' => $token, 'tokenExpires' => Carbon::now()->addDays(5), - 'invitedUserId' => $user_id + 'invitedUserId' => $user_id, ]); - if (!$user) return false; + if (! $user) { + return false; + } // send an email notifying that you are invited Mail::to($email)->send(new InviteCreated($url)); + return true; } @@ -46,13 +50,15 @@ public static function invitedList(): Collection public function resendInvite($email): bool { $user = InviteToken::where('email', $email)->first(); - if (!$user) return false; + if (! $user) { + return false; + } //if user exists then generate new token and email $token = $this->generateToken(); - $url = config('frontend.url') . '/register/' . $token . '?email=' . $email . '&name=' . urlencode($user->name); + $url = config('frontend.url').'/register/'.$token.'?email='.$email.'&name='.urlencode($user->name); $user->forceFill([ - 'token' => $token + 'token' => $token, ]); $user->save(); Mail::to($email)->send(new ReInvite($url)); @@ -63,10 +69,13 @@ public function resendInvite($email): bool public static function revokeInvite($id): bool { $user = InviteToken::where('id', $id)->first(); - if (!$user) return false; + if (! $user) { + return false; + } //if users exists then delete their invite $user->delete(); + return true; } } diff --git a/app/Services/ProjectService.php b/app/Services/ProjectService.php index db381df..794e5f4 100644 --- a/app/Services/ProjectService.php +++ b/app/Services/ProjectService.php @@ -4,7 +4,7 @@ use App\Models\Project; use App\Models\UserProject; -use \Exception; +use Exception; class ProjectService { @@ -18,7 +18,10 @@ public static function addProject(array $validatedAddProject): bool $userproject->project_id = $log->id; $userproject->save(); - if (!is_object($log)) return false; + if (! is_object($log)) { + return false; + } + return true; } @@ -34,16 +37,19 @@ public static function checkProjectIdExists($id) { $user = Project::where('id', $id)->first(); - if (!$user) return false; + if (! $user) { + return false; + } return true; } + public function removeProject(int $id): void { - $project = Project::where('id' , $id)->first(); - if(!$project){ - throw new Exception("Project With this Id doesnt exist",); - } - $project->delete(); + $project = Project::where('id', $id)->first(); + if (! $project) { + throw new Exception('Project With this Id doesnt exist', ); + } + $project->delete(); } } diff --git a/app/Services/TimeLogService.php b/app/Services/TimeLogService.php index ea81bc4..91e1026 100644 --- a/app/Services/TimeLogService.php +++ b/app/Services/TimeLogService.php @@ -19,20 +19,20 @@ public static function viewTotalTimeLogs($id) public static function viewPaginateTimeLogs(int $id, int $size) { - return User::find($id)->timeLogs()->paginate($size); - - + return User::find($id)->timeLogs()->paginate($size); } public static function editTimeLog(array $validatedEditLog, $id): bool { - // after validation find the time log - $log = TimeLog::where('id', $id)->first(); - if (!$log) return false; + // after validation find the time log + $log = TimeLog::where('id', $id)->first(); + if (! $log) { + return false; + } // if time log exists then update the details $log->update($validatedEditLog); - + $log->save(); return true; @@ -41,10 +41,12 @@ public static function editTimeLog(array $validatedEditLog, $id): bool public static function removeLog($id): bool { $log = TimeLog::where('id', $id)->first(); - if (!$log) return false; + if (! $log) { + return false; + } //if log exists then delete $log->delete(); + return true; } - } diff --git a/app/Services/UserService.php b/app/Services/UserService.php index d55b81e..5df19d4 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -2,21 +2,15 @@ namespace App\Services; -use App\Mail\InviteCreated; use App\Models\InviteToken; use App\Models\Role; -use App\Models\UserRole; -use Illuminate\Auth\Events\PasswordReset; -use Illuminate\Support\Facades\Auth; use App\Models\User; -use http\Exception\InvalidArgumentException; +use App\Models\UserRole; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Password; -use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use Mockery\Exception; - class UserService { public static function saveUserData(array $validatedUserRegister) @@ -24,7 +18,7 @@ public static function saveUserData(array $validatedUserRegister) $invitedUser = InviteToken::where('email', $validatedUserRegister['email'])->first(); $check = Hash::check($validatedUserRegister['token'], $invitedUser->token); - if (!$check) { + if (! $check) { throw new Exception('Please provide a valid token'); } @@ -34,16 +28,17 @@ public static function saveUserData(array $validatedUserRegister) 'role_id' => $invitedUser['role_id'], ]); $invitedUser->delete(); + return $result; } public static function getUserWithCreds(array $validatedUserCreds) { - $user = User::where('email', $validatedUserCreds['email'])->first(); - if (!$user || !Hash::check($validatedUserCreds['password'], $user->password)) { + if (! $user || ! Hash::check($validatedUserCreds['password'], $user->password)) { throw new Exception('Email address or password is invalid'); } + return $user; } @@ -54,9 +49,10 @@ public static function getUser($cred, $rules) throw new Exception($validateReq->errors()); } $user = User::where('email', $cred['email'])->first(); - if (!$user) { + if (! $user) { throw new Exception('User does not exist'); } + return $user; } @@ -68,7 +64,10 @@ public static function roles() public static function forgotPassword($validatedForgetPass): bool { $status = Password::sendResetLink($validatedForgetPass); - if ($status === Password::INVALID_USER) return false; + if ($status === Password::INVALID_USER) { + return false; + } + return true; } @@ -78,7 +77,10 @@ public static function resetPassword(array $validatedResetPass): bool $user->forceFill(['password' => $password])->setRememberToken(Str::random(60)); $user->save(); }); - if ($status === Password::INVALID_TOKEN) return false; + if ($status === Password::INVALID_TOKEN) { + return false; + } + return true; } @@ -86,7 +88,7 @@ public static function checkUserIdExists($id) { $user = User::where('id', $id)->first(); - if (!$user) { + if (! $user) { return false; } diff --git a/composer.json b/composer.json index 5a54a33..dcece2c 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "require": { "php": "^8.0.2", "doctrine/dbal": "^3.4", + "friendsofphp/php-cs-fixer": "*", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.2", "laravel/sanctum": "^2.14.1", @@ -46,7 +47,8 @@ ], "post-create-project-cmd": [ "@php artisan key:generate --ansi" - ] + ], + "lint:fix": "php-cs-fixer fix ./ -vvv --show-progress=dots --config=.php-cs-fixer.php" }, "extra": { "laravel": { diff --git a/composer.lock b/composer.lock index 81ba0a3..7c3542e 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": "a30b14cc537b87d1c2915fe7a5ccca78", + "content-hash": "53d446f585b7ed0abc045ec83774744c", "packages": [ { "name": "brick/math", @@ -66,6 +66,224 @@ ], "time": "2021-08-15T20:50:18+00:00" }, + { + "name": "composer/pcre", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/composer/pcre.git", + "reference": "4bff79ddd77851fe3cdd11616ed3f92841ba5bd2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/pcre/zipball/4bff79ddd77851fe3cdd11616ed3f92841ba5bd2", + "reference": "4bff79ddd77851fe3cdd11616ed3f92841ba5bd2", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.3", + "phpstan/phpstan-strict-rules": "^1.1", + "symfony/phpunit-bridge": "^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Pcre\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "PCRE wrapping library that offers type-safe preg_* replacements.", + "keywords": [ + "PCRE", + "preg", + "regex", + "regular expression" + ], + "support": { + "issues": "https://github.com/composer/pcre/issues", + "source": "https://github.com/composer/pcre/tree/3.1.0" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2022-11-17T09:50:14+00:00" + }, + { + "name": "composer/semver", + "version": "3.3.2", + "source": { + "type": "git", + "url": "https://github.com/composer/semver.git", + "reference": "3953f23262f2bff1919fc82183ad9acb13ff62c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/semver/zipball/3953f23262f2bff1919fc82183ad9acb13ff62c9", + "reference": "3953f23262f2bff1919fc82183ad9acb13ff62c9", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.4", + "symfony/phpunit-bridge": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Semver\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "Semver library that offers utilities, version constraint parsing and validation.", + "keywords": [ + "semantic", + "semver", + "validation", + "versioning" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/semver/issues", + "source": "https://github.com/composer/semver/tree/3.3.2" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2022-04-01T19:23:25+00:00" + }, + { + "name": "composer/xdebug-handler", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/composer/xdebug-handler.git", + "reference": "ced299686f41dce890debac69273b47ffe98a40c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/ced299686f41dce890debac69273b47ffe98a40c", + "reference": "ced299686f41dce890debac69273b47ffe98a40c", + "shasum": "" + }, + "require": { + "composer/pcre": "^1 || ^2 || ^3", + "php": "^7.2.5 || ^8.0", + "psr/log": "^1 || ^2 || ^3" + }, + "require-dev": { + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-strict-rules": "^1.1", + "symfony/phpunit-bridge": "^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Composer\\XdebugHandler\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "John Stevenson", + "email": "john-stevenson@blueyonder.co.uk" + } + ], + "description": "Restarts a process without Xdebug.", + "keywords": [ + "Xdebug", + "performance" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/xdebug-handler/issues", + "source": "https://github.com/composer/xdebug-handler/tree/3.0.3" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2022-02-25T21:32:43+00:00" + }, { "name": "dflydev/dot-access-data", "version": "v3.0.1", @@ -141,6 +359,82 @@ }, "time": "2021-08-13T13:06:58+00:00" }, + { + "name": "doctrine/annotations", + "version": "1.14.3", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "fb0d71a7393298a7b232cbf4c8b1f73f3ec3d5af" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/fb0d71a7393298a7b232cbf4c8b1f73f3ec3d5af", + "reference": "fb0d71a7393298a7b232cbf4c8b1f73f3ec3d5af", + "shasum": "" + }, + "require": { + "doctrine/lexer": "^1 || ^2", + "ext-tokenizer": "*", + "php": "^7.1 || ^8.0", + "psr/cache": "^1 || ^2 || ^3" + }, + "require-dev": { + "doctrine/cache": "^1.11 || ^2.0", + "doctrine/coding-standard": "^9 || ^10", + "phpstan/phpstan": "~1.4.10 || ^1.8.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "symfony/cache": "^4.4 || ^5.4 || ^6", + "vimeo/psalm": "^4.10" + }, + "suggest": { + "php": "PHP 8.0 or higher comes with attributes, a native replacement for annotations" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "https://www.doctrine-project.org/projects/annotations.html", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "support": { + "issues": "https://github.com/doctrine/annotations/issues", + "source": "https://github.com/doctrine/annotations/tree/1.14.3" + }, + "time": "2023-02-01T09:20:38+00:00" + }, { "name": "doctrine/cache", "version": "2.2.0", @@ -775,6 +1069,95 @@ ], "time": "2021-10-11T09:18:27+00:00" }, + { + "name": "friendsofphp/php-cs-fixer", + "version": "v3.13.2", + "source": { + "type": "git", + "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", + "reference": "3952f08a81bd3b1b15e11c3de0b6bf037faa8496" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/3952f08a81bd3b1b15e11c3de0b6bf037faa8496", + "reference": "3952f08a81bd3b1b15e11c3de0b6bf037faa8496", + "shasum": "" + }, + "require": { + "composer/semver": "^3.2", + "composer/xdebug-handler": "^3.0.3", + "doctrine/annotations": "^1.13", + "ext-json": "*", + "ext-tokenizer": "*", + "php": "^7.4 || ^8.0", + "sebastian/diff": "^4.0", + "symfony/console": "^5.4 || ^6.0", + "symfony/event-dispatcher": "^5.4 || ^6.0", + "symfony/filesystem": "^5.4 || ^6.0", + "symfony/finder": "^5.4 || ^6.0", + "symfony/options-resolver": "^5.4 || ^6.0", + "symfony/polyfill-mbstring": "^1.23", + "symfony/polyfill-php80": "^1.25", + "symfony/polyfill-php81": "^1.25", + "symfony/process": "^5.4 || ^6.0", + "symfony/stopwatch": "^5.4 || ^6.0" + }, + "require-dev": { + "justinrainbow/json-schema": "^5.2", + "keradus/cli-executor": "^2.0", + "mikey179/vfsstream": "^1.6.10", + "php-coveralls/php-coveralls": "^2.5.2", + "php-cs-fixer/accessible-object": "^1.1", + "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.2", + "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.2.1", + "phpspec/prophecy": "^1.15", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^9.5", + "phpunitgoodpractices/polyfill": "^1.6", + "phpunitgoodpractices/traits": "^1.9.2", + "symfony/phpunit-bridge": "^6.0", + "symfony/yaml": "^5.4 || ^6.0" + }, + "suggest": { + "ext-dom": "For handling output formats in XML", + "ext-mbstring": "For handling non-UTF8 characters." + }, + "bin": [ + "php-cs-fixer" + ], + "type": "application", + "autoload": { + "psr-4": { + "PhpCsFixer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Dariusz RumiƄski", + "email": "dariusz.ruminski@gmail.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "support": { + "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.13.2" + }, + "funding": [ + { + "url": "https://github.com/keradus", + "type": "github" + } + ], + "time": "2023-01-02T23:53:50+00:00" + }, { "name": "fruitcake/php-cors", "version": "v1.2.0", @@ -3213,29 +3596,95 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "MIT" + ], + "description": "A PHP library for generating and working with universally unique identifiers (UUIDs).", + "keywords": [ + "guid", + "identifier", + "uuid" + ], + "support": { + "issues": "https://github.com/ramsey/uuid/issues", + "source": "https://github.com/ramsey/uuid/tree/4.2.3" + }, + "funding": [ + { + "url": "https://github.com/ramsey", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/ramsey/uuid", + "type": "tidelift" + } + ], + "time": "2021-09-25T23:10:38+00:00" + }, + { + "name": "sebastian/diff", + "version": "4.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d", + "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" ], - "description": "A PHP library for generating and working with universally unique identifiers (UUIDs).", + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", "keywords": [ - "guid", - "identifier", - "uuid" + "diff", + "udiff", + "unidiff", + "unified diff" ], "support": { - "issues": "https://github.com/ramsey/uuid/issues", - "source": "https://github.com/ramsey/uuid/tree/4.2.3" + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4" }, "funding": [ { - "url": "https://github.com/ramsey", + "url": "https://github.com/sebastianbergmann", "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/ramsey/uuid", - "type": "tidelift" } ], - "time": "2021-09-25T23:10:38+00:00" + "time": "2020-10-26T13:10:38+00:00" }, { "name": "symfony/console", @@ -3697,6 +4146,69 @@ ], "time": "2021-07-15T12:33:35+00:00" }, + { + "name": "symfony/filesystem", + "version": "v6.2.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "82b6c62b959f642d000456f08c6d219d749215b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/82b6c62b959f642d000456f08c6d219d749215b3", + "reference": "82b6c62b959f642d000456f08c6d219d749215b3", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides basic utilities for the filesystem", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/filesystem/tree/v6.2.7" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-02-14T08:44:56+00:00" + }, { "name": "symfony/finder", "version": "v6.0.3", @@ -4094,6 +4606,73 @@ ], "time": "2022-01-02T09:55:41+00:00" }, + { + "name": "symfony/options-resolver", + "version": "v6.2.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/options-resolver.git", + "reference": "aa0e85b53bbb2b4951960efd61d295907eacd629" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/aa0e85b53bbb2b4951960efd61d295907eacd629", + "reference": "aa0e85b53bbb2b4951960efd61d295907eacd629", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.1|^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\OptionsResolver\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an improved replacement for the array_replace PHP function", + "homepage": "https://symfony.com", + "keywords": [ + "config", + "configuration", + "options" + ], + "support": { + "source": "https://github.com/symfony/options-resolver/tree/v6.2.7" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-02-14T08:44:56+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.25.0", @@ -4980,6 +5559,68 @@ ], "time": "2021-11-04T17:53:12+00:00" }, + { + "name": "symfony/stopwatch", + "version": "v6.2.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/stopwatch.git", + "reference": "f3adc98c1061875dd2edcd45e5b04e63d0e29f8f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/f3adc98c1061875dd2edcd45e5b04e63d0e29f8f", + "reference": "f3adc98c1061875dd2edcd45e5b04e63d0e29f8f", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/service-contracts": "^1|^2|^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Stopwatch\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides a way to profile code", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/stopwatch/tree/v6.2.7" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-02-14T08:44:56+00:00" + }, { "name": "symfony/string", "version": "v6.0.3", @@ -7117,72 +7758,6 @@ ], "time": "2020-10-26T15:52:27+00:00" }, - { - "name": "sebastian/diff", - "version": "4.0.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d", - "shasum": "" - }, - "require": { - "php": ">=7.3" - }, - "require-dev": { - "phpunit/phpunit": "^9.3", - "symfony/process": "^4.2 || ^5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - } - ], - "description": "Diff implementation", - "homepage": "https://github.com/sebastianbergmann/diff", - "keywords": [ - "diff", - "udiff", - "unidiff", - "unified diff" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2020-10-26T13:10:38+00:00" - }, { "name": "sebastian/environment", "version": "5.1.3", @@ -8126,5 +8701,5 @@ "php": "^8.0.2" }, "platform-dev": [], - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.3.0" } diff --git a/config/frontend.php b/config/frontend.php index 5f3a278..e565e25 100644 --- a/config/frontend.php +++ b/config/frontend.php @@ -1,5 +1,5 @@ env('APP_FRONTEND_URL') + 'url' => env('APP_FRONTEND_URL'), ]; diff --git a/config/sanctum.php b/config/sanctum.php index 82b6e1a..681d393 100644 --- a/config/sanctum.php +++ b/config/sanctum.php @@ -17,7 +17,7 @@ 'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( '%s%s', - 'https://frontendbootcamp.proshore.eu','http://localhost:3000', + 'https://frontendbootcamp.proshore.eu', 'http://localhost:3000', Sanctum::currentApplicationUrlWithPort() ))), 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 fa38e32..f6f4a8c 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 fd235f8..bd07c85 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_24_063305_create_roles_table.php b/database/migrations/2022_03_24_063305_create_roles_table.php index 81f1467..58d5da7 100644 --- a/database/migrations/2022_03_24_063305_create_roles_table.php +++ b/database/migrations/2022_03_24_063305_create_roles_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_24_111817_create_user_roles_table.php b/database/migrations/2022_03_24_111817_create_user_roles_table.php index 5f98dd6..a79a461 100644 --- a/database/migrations/2022_03_24_111817_create_user_roles_table.php +++ b/database/migrations/2022_03_24_111817_create_user_roles_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_05_15_031617_create_projects_table.php b/database/migrations/2022_05_15_031617_create_projects_table.php index 17fc3c6..86aa14b 100644 --- a/database/migrations/2022_05_15_031617_create_projects_table.php +++ b/database/migrations/2022_05_15_031617_create_projects_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_05_15_033637_create_user_projects_table.php b/database/migrations/2022_05_15_033637_create_user_projects_table.php index 4a052f7..0a6c6d6 100644 --- a/database/migrations/2022_05_15_033637_create_user_projects_table.php +++ b/database/migrations/2022_05_15_033637_create_user_projects_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_05_25_112945_create_clients_table.php b/database/migrations/2022_05_25_112945_create_clients_table.php index a4b23b3..bba6bdd 100644 --- a/database/migrations/2022_05_25_112945_create_clients_table.php +++ b/database/migrations/2022_05_25_112945_create_clients_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_08_31_135013_change_role_id_type_invite_tokens_table.php b/database/migrations/2022_08_31_135013_change_role_id_type_invite_tokens_table.php index 4ad0e29..ecab4d6 100644 --- a/database/migrations/2022_08_31_135013_change_role_id_type_invite_tokens_table.php +++ b/database/migrations/2022_08_31_135013_change_role_id_type_invite_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. * @@ -28,7 +27,6 @@ public function up() */ public function down() { - Schema::table('invite_tokens', function (Blueprint $table) { $table->dropForeign(['role_id']); }); @@ -36,6 +34,5 @@ public function down() Schema::table('invite_tokens', function (Blueprint $table) { $table->integer('role_id')->unsigned()->change(); }); - } }; diff --git a/database/migrations/2022_08_31_152752_change_client_id_type_projects_table.php b/database/migrations/2022_08_31_152752_change_client_id_type_projects_table.php index 931b2fb..1113731 100644 --- a/database/migrations/2022_08_31_152752_change_client_id_type_projects_table.php +++ b/database/migrations/2022_08_31_152752_change_client_id_type_projects_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. * @@ -19,7 +18,6 @@ public function up() ->onDelete('cascade') ->onUpdate('cascade'); }); - } /** @@ -29,7 +27,6 @@ public function up() */ public function down() { - Schema::table('projects', function (Blueprint $table) { $table->dropForeign(['client_id']); }); @@ -37,6 +34,5 @@ public function down() Schema::table('projects', function (Blueprint $table) { $table->integer('client_id')->change(); }); - } }; diff --git a/database/migrations/2022_08_31_153415_change_user_id_project_id_type_user_projects_table.php b/database/migrations/2022_08_31_153415_change_user_id_project_id_type_user_projects_table.php index c11a917..ad26d4b 100644 --- a/database/migrations/2022_08_31_153415_change_user_id_project_id_type_user_projects_table.php +++ b/database/migrations/2022_08_31_153415_change_user_id_project_id_type_user_projects_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. * @@ -13,7 +12,6 @@ */ public function up() { - Schema::table('user_projects', function (Blueprint $table) { $table->foreignId('user_id')->nullable()->change() ->constrained() @@ -24,7 +22,6 @@ public function up() ->onDelete('cascade') ->onUpdate('cascade'); }); - } /** @@ -34,7 +31,6 @@ public function up() */ public function down() { - Schema::table('user_projects', function (Blueprint $table) { $table->dropForeign(['user_id']); $table->dropForeign(['project_id']); @@ -44,6 +40,5 @@ public function down() $table->integer('user_id')->unsigned()->nullable()->change(); $table->integer('project_id')->unsigned()->nullable()->change(); }); - } }; diff --git a/database/migrations/2022_08_31_154447_change_user_id_type_project_id_type_time_logs_table.php b/database/migrations/2022_08_31_154447_change_user_id_type_project_id_type_time_logs_table.php index bf1b4a9..f6d36a3 100644 --- a/database/migrations/2022_08_31_154447_change_user_id_type_project_id_type_time_logs_table.php +++ b/database/migrations/2022_08_31_154447_change_user_id_type_project_id_type_time_logs_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. * @@ -13,7 +12,6 @@ */ public function up() { - Schema::table('time_logs', function (Blueprint $table) { $table->foreignId('user_id')->change() ->constrained() @@ -24,7 +22,6 @@ public function up() ->onDelete('cascade') ->onUpdate('cascade'); }); - } /** @@ -34,7 +31,6 @@ public function up() */ public function down() { - Schema::table('time_logs', function (Blueprint $table) { $table->dropForeign(['user_id']); $table->dropForeign(['project_id']); @@ -44,6 +40,5 @@ public function down() $table->integer('user_id')->unsigned()->change(); $table->integer('project_id')->unsigned()->change(); }); - } }; diff --git a/database/migrations/2022_08_31_154930_change_user_id_type_role_id_type_user_roles_table.php b/database/migrations/2022_08_31_154930_change_user_id_type_role_id_type_user_roles_table.php index 8c716b3..26d6ff8 100644 --- a/database/migrations/2022_08_31_154930_change_user_id_type_role_id_type_user_roles_table.php +++ b/database/migrations/2022_08_31_154930_change_user_id_type_role_id_type_user_roles_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. * @@ -13,7 +12,6 @@ */ public function up() { - Schema::table('user_roles', function (Blueprint $table) { $table->foreignId('user_id')->nullable()->change() ->constrained() @@ -24,7 +22,6 @@ public function up() ->onDelete('cascade') ->onUpdate('cascade'); }); - } /** @@ -34,7 +31,6 @@ public function up() */ public function down() { - Schema::table('user_roles', function (Blueprint $table) { $table->dropForeign(['user_id']); $table->dropForeign(['role_id']); @@ -44,7 +40,5 @@ public function down() $table->integer('user_id')->unsigned()->nullable()->change(); $table->integer('role_id')->unsigned()->default(1)->change(); }); - - } }; diff --git a/database/migrations/2022_09_07_163357_add_column_to_projects_table.php b/database/migrations/2022_09_07_163357_add_column_to_projects_table.php index 8958a97..9e2fe48 100644 --- a/database/migrations/2022_09_07_163357_add_column_to_projects_table.php +++ b/database/migrations/2022_09_07_163357_add_column_to_projects_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. * @@ -26,7 +25,7 @@ public function up() public function down() { Schema::table('projects', function (Blueprint $table) { - $table->string('project_color_code'); + $table->string('project_color_code'); }); } }; diff --git a/database/migrations/2022_10_18_152510_add_column_to_time_logs_table.php b/database/migrations/2022_10_18_152510_add_column_to_time_logs_table.php index ec0af79..3b022c1 100644 --- a/database/migrations/2022_10_18_152510_add_column_to_time_logs_table.php +++ b/database/migrations/2022_10_18_152510_add_column_to_time_logs_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_10_18_181143_add_start_time_end_time_column_to_time_logs_table.php b/database/migrations/2022_10_18_181143_add_start_time_end_time_column_to_time_logs_table.php index 03c3fad..45fde91 100644 --- a/database/migrations/2022_10_18_181143_add_start_time_end_time_column_to_time_logs_table.php +++ b/database/migrations/2022_10_18_181143_add_start_time_end_time_column_to_time_logs_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. * @@ -27,7 +26,7 @@ public function up() public function down() { Schema::table('time_logs', function (Blueprint $table) { - $table->dropColumn('started_time')->nullable( ); + $table->dropColumn('started_time')->nullable(); $table->dropColumn('ended_time')->nullable(); }); } diff --git a/database/migrations/2022_10_21_062440_change_start_date_and_end_date_from_datetime_to_date.php b/database/migrations/2022_10_21_062440_change_start_date_and_end_date_from_datetime_to_date.php index 8a06a9e..7fd98cc 100644 --- a/database/migrations/2022_10_21_062440_change_start_date_and_end_date_from_datetime_to_date.php +++ b/database/migrations/2022_10_21_062440_change_start_date_and_end_date_from_datetime_to_date.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/seeders/CreateRolesSeeder.php b/database/seeders/CreateRolesSeeder.php index ba72212..841adf9 100644 --- a/database/seeders/CreateRolesSeeder.php +++ b/database/seeders/CreateRolesSeeder.php @@ -5,7 +5,6 @@ use App\Models\Role; use App\Models\User; use App\Models\UserRole; -use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; class CreateRolesSeeder extends Seeder diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 846c193..f7503a8 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -2,7 +2,6 @@ namespace Database\Seeders; -use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder diff --git a/routes/api.php b/routes/api.php index e903ad9..615617a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,14 +1,14 @@ group(function (){ +Route::middleware(['auth:sanctum', 'user.status'])->group(function () { Route::controller(UserController::class)->prefix('user')->group(function () { Route::get('me', 'viewMe'); Route::patch('edit', 'updateMe'); @@ -49,7 +49,7 @@ Route::patch('{id}', 'editActivity'); Route::delete('{id}', 'removeActivity'); }); - Route::middleware(['isAdmin'])->group(function (){ + Route::middleware(['isAdmin'])->group(function () { Route::controller(AdminController::class)->prefix('admin')->group(function () { Route::get('users', 'viewAllUsers'); Route::post('change-roles', 'assignRoles'); @@ -68,16 +68,15 @@ Route::patch('{id}', 'updateActivity'); Route::patch('project-status/{id}', 'updateProjectStatus'); Route::delete('{id}', 'deleteProject'); - }); Route::controller(ClientController::class)->prefix('client')->group(function () { Route::post('/', 'addActivity'); Route::get('/', 'viewAllClients'); }); - Route::middleware(['project.status'])->group(function () { - Route::controller(ProjectController::class)->prefix('project')->group(function (){ - Route::patch('billable-status/{id}', 'updateBillableStatus'); + Route::middleware(['project.status'])->group(function () { + Route::controller(ProjectController::class)->prefix('project')->group(function () { + Route::patch('billable-status/{id}', 'updateBillableStatus'); + }); }); }); - }); }); diff --git a/routes/web.php b/routes/web.php index 821b5ba..abe4ea2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -16,4 +16,3 @@ Route::get('/', function () { return view('welcome'); })->name('home'); - diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index 78ccc21..627a8a0 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature; -use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; class ExampleTest extends TestCase