From 6bc44d2596b5f4c9b5c8817aa71e1f711de5f635 Mon Sep 17 00:00:00 2001 From: Faruk Date: Mon, 17 Feb 2020 17:10:22 +0300 Subject: [PATCH] Apply fixes from StyleCI (#1) --- config/config.php | 6 ++--- src/AbstractNetgsmMessage.php | 21 +++++++++------- src/Exceptions/CouldNotSendNotification.php | 1 - .../IncorrectPhoneNumberFormatException.php | 3 --- src/Exceptions/ReportException.php | 2 -- src/Netgsm.php | 5 ++-- src/NetgsmChannel.php | 2 +- src/NetgsmOtpMessage.php | 4 +-- src/NetgsmReportInterface.php | 3 --- src/NetgsmSmsDetailReport.php | 14 +++++------ src/NetgsmSmsMessage.php | 12 ++++----- src/NetgsmSmsReport.php | 20 +++++++-------- tests/NetGsmChannelTest.php | 2 +- tests/NetGsmReportDetailTest.php | 16 ++++++------ tests/NetGsmReportTest.php | 23 +++++++++-------- tests/NetGsmTest.php | 25 ++++++++++--------- tests/notification/TestNotification.php | 1 - 17 files changed, 74 insertions(+), 86 deletions(-) diff --git a/config/config.php b/config/config.php index d54d504..9e5fb94 100755 --- a/config/config.php +++ b/config/config.php @@ -3,11 +3,11 @@ return [ 'credentials' => [ 'user_code' => env('NETGSM_USERCODE'), - 'secret' => env('NETGSM_SECRET') + 'secret' => env('NETGSM_SECRET'), ], 'defaults' => [ 'language' => env('NETGSM_LANGUAGE', 'tr'), 'header' => env('NETGSM_HEADER', null), - 'sms_sending_method' => env('NETGSM_SMS_SENDING_METHOD', 'xml') - ] + 'sms_sending_method' => env('NETGSM_SMS_SENDING_METHOD', 'xml'), + ], ]; diff --git a/src/AbstractNetgsmMessage.php b/src/AbstractNetgsmMessage.php index 2d9ed95..2f6c91d 100644 --- a/src/AbstractNetgsmMessage.php +++ b/src/AbstractNetgsmMessage.php @@ -74,7 +74,7 @@ abstract class AbstractNetgsmMessage protected $message; /** - * authorized data parameter + * authorized data parameter. * * @see https://www.netgsm.com.tr/dokuman/#http-get-sms-g%C3%B6nderme * @see https://www.netgsm.com.tr/dokuman/#xml-post-sms-g%C3%B6nderme @@ -132,7 +132,7 @@ abstract protected function createXmlPost(): string; */ public function setRecipients($recipients) { - if (!is_array($recipients)) { + if (! is_array($recipients)) { $this->recipients = explode(',', $recipients); } else { $this->recipients = $recipients; @@ -202,11 +202,12 @@ public function getSendMethod(): string */ public function setSendMethod(string $sendMethod): self { - if (!in_array($sendMethod, $this->sendMethods)) { - throw new Exception($sendMethod." method is not allowed"); + if (! in_array($sendMethod, $this->sendMethods)) { + throw new Exception($sendMethod.' method is not allowed'); } $this->sendMethod = $sendMethod; + return $this; } @@ -219,13 +220,13 @@ public function isAuthorizedData(): bool } /** - * * @param bool $authorizedData * @return AbstractNetgsmMessage */ - public function setAuthorizedData(bool $authorizedData): AbstractNetgsmMessage + public function setAuthorizedData(bool $authorizedData): self { $this->authorizedData = $authorizedData; + return $this; } @@ -234,7 +235,7 @@ public function setAuthorizedData(bool $authorizedData): AbstractNetgsmMessage */ public function getUrl(): string { - return $this->url."/".$this->getSendMethod(); + return $this->url.'/'.$this->getSendMethod(); } /** @@ -300,6 +301,7 @@ public function setCredentials(array $credentials): self public function setStartDate(Carbon $startDate): self { $this->startDate = $startDate; + return $this; } @@ -310,6 +312,7 @@ public function setStartDate(Carbon $startDate): self public function setEndDate(Carbon $endDate): self { $this->endDate = $endDate; + return $this; } @@ -337,11 +340,11 @@ public function parseResponse(): self { $result = explode(' ', $this->getResponseContent()); - if (!isset($result[0])) { + if (! isset($result[0])) { throw new CouldNotSendNotification(CouldNotSendNotification::NETGSM_GENERAL_ERROR); } - if (!in_array($result[0], self::SUCCESS_CODES)) { + if (! in_array($result[0], self::SUCCESS_CODES)) { $message = $this->errorCodes[$result[0]]; throw new CouldNotSendNotification($message); } diff --git a/src/Exceptions/CouldNotSendNotification.php b/src/Exceptions/CouldNotSendNotification.php index 0474175..ee20762 100644 --- a/src/Exceptions/CouldNotSendNotification.php +++ b/src/Exceptions/CouldNotSendNotification.php @@ -18,7 +18,6 @@ class CouldNotSendNotification extends \Exception const SYSTEM_ERROR = 'Sistem hatası.'; const NETGSM_GENERAL_ERROR = 'Netgsm responded with an error :'; - /** * Thrown when there's a bad request and an error is responded. * diff --git a/src/Exceptions/IncorrectPhoneNumberFormatException.php b/src/Exceptions/IncorrectPhoneNumberFormatException.php index 3ce8272..90e28d5 100644 --- a/src/Exceptions/IncorrectPhoneNumberFormatException.php +++ b/src/Exceptions/IncorrectPhoneNumberFormatException.php @@ -1,10 +1,7 @@ setClient($this->client) ->setCredentials($this->credentials) @@ -80,10 +79,10 @@ public function getReports( if (count($filters) > 0) { foreach ($filters as $filter => $value) { - if (!method_exists($report, 'set'.$filter)) { + if (! method_exists($report, 'set'.$filter)) { continue; } - + call_user_func([$report, 'set'.$filter], $value); } } diff --git a/src/NetgsmChannel.php b/src/NetgsmChannel.php index 19c5692..28bad5f 100644 --- a/src/NetgsmChannel.php +++ b/src/NetgsmChannel.php @@ -26,7 +26,7 @@ public function send($notifiable, Notification $notification) { $message = $notification->toNetgsm($notifiable); - if (!$message instanceof AbstractNetgsmMessage) { + if (! $message instanceof AbstractNetgsmMessage) { throw new \Exception('Geçerli bir Netgsm mesajı değil'); } diff --git a/src/NetgsmOtpMessage.php b/src/NetgsmOtpMessage.php index 2ecdad1..6d8b965 100644 --- a/src/NetgsmOtpMessage.php +++ b/src/NetgsmOtpMessage.php @@ -1,9 +1,7 @@ 1, 'version' => 1, - 'view' => 2 + 'view' => 2, ]; /** @@ -62,7 +62,7 @@ public function setBulkId($bulkId): AbstractNetgsmReport } /** - * Processes the report line + * Processes the report line. * * @param $line * @return array @@ -70,13 +70,13 @@ public function setBulkId($bulkId): AbstractNetgsmReport public function processRow($line): array { return [ - 'jobId' => (integer) $line->msginfo->jobID, + 'jobId' => (int) $line->msginfo->jobID, 'message' => (string) $line->msginfo->msg, 'startDate' => (string) $line->datetime->startdate, 'endDate' => (string) $line->datetime->stopdate, 'status' => (string) $line->msginfo->state, 'total' => (string) $line->msginfo->total, - 'header' => (string) $line->msginfo->msgheader + 'header' => (string) $line->msginfo->msgheader, ]; } diff --git a/src/NetgsmSmsMessage.php b/src/NetgsmSmsMessage.php index 442a463..6c2ad02 100644 --- a/src/NetgsmSmsMessage.php +++ b/src/NetgsmSmsMessage.php @@ -12,7 +12,7 @@ class NetgsmSmsMessage extends AbstractNetgsmMessage '20' => CouldNotSendNotification::MESSAGE_TOO_LONG, '30' => CouldNotSendNotification::CREDENTIALS_INCORRECT, '40' => CouldNotSendNotification::SENDER_INCORRECT, - '70' => CouldNotSendNotification::PARAMETERS_INCORRECT + '70' => CouldNotSendNotification::PARAMETERS_INCORRECT, ]; protected $fields = [ @@ -24,7 +24,7 @@ class NetgsmSmsMessage extends AbstractNetgsmMessage 'startdate', 'stopdate', 'dil', - 'izin' + 'izin', ]; /** @@ -63,11 +63,9 @@ protected function mappers(): array 'usercode' => $this->credentials['user_code'], 'password' => $this->credentials['secret'], 'message' => $this->message, - 'startdate' => !empty($this->startDate) ? $this->startDate->format('dmYHi') : null, - 'stopdate' => !empty($this->endDate) ? $this->endDate->format('dmYHi') : null, - 'izin' => (int) $this->isAuthorizedData() + 'startdate' => ! empty($this->startDate) ? $this->startDate->format('dmYHi') : null, + 'stopdate' => ! empty($this->endDate) ? $this->endDate->format('dmYHi') : null, + 'izin' => (int) $this->isAuthorizedData(), ]; } - - } diff --git a/src/NetgsmSmsReport.php b/src/NetgsmSmsReport.php index d08d4a2..25f2139 100644 --- a/src/NetgsmSmsReport.php +++ b/src/NetgsmSmsReport.php @@ -1,9 +1,7 @@ 2, - 'version' => 2 + 'version' => 2, ]; /** @@ -38,12 +36,12 @@ class NetgsmSmsReport extends AbstractNetgsmReport 0 => [ 'jobId' => 'integer', 'phone' => 'string', - 'status' => 'integer' + 'status' => 'integer', ], 1 => [ 'jobId' => 'integer', 'phone' => 'string', - 'status' => 'integer' + 'status' => 'integer', ], 2 => [ 'jobId' => 'integer', @@ -53,13 +51,13 @@ class NetgsmSmsReport extends AbstractNetgsmReport 'length' => 'integer', 'startDate' => 'date', 'startTime' => 'date', - 'errorCode' => 'integer' + 'errorCode' => 'integer', ], 3 => [ 'jobId' => 'integer', 'phone' => 'string', - 'status' => 'integer' - ] + 'status' => 'integer', + ], ]; /** @@ -73,7 +71,7 @@ class NetgsmSmsReport extends AbstractNetgsmReport 'length' => null, 'startDate' => null, 'startTime' => null, - 'errorCode' => null + 'errorCode' => null, ]; /** diff --git a/tests/NetGsmChannelTest.php b/tests/NetGsmChannelTest.php index fd8f38d..00b4986 100644 --- a/tests/NetGsmChannelTest.php +++ b/tests/NetGsmChannelTest.php @@ -44,7 +44,7 @@ public function setUp(): void $this->netgsm = Mockery::mock(new Netgsm($this->httpClient, [ 'userCode' => '', - 'secret' => '' + 'secret' => '', ])); $this->channel = new NetGsmChannel($this->netgsm); diff --git a/tests/NetGsmReportDetailTest.php b/tests/NetGsmReportDetailTest.php index 15d9574..fb8c61f 100644 --- a/tests/NetGsmReportDetailTest.php +++ b/tests/NetGsmReportDetailTest.php @@ -32,7 +32,7 @@ public function setUp(): void $this->netgsm = new Netgsm($this->httpClient, [ 'user_code' => $this->faker->userName, - 'secret' => $this->faker->password + 'secret' => $this->faker->password, ]); } @@ -58,7 +58,7 @@ protected function mockReportApiRequest($rowCount, $times) $lastResponse = new Response( $status = 200, $headers = [], - "100" + '100' ); $responses[] = $lastResponse; @@ -85,9 +85,10 @@ protected function generateResponse($rowCount): array 'header' => $this->faker->word, 'message' => $this->faker->sentence, 'status' => $this->faker->randomElement(range(1, 9)), - 'total' => $this->faker->numberBetween(1, 10) + 'total' => $this->faker->numberBetween(1, 10), ]; } + return $response; } @@ -101,7 +102,6 @@ protected function convertXml($items) $child = $xml->addChild('header'); foreach ($items as $item) { - $report = $child->addChild('SMSReport'); $datetimeChild = $report->addChild('datetime'); @@ -111,7 +111,7 @@ protected function convertXml($items) $msgInfoChild = $report->addChild('msginfo'); $msgInfoChild->addChild('jobID', $item['jobId']); $msgInfoChild->addChild('msgheader', $item['header']); - $msgInfoChild->addChild('groups', "--"); + $msgInfoChild->addChild('groups', '--'); $msgInfoChild->addChild('msg', $item['message']); $msgInfoChild->addChild('state', $item['status']); $msgInfoChild->addChild('total', $item['total']); @@ -183,7 +183,7 @@ public function it_does_get_same_row_count_with_correct_arguments() $this->mockReportApiRequest($rowCount, $pages); $filters = [ - 'type' => $type + 'type' => $type, ]; if ($type == 0) { @@ -222,7 +222,7 @@ public function should_throw_exception_when_return_code_is_not_success() $this->expectExceptionCode($errorCode); $this->netgsm->getReports($report, $startDate, $endDate, [ - 'version' => $version + 'version' => $version, ]); } @@ -242,7 +242,7 @@ public function response_should_properly_parsed_according_by_version() $endDate = new Carbon(); $reportCollection = $this->netgsm->getReports($report, $startDate, $endDate, [ - 'version' => $version + 'version' => $version, ])->keyBy('jobId'); foreach ($reportCollection as $jobId => $item) { diff --git a/tests/NetGsmReportTest.php b/tests/NetGsmReportTest.php index 40569c2..4db14e5 100644 --- a/tests/NetGsmReportTest.php +++ b/tests/NetGsmReportTest.php @@ -31,7 +31,7 @@ public function setUp(): void $this->netgsm = new Netgsm($this->httpClient, [ 'user_code' => $this->faker->userName, - 'secret' => $this->faker->password + 'secret' => $this->faker->password, ]); } @@ -53,7 +53,7 @@ protected function mockReportApiRequest($response) * @param $rowCount * @return array */ - protected function generateResponse($version, $rowCount):array + protected function generateResponse($version, $rowCount): array { $response = []; switch ($version) { @@ -63,7 +63,7 @@ protected function generateResponse($version, $rowCount):array $item = [ $this->faker->numberBetween(11111, 99999), $this->faker->e164PhoneNumber, - $this->faker->randomElement([0, 1, 2, 3, 4, 11, 12, 13, 100, 103]) + $this->faker->randomElement([0, 1, 2, 3, 4, 11, 12, 13, 100, 103]), ]; $response[] = $item; } @@ -79,8 +79,8 @@ protected function generateResponse($version, $rowCount):array $this->faker->dateTime->format('d.m.Y'), $this->faker->dateTime->format('H:i:s'), $this->faker->randomElement([ - 0, 101, 102, 103, 104, 105, 106, 111, 112, 113, 114, 115, 116, 117, 119 - ]) + 0, 101, 102, 103, 104, 105, 106, 111, 112, 113, 114, 115, 116, 117, 119, + ]), ]; $response[] = $item; } @@ -91,13 +91,14 @@ protected function generateResponse($version, $rowCount):array $this->faker->numberBetween(11111, 99999), $this->faker->randomElement([0, 1, 2, 3, 4, 11, 12, 13, 100, 103]), $this->faker->randomElement([ - 0, 101, 102, 103, 104, 105, 106, 111, 112, 113, 114, 115, 116, 117, 119 - ]) + 0, 101, 102, 103, 104, 105, 106, 111, 112, 113, 114, 115, 116, 117, 119, + ]), ]; $response[] = $item; } break; } + return $response; } @@ -181,7 +182,7 @@ public function it_does_get_same_row_count_with_correct_arguments() $endDate = new Carbon(); $report = $this->netgsm->getReports($report, $startDate, $endDate, [ - 'version' => $version + 'version' => $version, ]); $this->assertSame($report->count(), $rowCount); @@ -204,7 +205,7 @@ public function should_throw_exception_when_return_code_is_not_success() $this->expectExceptionCode($errorCode); $this->netgsm->getReports($report, $startDate, $endDate, [ - 'version' => $version + 'version' => $version, ]); } @@ -226,10 +227,10 @@ public function response_should_properly_parsed_according_by_version() $endDate = new Carbon(); $reportCollection = $this->netgsm->getReports($report, $startDate, $endDate, [ - 'version' => $version + 'version' => $version, ])->keyBy('jobId'); - foreach($reportCollection as $jobId => $item){ + foreach ($reportCollection as $jobId => $item) { $existingItem = array_filter($collection[$jobId]); $item = array_filter($item); $this->assertTrue($existingItem == $item); diff --git a/tests/NetGsmTest.php b/tests/NetGsmTest.php index 6921756..3dfc00e 100644 --- a/tests/NetGsmTest.php +++ b/tests/NetGsmTest.php @@ -30,11 +30,11 @@ public function setUp(): void $this->netgsm = new Netgsm($this->httpClient, [ 'user_code' => $this->faker->userName, - 'secret' => $this->faker->password - ],[ + 'secret' => $this->faker->password, + ], [ 'language' => $this->faker->languageCode, 'header' => $this->faker->word, - 'sms_sending_method' => $this->faker->randomElement(['xml','get']) + 'sms_sending_method' => $this->faker->randomElement(['xml', 'get']), ]); } @@ -44,8 +44,9 @@ public function setUp(): void */ protected function newSmsMessage($phone = null) { - $netgsmMessage = new NetgsmSmsMessage($this->faker->sentence($this->faker->numberBetween(1,5))); + $netgsmMessage = new NetgsmSmsMessage($this->faker->sentence($this->faker->numberBetween(1, 5))); $netgsmMessage->setRecipients($phone ?? $this->faker->numberBetween(1111111111, 9999999999)); + return $netgsmMessage; } @@ -54,9 +55,9 @@ protected function newSmsMessage($phone = null) */ public function it_can_send_sms_message_with_correct_arguments() { - $code = $this->faker->randomElement(['00','01','02']); + $code = $this->faker->randomElement(['00', '01', '02']); - $jobId = "98465465484"; + $jobId = '98465465484'; $response = $code.' '.$jobId; $this->httpClient->shouldReceive('request') @@ -74,15 +75,15 @@ public function it_can_send_sms_message_with_correct_arguments() /** * @test */ - public function should_throw_exception_when_return_code_is_not_success(){ - + public function should_throw_exception_when_return_code_is_not_success() + { $this->expectException(CouldNotSendNotification::class); $this->httpClient->shouldReceive('request') ->andReturn(new Response( $status = 200, $headers = [], - $this->faker->randomElement(['20','30','40','70']) + $this->faker->randomElement(['20', '30', '40', '70']) )); $this->netgsm->sendSms($this->newSmsMessage()); @@ -91,11 +92,11 @@ public function should_throw_exception_when_return_code_is_not_success(){ /** * @test */ - public function should_throw_exception_when_phone_number_is_incorrect(){ - + public function should_throw_exception_when_phone_number_is_incorrect() + { $this->expectException(IncorrectPhoneNumberFormatException::class); - $this->netgsm->sendSms($this->newSmsMessage("00000")); + $this->netgsm->sendSms($this->newSmsMessage('00000')); } public function tearDown(): void diff --git a/tests/notification/TestNotification.php b/tests/notification/TestNotification.php index c08424e..121e7a2 100644 --- a/tests/notification/TestNotification.php +++ b/tests/notification/TestNotification.php @@ -2,7 +2,6 @@ namespace TarfinLabs\Netgsm\Tests\notification; - use Illuminate\Notifications\Notification; use TarfinLabs\Netgsm\NetgsmSmsMessage;