1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LBHurtado\EngageSpark\Jobs; |
4
|
|
|
|
5
|
|
|
use Illuminate\Bus\Queueable; |
6
|
|
|
use LBHurtado\EngageSpark\EngageSpark; |
7
|
|
|
use Illuminate\Queue\SerializesModels; |
8
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
9
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
10
|
|
|
use Illuminate\Foundation\Bus\Dispatchable; |
11
|
|
|
use LBHurtado\EngageSpark\Classes\ServiceMode; |
12
|
|
|
use LBHurtado\EngageSpark\Classes\SendHttpApiParams; |
13
|
|
|
|
14
|
|
View Code Duplication |
class SendMessage implements ShouldQueue |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
17
|
|
|
|
18
|
|
|
/** @var string */ |
19
|
|
|
public $mobile; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
public $message; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
public $senderId; |
26
|
|
|
|
27
|
|
|
/** @var EngageSpark */ |
28
|
|
|
public $service; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* SendMessage constructor. |
32
|
|
|
* @param string $mobile |
33
|
|
|
* @param string $message |
34
|
|
|
* @param string $senderId |
35
|
|
|
*/ |
36
|
|
|
public function __construct(string $mobile, string $message, string $senderId = null) |
37
|
|
|
{ |
38
|
|
|
$this->mobile = $mobile; |
39
|
|
|
$this->message = $message; |
40
|
|
|
$this->senderId = $senderId; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param EngageSpark $service |
45
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
46
|
|
|
*/ |
47
|
|
|
public function handle(EngageSpark $service) |
48
|
|
|
{ |
49
|
|
|
$this->setService($service)->send(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function send() |
53
|
|
|
{ |
54
|
|
|
tap(new SendHttpApiParams($this->service, $this->mobile, $this->message, $this->senderId), function ($params) { |
55
|
|
|
$this->service->send($params->toArray(), ServiceMode::SMS); |
56
|
|
|
}); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function setService(EngageSpark $service) |
60
|
|
|
{ |
61
|
|
|
$this->service = $service; |
62
|
|
|
|
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.