<commit_before><?php

namespace Mcfedr\AwsPushBundle\Service;

use Aws\Sns\Exception\SnsException;
use Aws\Sns\SnsClient;
use Mcfedr\AwsPushBundle\Exception\PlatformNotConfiguredException;

class Devices
{

    /**
     * @var SnsClient
     */
    private $sns;

    /**
     * @var array
     */
    private $arns;

    /**
     * @param SnsClient $client
     * @param array $platformARNS
     */
    public function __construct(SnsClient $client, $platformARNS)
    {
        $this->sns = $client;
        $this->arns = $platformARNS;
    }

    /**
     * Register a device token
     *
     * @param string $deviceId device token
     * @param string $platform platform on which to register
     * @return string the endpoint ARN for this device
     * @throws PlatformNotConfiguredException
     */
    public function registerDevice($deviceId, $platform)
    {
        if (!isset($this->arns[$platform])) {
            throw new PlatformNotConfiguredException("There is no configured ARN for $platform");
        }

        try {
            $res = $this->sns->createPlatformEndpoint(
                [
                    'PlatformApplicationArn' => $this->arns[$platform],
                    'Token' => $deviceId,
                    'Attributes' => [
                        'Enabled' => 'true'
                    ]
                ]
            );
        } catch (SnsException $e) {
            preg_match('/Endpoint (.+?) already/', $e->getMessage(), $matches);
            if (isset($matches[1])) {
                $this->sns->setEndpointAttributes(
                    [
                        'EndpointArn' => $matches[1],
                        'Attributes' => [
                            'Enabled' => 'true'
                        ]
                    ]
                );
                return $matches[1];
            } else {
                throw $e;
            }
        }

        return $res['EndpointArn'];
    }

    /**
     * Unregister a device, using its endpoint ARN
     *
     * @param string $endpoint
     */
    public function unregisterDevice($endpoint)<commit_msg>Added user data to args, when registering device on Aws Sns.<commit_after><?php

namespace Mcfedr\AwsPushBundle\Service;

use Aws\Sns\Exception\SnsException;
use Aws\Sns\SnsClient;
use Mcfedr\AwsPushBundle\Exception\PlatformNotConfiguredException;

class Devices
{

    /**
     * @var SnsClient
     */
    private $sns;

    /**
     * @var array
     */
    private $arns;

    /**
     * @param SnsClient $client
     * @param array $platformARNS
     */
    public function __construct(SnsClient $client, $platformARNS)
    {
        $this->sns = $client;
        $this->arns = $platformARNS;
    }

    /**
     * Register a device token
     *
     * @param string $deviceId device token
     * @param string $platform platform on which to register
     * @param string $userData
     * @return string the endpoint ARN for this device
     * @throws PlatformNotConfiguredException
     * @throws \Exception
     */
    public function registerDevice($deviceId, $platform, $userData = null)
    {
        if (!isset($this->arns[$platform])) {
            throw new PlatformNotConfiguredException("There is no configured ARN for $platform");
        }

        try {
            $args = [
                'PlatformApplicationArn' => $this->arns[$platform],
                'Token' => $deviceId,
                'Attributes' => [
                    'Enabled' => 'true'
                ]
            ];

            if ($userData && is_string($userData)) {
                $args['CustomUserData'] = $userData;
            }

            $res = $this->sns->createPlatformEndpoint($args);
        } catch (SnsException $e) {
            preg_match('/Endpoint (.+?) already/', $e->getMessage(), $matches);
            if (isset($matches[1])) {
                $this->sns->setEndpointAttributes(
                    [
                        'EndpointArn' => $matches[1],
                        'Attributes' => [
                            'Enabled' => 'true'
                        ]
                    ]
                );
                return $matches[1];
            } else {
                throw $e;
            }
        }

        return $res['EndpointArn'];
    }

    /**
     * Unregister a device, using its endpoint ARN
     *
     * @param string $endpoint
     */
    public function unregisterDevice($endpoint)
{'fraction_non_alphanumeric': 0.11805711715763437, 'fraction_numerical': 0.0013492241960872497, 'mean_word_length': 1.5344729344729344, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, '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': '5002355', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1178, 'n_words': 264}