WhatsappNotify::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Artisanpay\WhatsappNotify;
4
5
use Symfony\Component\HttpClient\HttpClient;
6
7
class WhatsappNotify
8
{
9
    private  $client;
10
    public function __construct()
11
    {
12
        $this->client = HttpClient::create();
13
    }
14
15
    /**
16
     * send push message to whatsapp
17
     * @param string $to
18
     * @param string $content
19
     * @return bool
20
     * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
21
     */
22
    public function send(string $to , string $content)
23
    {
24
        try {
25
            $this->client->request('POST', config('whatsapp.server_url'), [
26
                'json' => [
27
                    'to' => $to,
28
                    'content' => $content,
29
                ]
30
            ]);
31
            return true;
32
        } catch (\Exception $e) {
33
            return false;
34
        }
35
    }
36
}
37