<commit_before><?php namespace Nathanmac\InstantMessenger\Services;

use Nathanmac\InstantMessenger\Message;
use Exception;

class TwilioService extends HTTPService implements MessengerService {

    /**
     * The account sid for the Twilio service.
     *
     * @var string
     */
    private $account_sid;

    /**
     * The auth token for the Twilio service.
     *
     * @var string
     */
    private $auth_token;

    /**
     * The phone number to send to, for the Twilio service.
     *
     * @var string|null
     */
    private $to = null;

    /**
     * The phone number to send from, for the Twilio service.
     *
     * @var string
     */
    private $from;

    /**
     * The API endpoint for the Twilio service.
     *
     * @var string
     */
    private $api_endpoint = 'https://api.twilio.com/2010-04-01/Accounts/';

    /**
     * Setup the transporter for the Twilio service.
     *
     * @param string      $account_sid Twilio Account SID
     * @param string      $auth_token  Twilio Auth Token
     * @param string      $from        Twilio From Number
     * @param string|null $to          Twilio To Number
     */
    public function __construct($account_sid, $auth_token, $from, $to = null)
    {
        $this->account_sid = $account_sid;
        $this->auth_token = $auth_token;
        $this->from = $from;
        $this->to = $to;
    }

    /**
     * Create a new TwilioService instance.
     *
     * @codeCoverageIgnore
     *
     * @param string      $account_sid Twilio Account SID
     * @param string      $auth_token  Twilio Auth Token
     * @param string      $from        Twilio From Number
     * @param string|null $to          Twilio To Number
     *
     * @return TwilioService
     */
    public static function newInstance($account_sid, $auth_token, $from, $to = null)
    {
        return new self($account_sid, $auth_token, $from, $to);
    }

    /**
     * Send/Transmit the message using the service.
     *
     * @param Message $message
     *
     * @return mixed|void
     *
     * @throws Exception
     */
    public function send(Message $message)
    {
        if (is_null($this->getTo()) || empty($this->getTo()))
            throw new Exception('Missing phone number');

        $client = $this->getHttpClient();

        $url = $this->api_endpoint . $this->getAccountSid() . '/Messages.json';
        $client->post($url, array('auth' => array($this->getAccountSid(), $this->getAuthToken()), 'form_params' => $this->buildMessage($message)));
    }

    /**<commit_msg>Fix comparison issue with php 5.4<commit_after><?php namespace Nathanmac\InstantMessenger\Services;

use Nathanmac\InstantMessenger\Message;
use Exception;

class TwilioService extends HTTPService implements MessengerService {

    /**
     * The account sid for the Twilio service.
     *
     * @var string
     */
    private $account_sid;

    /**
     * The auth token for the Twilio service.
     *
     * @var string
     */
    private $auth_token;

    /**
     * The phone number to send to, for the Twilio service.
     *
     * @var string|null
     */
    private $to = null;

    /**
     * The phone number to send from, for the Twilio service.
     *
     * @var string
     */
    private $from;

    /**
     * The API endpoint for the Twilio service.
     *
     * @var string
     */
    private $api_endpoint = 'https://api.twilio.com/2010-04-01/Accounts/';

    /**
     * Setup the transporter for the Twilio service.
     *
     * @param string      $account_sid Twilio Account SID
     * @param string      $auth_token  Twilio Auth Token
     * @param string      $from        Twilio From Number
     * @param string|null $to          Twilio To Number
     */
    public function __construct($account_sid, $auth_token, $from, $to = null)
    {
        $this->account_sid = $account_sid;
        $this->auth_token = $auth_token;
        $this->from = $from;
        $this->to = $to;
    }

    /**
     * Create a new TwilioService instance.
     *
     * @codeCoverageIgnore
     *
     * @param string      $account_sid Twilio Account SID
     * @param string      $auth_token  Twilio Auth Token
     * @param string      $from        Twilio From Number
     * @param string|null $to          Twilio To Number
     *
     * @return TwilioService
     */
    public static function newInstance($account_sid, $auth_token, $from, $to = null)
    {
        return new self($account_sid, $auth_token, $from, $to);
    }

    /**
     * Send/Transmit the message using the service.
     *
     * @param Message $message
     *
     * @return mixed|void
     *
     * @throws Exception
     */
    public function send(Message $message)
    {
        if (null !== $this->getTo() || '' !== $this->getTo())
            throw new Exception('Missing phone number');

        $client = $this->getHttpClient();

        $url = $this->api_endpoint . $this->getAccountSid() . '/Messages.json';
        $client->post($url, array('auth' => array($this->getAccountSid(), $this->getAuthToken()), 'form_params' => $this->buildMessage($message)));
    }

    /**
{'fraction_non_alphanumeric': 0.12182244818146265, 'fraction_numerical': 0.0035197497066875244, 'mean_word_length': 2.098122350090854, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '11756', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1511, 'n_words': 416}