<commit_before><?php

namespace Edujugon\PushNotification;


use GuzzleHttp\Client;

class Fcm extends Gcm
{

    /**
     * Fcm constructor.
     * Override parent constructor.
     */
    public function __construct()
    {
        $this->url = 'https://fcm.googleapis.com/fcm/send';

        $this->config = $this->initializeConfig('fcm');

        $this->client = new Client();
    }

    /**
     * Send notification by topic.
     * if isCondition is true, $topic will be treated as an expression
     *
     * @param $topic
     * @param bool $isCondition
     * @return object
     */
    public function sendByTopic($topic, $isCondition = false)
    {
        $headers = $this->addRequestHeaders();

        $data = $this->buildData($topic, $isCondition);

        try {
            $result = $this->client->post(
                $this->url,
                [
                    'headers' => $headers,
                    'json' => $data,
                ]
            );

            $json = $result->getBody();

            $this->setFeedback(json_decode($json));

        } catch (\Exception $e) {
            $response = ['success' => false, 'error' => $e->getMessage()];

            $this->setFeedback(json_decode(json_encode($response), FALSE));

        } finally {
            return $this->feedback;
        }
    }

    /**
     * Prepare the data to be sent
     *
     * @param $topic
     * @param $isCondition
     * @return array
     */
    protected function buildData($topic, $isCondition)
    {
        if (!$isCondition) {

            return [
                'to' => '/topics/' . $topic,
                'data' => $this->message
            ];

        } else {
            return [
                'condition' => $topic,
                'data' => $this->message
            ];
        }
    }
}<commit_msg>Fix sendByTopic method<commit_after><?php

namespace Edujugon\PushNotification;


use GuzzleHttp\Client;

class Fcm extends Gcm
{

    /**
     * Fcm constructor.
     * Override parent constructor.
     */
    public function __construct()
    {
        $this->url = 'https://fcm.googleapis.com/fcm/send';

        $this->config = $this->initializeConfig('fcm');

        $this->client = new Client();
    }

    /**
     * Send notification by topic.
     * if isCondition is true, $topic will be treated as an expression
     *
     * @param $topic
     * @param $message
     * @param bool $isCondition
     * @return object
     */
    public function sendByTopic($topic,$message, $isCondition = false)
    {
        $headers = $this->addRequestHeaders();
        $data = $this->buildData($topic, $message, $isCondition);

        try {
            $result = $this->client->post(
                $this->url,
                [
                    'headers' => $headers,
                    'json' => $data,
                ]
            );

            $json = $result->getBody();

            $this->setFeedback(json_decode($json));

        } catch (\Exception $e) {
            $response = ['success' => false, 'error' => $e->getMessage()];

            $this->setFeedback(json_decode(json_encode($response), FALSE));

        } finally {
            return $this->feedback;
        }
    }

    /**
     * Prepare the data to be sent
     *
     * @param $topic
     * @param $message
     * @param $isCondition
     * @return array
     */
    protected function buildData($topic, $message, $isCondition)
    {
        $condition = $isCondition ? ['condition' => $topic] : ['to' => '/topics/' . $topic];

        return array_merge($condition , $this->buildMessage($message));
    }
}
{'fraction_non_alphanumeric': 0.14395816129920175, 'fraction_numerical': 0.0, 'mean_word_length': 1.6799410029498525, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 48, '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': '3974385', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1013, 'n_words': 224}