Code Duplication    Length = 24-24 lines in 2 locations

src/Newsletter.php 2 locations

@@ 36-59 (lines=24) @@
33
     *
34
     * @throws \Spatie\Newsletter\Exceptions\InvalidNewsletterList
35
     */
36
    public function subscribe($email, $mergeFields = [], $listName = '', $options = [])
37
    {
38
        $list = $this->lists->findByName($listName);
39
40
        $defaultOptions = [
41
            'email_address' => $email,
42
            'status' => 'subscribed',
43
            'email_type' => 'html',
44
        ];
45
46
        if (count($mergeFields)) {
47
            $defaultOptions['merge_fields'] = $mergeFields;
48
        }
49
50
        $options = array_merge($defaultOptions, $options);
51
52
        $response = $this->mailChimp->post("lists/{$list->getId()}/members", $options);
53
54
        if (! $this->lastActionSucceeded()) {
55
            return false;
56
        }
57
58
        return $response;
59
    }
60
61
    /**
62
     * @param string $email
@@ 71-94 (lines=24) @@
68
     *
69
     * @throws \Spatie\Newsletter\Exceptions\InvalidNewsletterList
70
     */
71
    public function subscribeOrUpdate($email, $mergeFields = [], $listName = '', $options = [])
72
    {
73
        $list = $this->lists->findByName($listName);
74
75
        $defaultOptions = [
76
            'email_address' => $email,
77
            'status' => 'subscribed',
78
            'email_type' => 'html',
79
        ];
80
81
        if (count($mergeFields)) {
82
            $defaultOptions['merge_fields'] = $mergeFields;
83
        }
84
85
        $options = array_merge($defaultOptions, $options);
86
87
        $response = $this->mailChimp->put("lists/{$list->getId()}/members/{$this->getSubscriberHash($email)}", $options);
88
89
        if (! $this->lastActionSucceeded()) {
90
            return false;
91
        }
92
93
        return $response;
94
    }
95
96
    /**
97
     * @param string $email