for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @copyright Anton Tuyakhov <[email protected]>
*/
namespace tuyakhov\notifications\channels;
use tuyakhov\notifications\messages\SmsMessage;
use tuyakhov\notifications\NotifiableInterface;
use tuyakhov\notifications\NotificationInterface;
use yii\base\Component;
use yii\di\Instance;
use yii\httpclient\Client;
class TwilioChannel extends Component implements ChannelInterface
{
public $baseUrl = 'https://api.twilio.com/2010-04-01';
public $accountSid;
public $authToken;
public $from;
* @var Client
public $httpClient;
public function init()
parent::init();
$this->httpClient = Instance::ensure($this->httpClient, 'yii\httpclient\Client');
}
public function getUri()
return sprintf('%s/%s/%s', 'Accounts', $this->accountSid, 'Messages.json');
* @inheritdoc
public function send(NotifiableInterface $recipient, NotificationInterface $notification)
/** @var SmsMessage $message */
$message = $notification->exportFor('sms');
$data = [
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
$a = "a"; $ab = "ab"; $abc = "abc";
will produce issues in the first and second line, while this second example
will produce no issues.
'From' => isset($message->from) ? $message->from : $this->from,
'To' => $recipient->routeNotificationFor('sms'),
'Body' => $message->body
];
if (isset($message->mediaUrl)) {
$data['MedialUrl'] = $message->mediaUrl;
$this->httpClient
->createRequest()
->setMethod('post')
->setUrl($this->getUri())
->addHeaders(['Authorization' => 'Basic ' . base64_encode("{$this->accountSid}:{$this->authToken}")])
->setData($data)
->send();
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.