SmsExpiring   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 2
A __construct() 0 3 1
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use App\Subscription;
7
use App\Sms_trigger;
8
use Carbon\Carbon;
9
10
class SmsExpiring extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'sms:expiring';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Trigger sms to expiring subscriptions';
25
26
    /**
27
     * Create a new command instance.
28
     *
29
     * @return void
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
    }
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return mixed
40
     */
41
    public function handle()
42
    {
43
        $expirings = Subscription::where('end_date','<=',Carbon::today()->addDays(3))->where('status','=',\constSubscription::onGoing)->get();
44
45
        $sms_trigger = Sms_trigger::where('alias','=','subscription_expiring')->first();
46
        $message = $sms_trigger->message;
47
        $sms_status = $sms_trigger->status;
48
        $sender_id = \Utilities::getSetting('sms_sender_id');
49
50
        foreach ($expirings as $expiring) 
51
        {
52
            $sms_text = sprintf($message,$expiring->member->name,$expiring->end_date->format('d-m-Y'));
53
            \Utilities::Sms($sender_id,$expiring->member->contact,$sms_text,$sms_status);
54
        }
55
        
56
    }
57
}
58