From 67fda55af8041b1ca1a6343b78d736df616d1b45 Mon Sep 17 00:00:00 2001 From: Enrico Dias Date: Sat, 7 Aug 2021 23:20:15 -0300 Subject: [PATCH] auto formatting files --- README.md | 5 ++-- src/SmsDev.php | 40 +++++++++++++-------------- tests/ApiRequestsTest.php | 12 ++++---- tests/ApiResponseTest.php | 18 ++++++------ tests/PhoneNumberVerificationTest.php | 4 +-- tests/SmsDevMock.php | 4 +-- 6 files changed, 41 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 01924f8..caed656 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,6 @@ $SmsDev->setNumberValidation(false); // disables phone number validation Note that SmsDev will charge you for messages sent to invalid numbers. - ### Receiving SMS messages Get unread messages in a specific date interval: @@ -130,5 +129,5 @@ This class solves this problem by automatically correcting dates both in search ## TODO -- Check the status of sent messages. -- Send multiple SMS messages. +- Check the status of sent messages. +- Send multiple SMS messages. diff --git a/src/SmsDev.php b/src/SmsDev.php index 687fba5..cbdc156 100644 --- a/src/SmsDev.php +++ b/src/SmsDev.php @@ -7,11 +7,11 @@ /** * SmsDev - * + * * Send and receive SMS using SmsDev.com.br - * + * * @see https://www.smsdev.com.br/ SMSDev API. - * + * * @author Enrico Dias */ class SmsDev @@ -55,7 +55,7 @@ class SmsDev * Query string to be sent to the API as a search filter. * * The default 'status' = 1 will return all received messages. - * + * * @var array */ private $_query = [ @@ -83,7 +83,7 @@ public function __construct($apiKey = '') /** * Send an SMS message. - * + * * This method does not guarantee that the recipient received the massage since the message delivery is async. * * @param int $number Recipient's number. @@ -96,7 +96,7 @@ public function send($number, $message, $refer = null) $this->_result = []; if ($this->_numberValidation === true) { - + try { $number = $this->validatePhoneNumber($number); @@ -239,7 +239,7 @@ public function dateBetween($dateFrom, $dateTo) /** * Query the API for received messages using search filters. - * + * * @see SmsDev::$_query Search filters. * @see SmsDev::$_result API response. * @@ -274,11 +274,11 @@ public function fetch() /** * Parse the received messages in a more useful format with the fields date, number and message. - * + * * The dates received by the API are converted to SmsDev::$_dateFormat. * * @see SmsDev::$_dateFormat Date format to be used in all date functions. - * + * * @return array List of received messages. */ public function parsedMessages() @@ -341,7 +341,7 @@ public function getBalance() * Get the raw API response from the last response received. * * @see SmsDev::$_result Raw API response. - * + * * @return array Raw API response. */ public function getResult() @@ -353,10 +353,10 @@ public function getResult() * Verifies if a phone number is valid * * @see https://github.com/giggsey/libphonenumber-for-php libphonenumber for PHP repository. - * + * * @param int $number Phone number. * @return int A valid mobile phone number. - * + * * @throws \libphonenumber\NumberParseException If the number is not valid. * @throws \Exception If the number is not a valid brazilian mobile number. */ @@ -384,12 +384,12 @@ private function validatePhoneNumber($number) /** * Convert a date to format supported by the API. - * + * * The API requires the date format d/m/Y, but in this class any valid date format is supported. * Since the API is always using the timezone America/Sao_Paulo, this function must also do timezone conversions. * * @see SmsDev::$_dateFormat Date format to be used in all date functions. - * + * * @param string $key The filter key to be set as a search filter. * @param string $date A valid date format. * @return SmsDev Return itself for chaining. @@ -399,7 +399,7 @@ private function parseDate($key, $date) $parsedDate = \DateTime::createFromFormat($this->_dateFormat, $date); if ($parsedDate !== false) { - + $parsedDate->setTimezone($this->_apiTimeZone); $this->_query[$key] = $parsedDate->format('d/m/Y'); @@ -424,13 +424,13 @@ private function makeRequest($request) $response = $client->send($request); } catch (\Exception $e) { - + return false; - + } $response = json_decode($response->getBody(), true); - + if (json_last_error() != JSON_ERROR_NONE || is_array($response) === false) return false; $this->_result = $response; @@ -443,11 +443,11 @@ private function makeRequest($request) * This method is needed to test API calls in unit tests. * * @return object GuzzleHttp\Client instance. - * + * * @codeCoverageIgnore */ protected function getGuzzleClient() { return new Client(); } -} \ No newline at end of file +} diff --git a/tests/ApiRequestsTest.php b/tests/ApiRequestsTest.php index 7d2c7ab..e7e2431 100644 --- a/tests/ApiRequestsTest.php +++ b/tests/ApiRequestsTest.php @@ -4,7 +4,7 @@ /** * Test if the requests sent are compatible with the API specification. - * + * * @see https://www.smsdev.com.br/ SMSDev API specification. */ final class ApiRequestsTest extends SmsDevMock @@ -86,7 +86,7 @@ public function testFilterById() ->fetch(); $this->assertSame('/v1/inbox', $this->getRequestPath()); - + $query = $this->getRequestBody(); $this->assertEquals('', $query->key); @@ -123,11 +123,11 @@ public function testFilterByDateBetween_InvalidDate() $this->assertSame('/v1/inbox', $this->getRequestPath()); $query = $this->getRequestBody(); - + $this->assertEquals('', $query->key); $this->assertObjectNotHasAttribute('date_from', $query); $this->assertEquals('19/01/2019', $query->date_to); - + $SmsDev = $this->getServiceMock(); $SmsDev->setDateFormat('Y-m-d') @@ -179,7 +179,7 @@ public function testFilterByDate() /** * Test the timezone calculations in the date filters. - * + * * Example: 2020-01-02 01:00:00 should be day 2020-01-01 in America/Sao_Paulo */ public function testTimezoneDate() @@ -199,4 +199,4 @@ public function testTimezoneDate() $this->assertSame('01/01/2020', $query->date_from); } -} \ No newline at end of file +} diff --git a/tests/ApiResponseTest.php b/tests/ApiResponseTest.php index 78b8623..c19e0a5 100644 --- a/tests/ApiResponseTest.php +++ b/tests/ApiResponseTest.php @@ -4,7 +4,7 @@ /** * Test if the class can parse the API responses correctly. - * + * * @see https://www.smsdev.com.br/ SMSDev API specification. */ final class ApiResponseTest extends SmsDevMock @@ -62,7 +62,7 @@ public function sendDataProvider() [ '118888100', 'Message', 'Refer', true, '{"situacao":"OK","codigo":"1","id":"645106333","refer": "Refer","descricao":"MENSAGEM NA FILA"}' ], [ '11888810009', 'Message', 'Refer', true, '{"situacao":"OK","codigo":"1","id":"645106334","refer": "Refer","descricao":"MENSAGEM NA FILA"}' ], [ 'abc', 'Message', 'Refer', false, '{"situacao":"ERRO","codigo":"402","refer": "Refer","descricao":"SEM NUMERO DESTINATARIO."}' ], - [ '', 'Message', 'Refer', false, '{"situacao":"ERRO","codigo":"402","refer": "Refer","descricao":"SEM NUMERO DESTINATARIO."}'], + [ '', 'Message', 'Refer', false, '{"situacao":"ERRO","codigo":"402","refer": "Refer","descricao":"SEM NUMERO DESTINATARIO."}'], ]; } @@ -79,7 +79,7 @@ public function testFilterByUnread() ->fetch(); $parsedMessages = current($SmsDev->parsedMessages()); - + $this->assertSame('2018-01-19 13:35:14', $parsedMessages['date']); // UTC conversion $this->assertSame('5511988887777', $parsedMessages['number']); $this->assertSame('Resposta', $parsedMessages['message']); @@ -102,7 +102,7 @@ public function testFilterByUnread_EmptyResponse() public function testFilterById() { $apiResponse = '[{"situacao":"OK","data_read":"19\/01\/2018 11:35:14","telefone":"5511988887777","id":"","refer_id":"","nome":"","msg_sent":"","id_sms_read":"2515974","descricao":"Resposta"}]'; - + $SmsDev = $this->getServiceMock($apiResponse); $SmsDev->setFilter() @@ -110,7 +110,7 @@ public function testFilterById() ->fetch(); $result = current($SmsDev->getResult()); - + $this->assertSame(2515974, (int)$result['id_sms_read']); } @@ -123,7 +123,7 @@ public function testFilterById_EmptyResponse() $SmsDev->setFilter() ->byId(2515974) ->fetch(); - + $this->assertEmpty($SmsDev->parsedMessages()); } @@ -140,7 +140,7 @@ public function testFilterByDate() ->fetch(); $parsedMessages = current($SmsDev->parsedMessages()); - + $this->assertSame('1529418914', $parsedMessages['date']); $this->assertSame('5511988887777', $parsedMessages['number']); $this->assertSame('Resposta 1', $parsedMessages['message']); @@ -153,7 +153,7 @@ public function testEmptyInbox() $SmsDev = $this->getServiceMock($apiResponse); $SmsDev->setDateFormat('Y-m-d H:i:s')->fetch(); - + $this->assertEmpty($SmsDev->parsedMessages()); } @@ -169,4 +169,4 @@ public function testWrongApiKey() $this->assertSame(false, $SmsDev->fetch()); } -} \ No newline at end of file +} diff --git a/tests/PhoneNumberVerificationTest.php b/tests/PhoneNumberVerificationTest.php index eaf26eb..0f36b46 100644 --- a/tests/PhoneNumberVerificationTest.php +++ b/tests/PhoneNumberVerificationTest.php @@ -4,7 +4,7 @@ /** * Test the optional phone number verification - * + * * @see https://github.com/giggsey/libphonenumber-for-php libphonenumber for PHP repository. */ final class PhoneNumberVerificationTest extends SmsDevMock @@ -87,4 +87,4 @@ public function invalidPhoneProvider() ]; } -} \ No newline at end of file +} diff --git a/tests/SmsDevMock.php b/tests/SmsDevMock.php index 9820713..14829d1 100644 --- a/tests/SmsDevMock.php +++ b/tests/SmsDevMock.php @@ -38,9 +38,9 @@ public function getServiceMock($apiResponse = '') $stub = $this->getMockBuilder(SmsDev::class) ->setMethods(['getGuzzleClient']) ->getMock(); - + $stub->method('getGuzzleClient')->willReturn($client); - + return $stub; }