<commit_before><?php
/**
 * SocialConnect project
 * @author: <NAME> @ovr <<EMAIL>>
 */

namespace SocialConnect\Vk;

use SocialConnect\Common\HttpClient;

class Client extends \SocialConnect\Common\ClientAbstract
{
    use HttpClient;
    use Constants;

    /**
     * @link http://vk.com/dev/versions
     */
    const VK_API_VERSION = 5.24;

    /**
     * @var Entity\User
     */
    protected $entityUser;

    /**
     * @var Entity\Audio
     */
    protected $entityAudio;

    /**
     * @var Entity\Friend
     */
    protected $entityFriend;

    /**
     * {@inheritdoc}
     */
    public function __construct($appId, $appSecret, $accessToken = null)
    {
        parent::__construct($appId, $appSecret, $accessToken);

        /**
         * Init base entities
         */
        $this->entityUser = new Entity\User();
        $this->entityAudio = new Entity\Audio();
        $this->entityFriend = new Entity\Friend();
    }

    /**
     * @var array
     */
    protected $baseParameters = array(
        'v' => self::VK_API_VERSION
    );

    /**
     * @param string $accessToken
     */
    public function setAccessToken($accessToken)
    {
        $this->accessToken = $accessToken;
    }

    /**
     * @return \SocialConnect\Common\Hydrator\CloneObjectMap
     */
    public function getHydrator($object)
    {
        /**
         * @todo Think more about cache hydrators in class property
         */

        return new \SocialConnect\Common\Hydrator\CloneObjectMap(array(
            'id' => 'id',
            'first_name' => 'firstname',
            'last_name' => 'lastname',
            'hidden' => 'hidden',
            'deactivated' => 'deactivated',
            'owner_id' => 'ownerId',
            'sex' => 'sex',
            //Audio
            'artist' => 'artist',
            'title' => 'title',
            'duration' => 'duration',
            'url' => 'url',
            'genre_id' => 'genreId',
            'lyrics_id' => 'lyricsId',
            'no_search' => 'noSearch',
            'album_id' => 'albumId'
        ), $object);
    }

    /**
     * Request social server API
     *
     * @param string $uri
     * @param array $parameters
     * @param bool $accessToken
     * @return mixed
     * @throws Exception
     */
    public function request($uri, array $parameters = array(), $accessToken = false)
    {
        if ($accessToken) {
            $this->baseParameters['access_token'] = $this->accessToken;
        }

        $parameters = array_merge($this->baseParameters, $parameters);
        foreach ($parameters as $key => $parameter) {
            if (is_array($parameter)) {
                $parameters[$key] = implode(',', $parameter);
            }
        }

        $response = $this->httpClient->request('https://api.vk.com/' . $uri, $parameters);

        if ($response) {
            if ($response->isServerError()) {
                throw new Exception\ServerError($response);
            }

            $body = $response->getBody();
            if ($body) {
                $json = json_decode($body);

                if (isset($json->response)) {
                    return $json->response;
                } else {
                    if (isset($json->error)) {
                        throw new Exception($json->error->error_msg, $json->error->error_code);
                    }
                }
            } else {
                throw new Exception\ServerError($response);
            }
        }

        return false;
    }

    /**
     * @link http://vk.com/dev/users.get
     *
     * @param integer $id
     * @param array $fields
     * @return bool|object
     */
    public function getUser($id, array $fields = array('id', 'first_name', 'last_name'))
    {
        $parameters = array(
            'user_id' => $id
        );

        if ($fields != $this->USER_DEFAULT_FIELDS) {
            $parameters['fields'] = $fields;
        }

        $result = $this->request('method/getProfiles', $parameters);

        if ($result) {
            $result = $result[0];<commit_msg>Client - use latest VK Version<commit_after><?php
/**
 * SocialConnect project
 * @author: <NAME> @ovr <<EMAIL>>
 */

namespace SocialConnect\Vk;

use SocialConnect\Common\HttpClient;

class Client extends \SocialConnect\Common\ClientAbstract
{
    use HttpClient;
    use Constants;

    /**
     * @link http://vk.com/dev/versions
     */
    const VK_API_VERSION = 5.37;

    /**
     * @var Entity\User
     */
    protected $entityUser;

    /**
     * @var Entity\Audio
     */
    protected $entityAudio;

    /**
     * @var Entity\Friend
     */
    protected $entityFriend;

    /**
     * {@inheritdoc}
     */
    public function __construct($appId, $appSecret, $accessToken = null)
    {
        parent::__construct($appId, $appSecret, $accessToken);

        /**
         * Init base entities
         */
        $this->entityUser = new Entity\User();
        $this->entityAudio = new Entity\Audio();
        $this->entityFriend = new Entity\Friend();
    }

    /**
     * @var array
     */
    protected $baseParameters = array(
        'v' => self::VK_API_VERSION
    );

    /**
     * @param string $accessToken
     */
    public function setAccessToken($accessToken)
    {
        $this->accessToken = $accessToken;
    }

    /**
     * @return \SocialConnect\Common\Hydrator\CloneObjectMap
     */
    public function getHydrator($object)
    {
        /**
         * @todo Think more about cache hydrators in class property
         */

        return new \SocialConnect\Common\Hydrator\CloneObjectMap(array(
            'id' => 'id',
            'first_name' => 'firstname',
            'last_name' => 'lastname',
            'hidden' => 'hidden',
            'deactivated' => 'deactivated',
            'owner_id' => 'ownerId',
            'sex' => 'sex',
            //Audio
            'artist' => 'artist',
            'title' => 'title',
            'duration' => 'duration',
            'url' => 'url',
            'genre_id' => 'genreId',
            'lyrics_id' => 'lyricsId',
            'no_search' => 'noSearch',
            'album_id' => 'albumId'
        ), $object);
    }

    /**
     * Request social server API
     *
     * @param string $uri
     * @param array $parameters
     * @param bool $accessToken
     * @return mixed
     * @throws Exception
     */
    public function request($uri, array $parameters = array(), $accessToken = false)
    {
        if ($accessToken) {
            $this->baseParameters['access_token'] = $this->accessToken;
        }

        $parameters = array_merge($this->baseParameters, $parameters);
        foreach ($parameters as $key => $parameter) {
            if (is_array($parameter)) {
                $parameters[$key] = implode(',', $parameter);
            }
        }

        $response = $this->httpClient->request('https://api.vk.com/' . $uri, $parameters);
var_dump($response);
        if ($response) {
            if ($response->isServerError()) {
                throw new Exception\ServerError($response);
            }

            $body = $response->getBody();
            if ($body) {
                $json = json_decode($body);

                if (isset($json->response)) {
                    return $json->response;
                } else {
                    if (isset($json->error)) {
                        throw new Exception($json->error->error_msg, $json->error->error_code);
                    }
                }
            } else {
                throw new Exception\ServerError($response);
            }
        }

        return false;
    }

    /**
     * @link http://vk.com/dev/users.get
     *
     * @param integer $id
     * @param array $fields
     * @return bool|object
     */
    public function getUser($id, array $fields = array('id', 'first_name', 'last_name'))
    {
        $parameters = array(
            'user_id' => $id
        );

        if ($fields != $this->USER_DEFAULT_FIELDS) {
            $parameters['fields'] = $fields;
        }

        $result = $this->request('method/getProfiles', $parameters);
        if ($result) {
            $result = $result[0];
{'fraction_non_alphanumeric': 0.1475910980679873, 'fraction_numerical': 0.0009782342871117633, 'mean_word_length': 1.6869250985545334, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 85, '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': '454237', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2303, 'n_words': 468}