Completed
Push — master ( 9abbc7...a687e5 )
by Fabrizio
03:03
created

SendOne::hasCategory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 3 Features 1
Metric Value
c 4
b 3
f 1
dl 0
loc 11
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace Fenos\Notifynder\Senders;
4
5
use Fenos\Notifynder\Contracts\DefaultSender;
6
use Fenos\Notifynder\Contracts\StoreNotification;
7
use Fenos\Notifynder\Exceptions\CategoryNotFoundException;
8
9
/**
10
 * Class SendSingle.
11
 *
12
 * Send a single notification
13
 */
14
class SendOne implements DefaultSender
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $infoNotification = [];
20
21
    /**
22
     * @param   $infoNotification
23
     */
24
    public function __construct($infoNotification)
25
    {
26
        $this->infoNotification = $infoNotification;
27
    }
28
29
    /**
30
     * Send Single notification.
31
     *
32
     * @param  StoreNotification $sender
33
     * @return mixed
34
     */
35
    public function send(StoreNotification $sender)
36
    {
37
        $this->hasCategory();
38
39
        return $sender->storeSingle($this->infoNotification);
40
    }
41
42
    /**
43
     * Check if the category of the notification has been
44
     * specified in the array of information.
45
     *
46
     * @return bool
47
     * @throws \Fenos\Notifynder\Exceptions\CategoryNotFoundException
48
     */
49
    protected function hasCategory()
50
    {
51
        if (! array_key_exists('category_id', $this->infoNotification)) {
52
            $error = 'Category not found please provide one,
53
                     you can not store a notification without category id';
54
55
            throw new CategoryNotFoundException($error);
56
        }
57
58
        return true;
59
    }
60
}
61