<commit_before><?php
/**
 * Nexmo Client Library for PHP
 *
 * @copyright Copyright (c) 2016 Nexmo, Inc. (http://nexmo.com)
 * @license   https://github.com/Nexmo/nexmo-php/blob/master/LICENSE.txt MIT License
 */

namespace Nexmo\Verify;

use Nexmo\Client\APIResource;
use Nexmo\Client\ClientAwareInterface;
use Nexmo\Client\ClientAwareTrait;
use Nexmo\Client\Exception;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class Client implements ClientAwareInterface
{
    use ClientAwareTrait;

    /**
     * @var APIResource
     */
    protected $api;

    public function __construct(APIResource $api = null)
    {
        $this->api = $api;
    }

    /**
     * Shim to handle older instatiations of this class
     * @deprecated Will remove in v3
     */
    protected function getApiResource() : APIResource
    {
        if (is_null($this->api)) {
            $api = new APIResource();
            $api->setClient($this->getClient())
                ->setIsHAL(false)
                ->setBaseUri('/verify')
            ;
            $this->api = $api;
        }
        return clone $this->api;
    }

    /**
     * @param string|array|Verification $verification
     */
    public function start($verification) : Verification
    {
        if (is_array($verification)) {
            trigger_error(
                'Passing an array to Nexmo\Verification\Client::start() is deprecated, please pass a Verification object instead',
                E_USER_DEPRECATED
            );
        }
        if (is_string($verification)) {
            trigger_error(
                'Passing a string to Nexmo\Verification\Client::start() is deprecated, please pass a Verification object instead',
                E_USER_DEPRECATED
            );
        }

        $api = $this->getApiResource();
        $verification = $this->createVerification($verification);
        $response = $api->get('json', $verification->toArray());

        $this->processReqRes($verification, $api->getLastRequest(), $api->getLastResponse(), true);
        return $this->checkError($verification, $response);
    }

    /**
     * @param string|Verification $verification
     */
    public function search($verification)
    {
        if (is_string($verification)) {
            trigger_error(
                'Passing a Verification object to Nexmo\Verification\Client::search() is deprecated, please pass a string ID instead',
                E_USER_DEPRECATED
            );
        }

        $api = $this->getApiResource();
        $verification = $this->createVerification($verification);

        $params = [
            'request_id' => $verification->getRequestId()
        ];

        $data = $api->get('search/json', $params);
        $this->processReqRes($verification, $api->getLastRequest(), $api->getLastResponse(), true);

        return $this->checkError($verification, $data);
    }

    public function cancel($verification)
    {
        return $this->control($verification, 'cancel');
    }

    public function trigger($verification)
    {
        return $this->control($verification, 'trigger_next_event');
    }

    /**
     * @param string|array|Verification $verification
     */
    public function check($verification, string $code, string $ip = null) : Verification
    {
        if (is_array($verification)) {
            trigger_error(
                'Passing an array for parameter 1 to Nexmo\Verification\Client::check() is deprecated, please pass a string ID instead',
                E_USER_DEPRECATED
            );
        }
        if ($verification instanceof Verification) {
            trigger_error(
                'Passing a Verification object for parameter 1 to Nexmo\Verification\Client::check() is deprecated, please pass a string ID instead',
                E_USER_DEPRECATED
            );
        }

        $api = $this->getApiResource();
        $verification = $this->createVerification($verification);
        $params = [
            'request_id' => $verification->getRequestId(),
            'code' => $code
        ];

        if (!is_null($ip)) {
            $params['ip'] = $ip;
        }

        $data = $api->get('check/json', $params);

        $this->processReqRes($verification, $api->getLastRequest(), $api->getLastResponse(), false);
        return $this->checkError($verification, $data);
    }

    public function serialize(Verification $verification)
    {
        return serialize($verification);
    }

    public function unserialize($verification)
    {
        if (is_string($verification)) {
            $verification = unserialize($verification);
        }

        if (!($verification instanceof Verification)) {
            throw new \InvalidArgumentException('expected verification object or serialize verification object');
        }

        $verification->setClient($this);
        return $verification;
    }

    /**
     * @param string|array|Verification $verification
     * @param string $cmd Next command to execute, must be `cancel` or `trigger_next_event`
     */
    protected function control($verification, string $cmd) : Verification
    {
        if (is_array($verification)) {
            trigger_error(
                'Passing an array to Nexmo\Verification\Client::control() is deprecated, please pass a Verification object instead',
                E_USER_DEPRECATED
            );
        }
        if (is_string($verification)) {
            trigger_error(
                'Passing a string to Nexmo\Verification\Client::control() is deprecated, please pass a Verification object instead',
                E_USER_DEPRECATED
            );
        }

        $api = $this->getApiResource();
        $verification = $this->createVerification($verification);

        $params = [
            'request_id' => $verification->getRequestId(),
            'cmd' => $cmd
        ];

        $data = $api->get('control/json', $params);
        $this->processReqRes($verification, $api->getLastRequest(), $api->getLastResponse(), false);
        return $this->checkError($verification, $data);<commit_msg>Cleaned up Verification deprecation notices<commit_after><?php
/**
 * Nexmo Client Library for PHP
 *
 * @copyright Copyright (c) 2016 Nexmo, Inc. (http://nexmo.com)
 * @license   https://github.com/Nexmo/nexmo-php/blob/master/LICENSE.txt MIT License
 */

namespace Nexmo\Verify;

use Nexmo\Client\APIResource;
use Nexmo\Client\ClientAwareInterface;
use Nexmo\Client\ClientAwareTrait;
use Nexmo\Client\Exception;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class Client implements ClientAwareInterface
{
    use ClientAwareTrait;

    /**
     * @var APIResource
     */
    protected $api;

    public function __construct(APIResource $api = null)
    {
        $this->api = $api;
    }

    /**
     * Shim to handle older instatiations of this class
     * @deprecated Will remove in v3
     */
    protected function getApiResource() : APIResource
    {
        if (is_null($this->api)) {
            $api = new APIResource();
            $api->setClient($this->getClient())
                ->setIsHAL(false)
                ->setBaseUri('/verify')
            ;
            $this->api = $api;
        }
        return clone $this->api;
    }

    /**
     * @param string|array|Verification $verification
     */
    public function start($verification) : Verification
    {
        if (is_array($verification)) {
            trigger_error(
                'Passing an array to Nexmo\Verification\Client::start() is deprecated, please pass a Verification object instead',
                E_USER_DEPRECATED
            );
        }
        if (is_string($verification)) {
            trigger_error(
                'Passing a string to Nexmo\Verification\Client::start() is deprecated, please pass a Verification object instead',
                E_USER_DEPRECATED
            );
        }

        $api = $this->getApiResource();
        $verification = $this->createVerification($verification);
        $response = $api->get('json', $verification->toArray());

        $this->processReqRes($verification, $api->getLastRequest(), $api->getLastResponse(), true);
        return $this->checkError($verification, $response);
    }

    /**
     * @param string|Verification $verification
     */
    public function search($verification)
    {
        if ($verification instanceof Verification) {
            trigger_error(
                'Passing a Verification object to Nexmo\Verification\Client::search() is deprecated, please pass a string ID instead',
                E_USER_DEPRECATED
            );
        }

        $api = $this->getApiResource();
        $verification = $this->createVerification($verification);

        $params = [
            'request_id' => $verification->getRequestId()
        ];

        $data = $api->get('search/json', $params);
        $this->processReqRes($verification, $api->getLastRequest(), $api->getLastResponse(), true);

        return $this->checkError($verification, $data);
    }

    public function cancel($verification)
    {
        if ($verification instanceof Verification) {
            trigger_error(
                'Passing a Verification object to Nexmo\Verification\Client::cancel() is deprecated, please pass a string ID instead',
                E_USER_DEPRECATED
            );
        }

        return $this->control($verification, 'cancel');
    }

    public function trigger($verification)
    {
        if ($verification instanceof Verification) {
            trigger_error(
                'Passing a Verification object to Nexmo\Verification\Client::trigger() is deprecated, please pass a string ID instead',
                E_USER_DEPRECATED
            );
        }
        return $this->control($verification, 'trigger_next_event');
    }

    /**
     * @param string|array|Verification $verification
     */
    public function check($verification, string $code, string $ip = null) : Verification
    {
        if (is_array($verification)) {
            trigger_error(
                'Passing an array for parameter 1 to Nexmo\Verification\Client::check() is deprecated, please pass a string ID instead',
                E_USER_DEPRECATED
            );
        }
        if ($verification instanceof Verification) {
            trigger_error(
                'Passing a Verification object for parameter 1 to Nexmo\Verification\Client::check() is deprecated, please pass a string ID instead',
                E_USER_DEPRECATED
            );
        }

        $api = $this->getApiResource();
        $verification = $this->createVerification($verification);
        $params = [
            'request_id' => $verification->getRequestId(),
            'code' => $code
        ];

        if (!is_null($ip)) {
            $params['ip'] = $ip;
        }

        $data = $api->get('check/json', $params);

        $this->processReqRes($verification, $api->getLastRequest(), $api->getLastResponse(), false);
        return $this->checkError($verification, $data);
    }

    /**
     * @deprecated Serialize the Verification object directly instead
     */
    public function serialize(Verification $verification)
    {
        trigger_error(
            get_class($this) . '::serialize() is deprecated, serialize the Verification object directly',
            E_USER_DEPRECATED
        );
        return serialize($verification);
    }

    public function unserialize($verification)
    {
        trigger_error(
            get_class($this) . '::unserialize() is deprecated, unserialize the Verification object directly',
            E_USER_DEPRECATED
        );

        if (is_string($verification)) {
            $verification = unserialize($verification);
        }

        if (!($verification instanceof Verification)) {
            throw new \InvalidArgumentException('expected verification object or serialize verification object');
        }

        $verification->setClient($this);
        return $verification;
    }

    /**
     * @param string|array|Verification $verification
     * @param string $cmd Next command to execute, must be `cancel` or `trigger_next_event`
     */
    protected function control($verification, string $cmd) : Verification
    {
        if (is_array($verification)) {
            trigger_error(
                'Passing an array for parameter 1 to Nexmo\Verification\Client::control() is deprecated, please pass a string ID instead',
                E_USER_DEPRECATED
            );
        }
        if ($verification instanceof Verification) {
            trigger_error(
                'Passing a Verification object for parameter 1 to Nexmo\Verification\Client::control() is deprecated, please pass a string ID instead',
                E_USER_DEPRECATED
            );
        }

        $api = $this->getApiResource();
        $verification = $this->createVerification($verification);

        $params = [
            'request_id' => $verification->getRequestId(),
            'cmd' => $cmd
        ];

        $data = $api->get('control/json', $params);
        $this->processReqRes($verification, $api->getLastRequest(), $api->getLastResponse(), false);
        return $this->checkError($verification, $data);
{'fraction_non_alphanumeric': 0.1171733895243829, 'fraction_numerical': 0.0012040939193257074, 'mean_word_length': 2.29098563645369, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 99, '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': '1963522', 'n_tokens_mistral': 3658, 'n_tokens_neox': 3506, 'n_words': 817}