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

SendGroup   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 5
Bugs 3 Features 1
Metric Value
wmc 3
c 5
b 3
f 1
lcom 1
cbo 2
dl 0
loc 69
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A send() 0 23 2
1
<?php
2
3
namespace Fenos\Notifynder\Senders;
4
5
use Fenos\Notifynder\Contracts\NotifynderCategory;
6
use Fenos\Notifynder\Contracts\NotifynderGroup;
7
use Fenos\Notifynder\Contracts\DefaultSender;
8
use Fenos\Notifynder\Contracts\StoreNotification;
9
use Fenos\Notifynder\NotifynderManager;
10
11
/**
12
 * Class SendGroup.
13
 */
14
class SendGroup implements DefaultSender
15
{
16
    /**
17
     * @var NotifynderManager
18
     */
19
    protected $notifynder;
20
21
    /**
22
     * @var string
23
     */
24
    protected $nameGroup;
25
26
    /**
27
     * @var array
28
     */
29
    protected $info;
30
31
    /**
32
     * @var NotifynderCategory
33
     */
34
    protected $notifynderCategory;
35
36
    /**
37
     * @param NotifynderGroup    $notifynderGroup
38
     * @param NotifynderCategory $notifynderCategory
39
     * @param string             $nameGroup
40
     * @param array | \Closure   $info
41
     */
42
    public function __construct(NotifynderGroup $notifynderGroup,
43
                         NotifynderCategory $notifynderCategory,
44
                         $nameGroup,
45
                         array $info)
46
    {
47
        $this->info = $info;
48
        $this->nameGroup = $nameGroup;
49
        $this->notifynderGroup = $notifynderGroup;
0 ignored issues
show
Bug introduced by
The property notifynderGroup does not seem to exist. Did you mean notifynder?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
50
        $this->notifynderCategory = $notifynderCategory;
51
    }
52
53
    /**
54
     * Send group notifications.
55
     *
56
     * @param  StoreNotification $sender
57
     * @return mixed
58
     */
59
    public function send(StoreNotification $sender)
60
    {
61
        // Get group
62
        $group = $this->notifynderGroup->findByName($this->nameGroup);
0 ignored issues
show
Bug introduced by
The property notifynderGroup does not seem to exist. Did you mean notifynder?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
63
64
        // Categories
65
        $categoriesAssociated = $group->categories;
66
67
        // Send a notification for each category
68
        foreach ($categoriesAssociated as $category) {
69
            // Category name
70
            $categoryModel = $this->notifynderCategory->findByName($category->name);
71
72
            $notification = array_merge(
73
                ['category_id' => $categoryModel->id],
74
                $this->info
75
            );
76
77
            $sender->storeSingle($notification);
78
        }
79
80
        return $group;
81
    }
82
}
83