EmailJobs::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php namespace JobApis\JobsToMail\Console\Commands;
2
3
use Illuminate\Console\Command;
4
use Illuminate\Foundation\Bus\DispatchesJobs;
5
use JobApis\JobsToMail\Jobs\Notifications\SearchAndNotifyUser;
6
use JobApis\JobsToMail\Repositories\Contracts\SearchRepositoryInterface;
7
8
class EmailJobs extends Command
9
{
10
    use DispatchesJobs;
11
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'jobs:email {--email=}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Sends job listings for each search created by an active user.';
25
26
    /**
27
     * @var SearchRepositoryInterface
28
     */
29
    protected $searches;
30
31
    /**
32
     * Create a new command instance.
33
     *
34
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
35
     */
36
    public function __construct(SearchRepositoryInterface $searches)
37
    {
38
        parent::__construct();
39
        $this->searches = $searches;
40
    }
41
42
    /**
43
     * Goes through each user and queues up a task to collect and email them their jobs.
44
     *
45
     * @return mixed
46
     */
47
    public function handle()
48
    {
49
        $count = 0;
50
        foreach ($this->searches->getActive($this->option('email')) as $search) {
51
            $this->dispatch(new SearchAndNotifyUser($search));
52
            $count++;
53
        }
54
        return $this->info("{$count} job searches queued for collection.");
55
    }
56
}
57