PeriodicPublicationNotification::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
namespace PeriodicNotice\Notifications;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Contracts\Queue\ShouldQueue;
7
use Illuminate\Notifications\Notification;
8
use Illuminate\Support\Collection;
9
10
class PeriodicPublicationNotification extends Notification implements ShouldQueue
11
{
12
    use Queueable;
13
    use HasDynamicChannels {
14
        HasDynamicChannels::via as dynamicVia;
15
    }
16
17 2
    public function __construct(
18
        protected Collection $entities
19
    ) {
20 2
    }
21
22 1
    public function via($notifiable)
23
    {
24 1
        if ($this->entities->count() > 0) {
25 1
            return $this->dynamicVia($notifiable);
26
        }
27
28
        return [];
29
    }
30
31 1
    protected function mailMessageBuilder($notifiable): MailMessageBuilder
0 ignored issues
show
Unused Code introduced by
The parameter $notifiable is not used and could be removed. ( Ignorable by Annotation )

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

31
    protected function mailMessageBuilder(/** @scrutinizer ignore-unused */ $notifiable): MailMessageBuilder

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
    {
33 1
        $className = config('periodic-notice.defaults.mail_builder', MailMessageBuilder::class);
34 1
        if (!is_a($className, MailMessageBuilder::class, true)) {
35
            throw new \Exception('Wrong mail builder class');
36
        }
37
38 1
        return $className::make();
39
    }
40
41 1
    public function toMail($notifiable)
42
    {
43 1
        return $this->mailMessageBuilder($notifiable)
44 1
                    ->useEntries($this->entities)
45 1
                    ->build();
46
    }
47
}
48