Mailqueues::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 21
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php namespace crocodicstudio\crudbooster\commands;
2
3
use Cache;
4
use CRUDBooster;
0 ignored issues
show
Bug introduced by
The type CRUDBooster was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use DB;
6
use Illuminate\Console\Command;
7
use Request;
8
9
class Mailqueues extends Command
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'mailqueues';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Run Mail Queues';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return mixed
29
     */
30
    public function handle()
31
    {
32
33
34
        $now = date('Y-m-d H:i:s');
35
36
        $this->comment('Mail Queues Started '.$now);
37
38
        $queues = DB::table('cms_email_queues')->where('send_at', '<=', $now)->take($limit_an_hour)->get();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $limit_an_hour seems to be never defined.
Loading history...
39
40
        $this->comment('Total Queues : '.count($queues));
41
42
        Cache::increment('total_email_sent', count($queues));
43
        Cache::put('last_email_sent', date('Y-m-d H:i:s'));
0 ignored issues
show
Bug introduced by
The call to Illuminate\Support\Facades\Cache::put() has too few arguments starting with ttl. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        Cache::/** @scrutinizer ignore-call */ 
44
               put('last_email_sent', date('Y-m-d H:i:s'));

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
44
45
        foreach ($queues as $q) {
46
            if (filter_var($q->email_recipient, FILTER_VALIDATE_EMAIL) !== false) {
47
                CRUDBooster::sendEmailQueue($queue);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $queue does not exist. Did you maybe mean $queues?
Loading history...
48
                $this->comment('Email send -> '.$q->subject);
49
            }
50
            DB::table('mailqueues')->where('id', $q->id)->delete();
51
        }
52
    }
53
}
54