From 750239328be0acabaf7d448140b11c8b5625f40e Mon Sep 17 00:00:00 2001 From: Tatevik Date: Sun, 15 Dec 2024 21:43:12 +0400 Subject: [PATCH] ISSUE-337: fix phpcs --- src/Controller/ListController.php | 270 +++++++++++++----------- src/Controller/SessionController.php | 70 +++--- src/Controller/SubscriberController.php | 83 +++++--- src/PhpListRestBundle.php | 17 +- 4 files changed, 244 insertions(+), 196 deletions(-) diff --git a/src/Controller/ListController.php b/src/Controller/ListController.php index a58c0de..ccac0f9 100644 --- a/src/Controller/ListController.php +++ b/src/Controller/ListController.php @@ -47,50 +47,63 @@ public function __construct( #[Route('/lists', name: 'get_lists', methods: ['GET'])] #[OA\Get( - path: "/lists", - description: "Returns a JSON list of all subscriber lists.", - summary: "Gets a list of all subscriber lists.", - tags: ["lists"], + path: '/lists', + description: 'Returns a JSON list of all subscriber lists.', + summary: 'Gets a list of all subscriber lists.', + tags: ['lists'], parameters: [ new OA\Parameter( - name: "session", - description: "Session ID obtained from authentication", - in: "header", + name: 'session', + description: 'Session ID obtained from authentication', + in: 'header', required: true, schema: new OA\Schema( - type: "string" + type: 'string' ) ) ], responses: [ new OA\Response( response: 200, - description: "Success", + description: 'Success', content: new OA\JsonContent( - type: "array", + type: 'array', items: new OA\Items( properties: [ - new OA\Property(property: "name", type: "string", example: "News"), - new OA\Property(property: "description", type: "string", example: "News (and some fun stuff)"), - new OA\Property(property: "creation_date", type: "string", format: "date-time", example: "2016-06-22T15:01:17+00:00"), - new OA\Property(property: "list_position", type: "integer", example: 12), - new OA\Property(property: "subject_prefix", type: "string", example: "phpList"), - new OA\Property(property: "public", type: "boolean", example: true), - new OA\Property(property: "category", type: "string", example: "news"), - new OA\Property(property: "id", type: "integer", example: 1) + new OA\Property(property: 'name', type: 'string', example: 'News'), + new OA\Property( + property: 'description', + type: 'string', + example: 'News (and some fun stuff)' + ), + new OA\Property( + property: 'creation_date', + type: 'string', + format: 'date-time', + example: '2016-06-22T15:01:17+00:00' + ), + new OA\Property(property: 'list_position', type: 'integer', example: 12), + new OA\Property(property: 'subject_prefix', type: 'string', example: 'phpList'), + new OA\Property(property: 'public', type: 'boolean', example: true), + new OA\Property(property: 'category', type: 'string', example: 'news'), + new OA\Property(property: 'id', type: 'integer', example: 1) ], - type: "object" + type: 'object' ) ) ), new OA\Response( response: 403, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ - new OA\Property(property: "message", type: "string", example: "No valid session key was provided as basic auth password.") + new OA\Property( + property: 'message', + type: 'string', + example: 'No valid session key was provided as basic auth password.' + ) ], - type: "object" + type: 'object' ) ) ] @@ -108,70 +121,70 @@ public function getLists(Request $request): JsonResponse #[Route('/lists/{id}', name: 'get_list', methods: ['GET'])] #[OA\Get( - path: "/lists/{list}", - description: "Returns a single subscriber list with specified ID.", - summary: "Gets a subscriber list.", - tags: ["lists"], + path: '/lists/{list}', + description: 'Returns a single subscriber list with specified ID.', + summary: 'Gets a subscriber list.', + tags: ['lists'], parameters: [ new OA\Parameter( - name: "list", - description: "List ID", - in: "path", + name: 'list', + description: 'List ID', + in: 'path', required: true, - schema: new OA\Schema(type: "string") + schema: new OA\Schema(type: 'string') ), new OA\Parameter( - name: "session", - description: "Session ID obtained from authentication", - in: "header", + name: 'session', + description: 'Session ID obtained from authentication', + in: 'header', required: true, - schema: new OA\Schema(type: "string") + schema: new OA\Schema(type: 'string') ) ], responses: [ new OA\Response( response: 200, - description: "Success", + description: 'Success', content: new OA\JsonContent( - type: "object", + type: 'object', example: [ - "name" => "News", - "description" => "News (and some fun stuff)", - "creation_date" => "2016-06-22T15:01:17+00:00", - "list_position" => 12, - "subject_prefix" => "phpList", - "public" => true, - "category" => "news", - "id" => 1 + 'name' => 'News', + 'description' => 'News (and some fun stuff)', + 'creation_date' => '2016-06-22T15:01:17+00:00', + 'list_position' => 12, + 'subject_prefix' => 'phpList', + 'public' => true, + 'category' => 'news', + 'id' => 1 ] ) ), new OA\Response( response: 403, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ new OA\Property( - property: "message", - type: "string", - example: "No valid session key was provided as basic auth password." + property: 'message', + type: 'string', + example: 'No valid session key was provided as basic auth password.' ) ], - type: "object" + type: 'object' ) ), new OA\Response( response: 404, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ new OA\Property( - property: "message", - type: "string", - example: "There is no list with that ID." + property: 'message', + type: 'string', + example: 'There is no list with that ID.' ) ], - type: "object" + type: 'object' ) ) ] @@ -188,57 +201,57 @@ public function getList(Request $request, #[MapEntity(mapping: ['id' => 'id'])] #[Route('/lists/{id}', name: 'delete_list', methods: ['DELETE'])] #[OA\Delete( - path: "/lists/{list}", - description: "Deletes a single subscriber list.", - summary: "Deletes a list.", - tags: ["lists"], + path: '/lists/{list}', + description: 'Deletes a single subscriber list.', + summary: 'Deletes a list.', + tags: ['lists'], parameters: [ new OA\Parameter( - name: "session", - description: "Session ID", - in: "header", + name: 'session', + description: 'Session ID', + in: 'header', required: true, - schema: new OA\Schema(type: "string") + schema: new OA\Schema(type: 'string') ), new OA\Parameter( - name: "list", - description: "List ID", - in: "path", + name: 'list', + description: 'List ID', + in: 'path', required: true, - schema: new OA\Schema(type: "string") + schema: new OA\Schema(type: 'string') ) ], responses: [ new OA\Response( response: 200, - description: "Success" + description: 'Success' ), new OA\Response( response: 403, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ new OA\Property( - property: "message", - type: "string", - example: "No valid session key was provided as basic auth password or You do not have access to this session." + property: 'message', + type: 'string', + example: 'No valid session key was provided.' ) ], - type: "object" + type: 'object' ) ), new OA\Response( response: 404, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ new OA\Property( - property: "message", - type: "string", - example: "There is no session with that ID." + property: 'message', + type: 'string', + example: 'There is no session with that ID.' ) ], - type: "object" + type: 'object' ) ) ] @@ -256,56 +269,69 @@ public function deleteList( #[Route('/lists/{id}/members', name: 'get_subscriber_from_list', methods: ['GET'])] #[OA\Get( - path: "/lists/{list}/members", - description: "Returns a JSON list of all subscribers for a subscriber list.", - summary: "Gets a list of all subscribers (members) of a subscriber list.", - tags: ["lists"], + path: '/lists/{list}/members', + description: 'Returns a JSON list of all subscribers for a subscriber list.', + summary: 'Gets a list of all subscribers (members) of a subscriber list.', + tags: ['lists'], parameters: [ new OA\Parameter( - name: "session", - description: "Session ID obtained from authentication", - in: "header", + name: 'session', + description: 'Session ID obtained from authentication', + in: 'header', required: true, - schema: new OA\Schema(type: "string") + schema: new OA\Schema(type: 'string') ), new OA\Parameter( - name: "list", - description: "List ID", - in: "path", + name: 'list', + description: 'List ID', + in: 'path', required: true, - schema: new OA\Schema(type: "string") + schema: new OA\Schema(type: 'string') ) ], responses: [ new OA\Response( response: 200, - description: "Success", + description: 'Success', content: new OA\JsonContent( - type: "array", + type: 'array', items: new OA\Items( properties: [ - new OA\Property(property: "creation_date", type: "string", format: "date-time", example: "2016-07-22T15:01:17+00:00"), - new OA\Property(property: "email", type: "string", example: "oliver@example.com"), - new OA\Property(property: "confirmed", type: "boolean", example: true), - new OA\Property(property: "blacklisted", type: "boolean", example: true), - new OA\Property(property: "bounce_count", type: "integer", example: 17), - new OA\Property(property: "unique_id", type: "string", example: "95feb7fe7e06e6c11ca8d0c48cb46e89"), - new OA\Property(property: "html_email", type: "boolean", example: true), - new OA\Property(property: "disabled", type: "boolean", example: true), - new OA\Property(property: "id", type: "integer", example: 1) + new OA\Property( + property: 'creation_date', + type: 'string', + format: 'date-time', + example: '2016-07-22T15:01:17+00:00' + ), + new OA\Property(property: 'email', type: 'string', example: 'oliver@example.com'), + new OA\Property(property: 'confirmed', type: 'boolean', example: true), + new OA\Property(property: 'blacklisted', type: 'boolean', example: true), + new OA\Property(property: 'bounce_count', type: 'integer', example: 17), + new OA\Property( + property: 'unique_id', + type: 'string', + example: '95feb7fe7e06e6c11ca8d0c48cb46e89' + ), + new OA\Property(property: 'html_email', type: 'boolean', example: true), + new OA\Property(property: 'disabled', type: 'boolean', example: true), + new OA\Property(property: 'id', type: 'integer', example: 1) ], - type: "object" + type: 'object' ) ) ), new OA\Response( response: 403, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ - new OA\Property(property: "message", type: "string", example: "No valid session key was provided as basic auth password.") + new OA\Property( + property: 'message', + type: 'string', + example: 'No valid session key was provided as basic auth password.' + ) ], - type: "object" + type: 'object' ) ) ] @@ -327,43 +353,43 @@ public function getListMembers( #[Route('/lists/{id}/subscribers/count', name: 'get_subscribers_count_from_list', methods: ['GET'])] #[OA\Get( - path: "/lists/{list}/count", - description: "Returns a count of all subscribers in a given list.", - summary: "Gets the total number of subscribers of a list", - tags: ["lists"], + path: '/lists/{list}/count', + description: 'Returns a count of all subscribers in a given list.', + summary: 'Gets the total number of subscribers of a list', + tags: ['lists'], parameters: [ new OA\Parameter( - name: "session", - description: "Session ID obtained from authentication", - in: "header", + name: 'session', + description: 'Session ID obtained from authentication', + in: 'header', required: true, - schema: new OA\Schema(type: "string") + schema: new OA\Schema(type: 'string') ), new OA\Parameter( - name: "list", - description: "List ID", - in: "path", + name: 'list', + description: 'List ID', + in: 'path', required: true, - schema: new OA\Schema(type: "string") + schema: new OA\Schema(type: 'string') ) ], responses: [ new OA\Response( response: 200, - description: "Success" + description: 'Success' ), new OA\Response( response: 403, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ new OA\Property( - property: "message", - type: "string", - example: "No valid session key was provided as basic auth password." + property: 'message', + type: 'string', + example: 'No valid session key was provided as basic auth password.' ) ], - type: "object" + type: 'object' ) ) ] diff --git a/src/Controller/SessionController.php b/src/Controller/SessionController.php index 3b4c989..1c12dd0 100644 --- a/src/Controller/SessionController.php +++ b/src/Controller/SessionController.php @@ -54,48 +54,52 @@ public function __construct( */ #[Route('/sessions', name: 'create_session', methods: ['POST'])] #[OA\Post( - path: "/sessions", - description: "Given valid login data, this will generate a login token that will be valid for 1 hour.", - summary: "Log in or create new session.", + path: '/sessions', + description: 'Given valid login data, this will generate a login token that will be valid for 1 hour.', + summary: 'Log in or create new session.', requestBody: new OA\RequestBody( - description: "Pass session credentials", + description: 'Pass session credentials', required: true, content: new OA\JsonContent( - required: ["login_name", "password"], + required: ['login_name', 'password'], properties: [ - new OA\Property(property: "login_name", type: "string", format: "string", example: "admin"), - new OA\Property(property: "password", type: "string", format: "password", example: "eetIc/Gropvoc1") + new OA\Property(property: 'login_name', type: 'string', format: 'string', example: 'admin'), + new OA\Property(property: 'password', type: 'string', format: 'password', example: 'eetIc/Gropvoc1') ] ) ), - tags: ["sessions"], + tags: ['sessions'], responses: [ new OA\Response( response: 201, - description: "Success", + description: 'Success', content: new OA\JsonContent( properties: [ - new OA\Property(property: "id", type: "integer", example: 1234), - new OA\Property(property: "key", type: "string", example: "2cfe100561473c6cdd99c9e2f26fa974"), - new OA\Property(property: "expiry", type: "string", example: "2017-07-20T18:22:48+00:00") + new OA\Property(property: 'id', type: 'integer', example: 1234), + new OA\Property(property: 'key', type: 'string', example: '2cfe100561473c6cdd99c9e2f26fa974'), + new OA\Property(property: 'expiry', type: 'string', example: '2017-07-20T18:22:48+00:00') ] ) ), new OA\Response( response: 400, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ - new OA\Property(property: "message", type: "string", example: "Empty json, invalid data and or incomplete data") + new OA\Property( + property: 'message', + type: 'string', + example: 'Empty json, invalid data and or incomplete data' + ) ] ) ), new OA\Response( response: 401, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ - new OA\Property(property: "message", type: "string", example: "Not authorized.") + new OA\Property(property: 'message', type: 'string', example: 'Not authorized.') ] ) ) @@ -127,46 +131,46 @@ public function createSession(Request $request): JsonResponse */ #[Route('/sessions/{id}', name: 'delete_session', methods: ['DELETE'])] #[OA\Delete( - path: "/sessions/{session}", - description: "Delete the session passed as a parameter.", - summary: "Delete a session.", - tags: ["sessions"], + path: '/sessions/{session}', + description: 'Delete the session passed as a parameter.', + summary: 'Delete a session.', + tags: ['sessions'], parameters: [ new OA\Parameter( - name: "session", - description: "Session ID", - in: "path", + name: 'session', + description: 'Session ID', + in: 'path', required: true, - schema: new OA\Schema(type: "string") + schema: new OA\Schema(type: 'string') ) ], responses: [ new OA\Response( response: 200, - description: "Success" + description: 'Success' ), new OA\Response( response: 403, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ new OA\Property( - property: "message", - type: "string", - example: "No valid session key was provided as basic auth password or You do not have access to this session." + property: 'message', + type: 'string', + example: 'No valid session key was provided as basic auth password.' ) ] ) ), new OA\Response( response: 404, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ new OA\Property( - property: "message", - type: "string", - example: "There is no session with that ID." + property: 'message', + type: 'string', + example: 'There is no session with that ID.' ) ] ) diff --git a/src/Controller/SubscriberController.php b/src/Controller/SubscriberController.php index 4113742..3d9087b 100644 --- a/src/Controller/SubscriberController.php +++ b/src/Controller/SubscriberController.php @@ -39,75 +39,92 @@ public function __construct( #[Route('/subscribers', name: 'create_subscriber', methods: ['POST'])] #[OA\Post( - path: "/subscriber", - description: "Creates a new subscriber (if the provided data is valid and there is no subscriber with the given email address yet).", - summary: "Create a subscriber", + path: '/subscriber', + description: 'Creates a new subscriber (if there is no subscriber with the given email address yet).', + summary: 'Create a subscriber', requestBody: new OA\RequestBody( - description: "Pass session credentials", + description: 'Pass session credentials', required: true, content: new OA\JsonContent( - required: ["email"], + required: ['email'], properties: [ - new OA\Property(property: "email", type: "string", format: "string", example: "admin@example.com"), - new OA\Property(property: "confirmed", type: "boolean", example: false), - new OA\Property(property: "blacklisted", type: "boolean", example: false), - new OA\Property(property: "html_email", type: "boolean", example: false), - new OA\Property(property: "disabled", type: "boolean", example: false) + new OA\Property(property: 'email', type: 'string', format: 'string', example: 'admin@example.com'), + new OA\Property(property: 'confirmed', type: 'boolean', example: false), + new OA\Property(property: 'blacklisted', type: 'boolean', example: false), + new OA\Property(property: 'html_email', type: 'boolean', example: false), + new OA\Property(property: 'disabled', type: 'boolean', example: false) ] ) ), - tags: ["subscribers"], + tags: ['subscribers'], parameters: [ new OA\Parameter( - name: "session", - description: "Session ID obtained from authentication", - in: "header", + name: 'session', + description: 'Session ID obtained from authentication', + in: 'header', required: true, - schema: new OA\Schema(type: "string") + schema: new OA\Schema(type: 'string') ) ], responses: [ new OA\Response( response: 201, - description: "Success", + description: 'Success', content: new OA\JsonContent( properties: [ - new OA\Property(property: "creation_date", type: "string", format: "date-time", example: "2017-12-16T18:44:27+00:00"), - new OA\Property(property: "email", type: "string", example: "subscriber@example.com"), - new OA\Property(property: "confirmed", type: "boolean", example: false), - new OA\Property(property: "blacklisted", type: "boolean", example: false), - new OA\Property(property: "bounced", type: "integer", example: 0), - new OA\Property(property: "unique_id", type: "string", example: "69f4e92cf50eafca9627f35704f030f4"), - new OA\Property(property: "html_email", type: "boolean", example: false), - new OA\Property(property: "disabled", type: "boolean", example: false), - new OA\Property(property: "id", type: "integer", example: 1) + new OA\Property( + property: 'creation_date', + type: 'string', + format: 'date-time', + example: '2017-12-16T18:44:27+00:00' + ), + new OA\Property(property: 'email', type: 'string', example: 'subscriber@example.com'), + new OA\Property(property: 'confirmed', type: 'boolean', example: false), + new OA\Property(property: 'blacklisted', type: 'boolean', example: false), + new OA\Property(property: 'bounced', type: 'integer', example: 0), + new OA\Property( + property: 'unique_id', + type: 'string', + example: '69f4e92cf50eafca9627f35704f030f4' + ), + new OA\Property(property: 'html_email', type: 'boolean', example: false), + new OA\Property(property: 'disabled', type: 'boolean', example: false), + new OA\Property(property: 'id', type: 'integer', example: 1) ] ) ), new OA\Response( response: 403, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ - new OA\Property(property: "message", type: "string", example: "No valid session key was provided as basic auth password.") + new OA\Property( + property: 'message', + type: 'string', + example: 'No valid session key was provided as basic auth password.' + ) ] ) ), new OA\Response( response: 409, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ - new OA\Property(property: "message", type: "string", example: "This resource already exists.") + new OA\Property(property: 'message', type: 'string', example: 'This resource already exists.') ] ) ), new OA\Response( response: 422, - description: "Failure", + description: 'Failure', content: new OA\JsonContent( properties: [ - new OA\Property(property: "message", type: "string", example: "Some fields invalid: email, confirmed, html_email") + new OA\Property( + property: 'message', + type: 'string', + example: 'Some fields invalid: email, confirmed, html_email' + ) ] ) ) @@ -158,7 +175,9 @@ private function validateSubscriber(Request $request): void $booleanFields = ['confirmed', 'blacklisted', 'html_email', 'disabled']; foreach ($booleanFields as $fieldKey) { - if ($request->getPayload()->get($fieldKey) !== null && !is_bool($request->getPayload()->get($fieldKey))) { + if ($request->getPayload()->get($fieldKey) !== null + && !is_bool($request->getPayload()->get($fieldKey)) + ) { $invalidFields[] = $fieldKey; } } diff --git a/src/PhpListRestBundle.php b/src/PhpListRestBundle.php index 35e5bb4..5ff7622 100644 --- a/src/PhpListRestBundle.php +++ b/src/PhpListRestBundle.php @@ -7,27 +7,26 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; use OpenApi\Attributes as OA; - /** * This bundle provides the REST API for phpList. * * @author Oliver Klee */ #[OA\Info( - version: "1.0.0", - description: "This is the OpenAPI documentation for My API.", - title: "My API Documentation", + version: '1.0.0', + description: 'This is the OpenAPI documentation for My API.', + title: 'My API Documentation', contact: new OA\Contact( - email: "support@phplist.com" + email: 'support@phplist.com' ), license: new OA\License( - name: "AGPL-3.0-or-later", - url: "https://www.gnu.org/licenses/agpl.txt" + name: 'AGPL-3.0-or-later', + url: 'https://www.gnu.org/licenses/agpl.txt' ) )] #[OA\Server( - url: "https://www.phplist.com/api/v2", - description: "Production server" + url: 'https://www.phplist.com/api/v2', + description: 'Production server' )] class PhpListRestBundle extends Bundle {