From bcf46e89fb1e97bf2a342a9536ccdcc94a73d849 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Thu, 2 Nov 2017 08:32:22 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/TwilioDriver.php | 4 ++-- src/TwilioMessageDriver.php | 13 +++++-------- src/TwilioSettings.php | 2 +- src/TwilioVoiceDriver.php | 9 ++++----- stubs/twilio.php | 2 +- tests/TwilioMessageDriverTest.php | 7 ++++--- tests/TwilioVoiceDriverTest.php | 9 +++++---- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/TwilioDriver.php b/src/TwilioDriver.php index ec0ceb1..0656460 100644 --- a/src/TwilioDriver.php +++ b/src/TwilioDriver.php @@ -11,7 +11,6 @@ abstract class TwilioDriver extends HttpDriver { - /** @var array */ protected $messages = []; @@ -48,6 +47,7 @@ public function getUser(IncomingMessage $matchingMessage) protected function isSignatureValid() { $validator = new RequestValidator($this->config->get('token')); + return $validator->validate($this->signature, $this->requestUri, $this->payload); } @@ -79,4 +79,4 @@ public function sendRequest($endpoint, array $parameters, IncomingMessage $match { // } -} \ No newline at end of file +} diff --git a/src/TwilioMessageDriver.php b/src/TwilioMessageDriver.php index b3310e6..3e59ced 100644 --- a/src/TwilioMessageDriver.php +++ b/src/TwilioMessageDriver.php @@ -2,13 +2,11 @@ namespace BotMan\Drivers\Twilio; -use BotMan\BotMan\Messages\Attachments\Image; -use BotMan\BotMan\Messages\Attachments\Location; use Twilio\Twiml; use BotMan\BotMan\Messages\Incoming\Answer; use BotMan\BotMan\Messages\Outgoing\Question; -use BotMan\BotMan\Drivers\Events\GenericEvent; use Symfony\Component\HttpFoundation\Response; +use BotMan\BotMan\Messages\Attachments\Location; use BotMan\BotMan\Interfaces\DriverEventInterface; use BotMan\BotMan\Messages\Incoming\IncomingMessage; use BotMan\BotMan\Messages\Outgoing\OutgoingMessage; @@ -47,7 +45,6 @@ public function getConversationAnswer(IncomingMessage $message) public function getMessages() { if (empty($this->messages)) { - $message = new IncomingMessage($this->event->get('Body'), $this->event->get('MessageSid'), $this->event->get('To')); $this->messages = [$message]; @@ -85,7 +82,7 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam } elseif ($message instanceof OutgoingMessage) { $attachment = $message->getAttachment(); $text = $message->getText(); - if ($attachment instanceof Location === false && !is_null($attachment)) { + if ($attachment instanceof Location === false && ! is_null($attachment)) { $parameters['media'] = $attachment->getUrl(); } } else { @@ -104,7 +101,7 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam public function sendPayload($payload) { if (isset($payload['twiml'])) { - return Response::create((string)$payload['twiml'])->send(); + return Response::create((string) $payload['twiml'])->send(); } $response = new Twiml(); @@ -112,7 +109,7 @@ public function sendPayload($payload) $body = $payload['text']; - foreach ((array)$payload['buttons'] as $button) { + foreach ((array) $payload['buttons'] as $button) { $body .= "\n".$button['text']; } $message->body($body); @@ -120,6 +117,6 @@ public function sendPayload($payload) $message->media($payload['media']); } - return Response::create((string)$response)->send(); + return Response::create((string) $response)->send(); } } diff --git a/src/TwilioSettings.php b/src/TwilioSettings.php index 72f7e7f..7b01df8 100644 --- a/src/TwilioSettings.php +++ b/src/TwilioSettings.php @@ -11,4 +11,4 @@ class TwilioSettings const INPUT_DTMF = 'dtmf'; const INPUT_SPEECH = 'speech'; const INPUT_DTMF_SPEECH = 'dtmf speech'; -} \ No newline at end of file +} diff --git a/src/TwilioVoiceDriver.php b/src/TwilioVoiceDriver.php index da74ef1..2f7fc22 100644 --- a/src/TwilioVoiceDriver.php +++ b/src/TwilioVoiceDriver.php @@ -46,7 +46,6 @@ public function getConversationAnswer(IncomingMessage $message) public function getMessages() { if (empty($this->messages)) { - $message = new IncomingMessage($this->event->get('Digits'), $this->event->get('CallSid'), $this->event->get('To')); $this->messages = [$message]; @@ -107,12 +106,12 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam public function sendPayload($payload) { if (isset($payload['twiml'])) { - return Response::create((string)$payload['twiml'])->send(); + return Response::create((string) $payload['twiml'])->send(); } $sayParameters = [ 'voice' => $this->config->get('voice'), - 'language' => $this->config->get('language') + 'language' => $this->config->get('language'), ]; if (isset($payload['voice'])) { $sayParameters['voice'] = $payload['voice']; @@ -126,13 +125,13 @@ public function sendPayload($payload) $input = $payload['input'] ?? TwilioSettings::INPUT_DTMF; $gather = $response->gather(['input' => $input]); $gather->say($payload['text'], $sayParameters); - foreach ((array)$payload['buttons'] as $button) { + foreach ((array) $payload['buttons'] as $button) { $gather->say($button['text'], $sayParameters); } } else { $response->say($payload['text'], $sayParameters); } - return Response::create((string)$response)->send(); + return Response::create((string) $response)->send(); } } diff --git a/stubs/twilio.php b/stubs/twilio.php index 1145527..284ca93 100644 --- a/stubs/twilio.php +++ b/stubs/twilio.php @@ -49,5 +49,5 @@ | See: https://www.twilio.com/docs/api/twiml/gather#attributes-input | */ - 'input' => \BotMan\Drivers\Twilio\TwilioSettings::INPUT_DTMF + 'input' => \BotMan\Drivers\Twilio\TwilioSettings::INPUT_DTMF, ]; diff --git a/tests/TwilioMessageDriverTest.php b/tests/TwilioMessageDriverTest.php index 6a2734d..311eb4b 100644 --- a/tests/TwilioMessageDriverTest.php +++ b/tests/TwilioMessageDriverTest.php @@ -9,8 +9,8 @@ use BotMan\BotMan\Messages\Attachments\Image; use BotMan\BotMan\Messages\Outgoing\Question; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use BotMan\Drivers\Twilio\TwilioMessageDriver; +use Symfony\Component\HttpFoundation\Response; use BotMan\BotMan\Messages\Outgoing\Actions\Button; use BotMan\BotMan\Messages\Incoming\IncomingMessage; use BotMan\BotMan\Messages\Outgoing\OutgoingMessage; @@ -20,7 +20,7 @@ class TwilioMessageDriverTest extends PHPUnit_Framework_TestCase private function getDriver($parameters = [], $htmlInterface = null) { $request = Request::create('', 'POST', $parameters, [], [], [ - 'Content-Type' => 'application/x-ww-form-urlencoded' + 'Content-Type' => 'application/x-ww-form-urlencoded', ]); $request->headers->set('X-Twilio-Signature', 'Lo3nfTHrzZ2sr2daOkmKFA9Ce0w='); if ($htmlInterface === null) { @@ -60,6 +60,7 @@ private function getValidDriver($htmlInterface = null) 'Direction' => 'inbound', 'ApiVersion' => '2010-04-01', ]; + return $this->getDriver($parameters, $htmlInterface); } @@ -223,7 +224,7 @@ public function it_can_send_questions() $question = Question::create('This is a question')->addButtons([ Button::create('Button 1')->value('1'), - Button::create('Button 2')->value('2') + Button::create('Button 2')->value('2'), ]); $payload = $driver->buildServicePayload($question, new IncomingMessage('', '', ''), []); diff --git a/tests/TwilioVoiceDriverTest.php b/tests/TwilioVoiceDriverTest.php index fca2578..028df30 100644 --- a/tests/TwilioVoiceDriverTest.php +++ b/tests/TwilioVoiceDriverTest.php @@ -6,10 +6,10 @@ use Twilio\Twiml; use BotMan\BotMan\Http\Curl; use PHPUnit_Framework_TestCase; +use BotMan\Drivers\Twilio\TwilioVoiceDriver; use BotMan\BotMan\Messages\Outgoing\Question; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use BotMan\Drivers\Twilio\TwilioVoiceDriver; use BotMan\BotMan\Messages\Outgoing\Actions\Button; use BotMan\BotMan\Messages\Incoming\IncomingMessage; use BotMan\BotMan\Messages\Outgoing\OutgoingMessage; @@ -19,7 +19,7 @@ class TwilioVoiceDriverTest extends PHPUnit_Framework_TestCase private function getDriver($parameters = [], $htmlInterface = null) { $request = Request::create('', 'POST', $parameters, [], [], [ - 'Content-Type' => 'application/x-ww-form-urlencoded' + 'Content-Type' => 'application/x-ww-form-urlencoded', ]); $request->headers->set('X-Twilio-Signature', '+vqR5LqFQepeHnZIFIuq4jID2ws='); if ($htmlInterface === null) { @@ -61,6 +61,7 @@ private function getValidDriver($withDigits = true, $htmlInterface = null) if ($withDigits === true) { $parameters['Digits'] = '1'; } + return $this->getDriver($parameters, $htmlInterface); } @@ -188,7 +189,7 @@ public function it_can_send_payload() $payload = [ 'text' => 'string', - 'question' => false + 'question' => false, ]; /** @var Response $response */ @@ -233,7 +234,7 @@ public function it_can_send_questions() $question = Question::create('This is a question')->addButtons([ Button::create('Button 1')->value('1'), - Button::create('Button 2')->value('2') + Button::create('Button 2')->value('2'), ]); $payload = $driver->buildServicePayload($question, new IncomingMessage('', '', ''), []);