CampaignEditHandler::editCampaign()   B
last analyzed

Complexity

Conditions 11
Paths 1

Size

Total Lines 33
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 28.6394

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 17
c 1
b 0
f 0
nc 1
nop 11
dl 0
loc 33
ccs 9
cts 19
cp 0.4737
crap 28.6394
rs 7.3166

How to fix   Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * File: CampaignEditHandler.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\FreshMail\Handler\Campaign;
10
11
use MSlwk\FreshMail\Handler\AbstractHandler;
12
13
/**
14
 * Class CampaignEditHandler
15
 *
16
 * @package MSlwk\FreshMail\Handler\Campaign
17
 */
18
class CampaignEditHandler extends AbstractHandler
19
{
20
    const API_ENDPOINT = '/rest/campaigns/edit';
21
22
    /**
23
     * @param string $campaignHash
24
     * @param string $name
25
     * @param string $urlToDownloadContent
26
     * @param string $content
27
     * @param string $subject
28
     * @param string $fromAddress
29
     * @param string $fromName
30
     * @param string $replyTo
31
     * @param string $listHash
32
     * @param string $groupHash
33
     * @param string $resignLink
34
     * @return null
35
     */
36 21
    public function editCampaign(
37
        string $campaignHash,
38
        string $name = '',
39
        string $urlToDownloadContent = '',
40
        string $content = '',
41
        string $subject = '',
42
        string $fromAddress = '',
43
        string $fromName = '',
44
        string $replyTo = '',
45
        string $listHash = '',
46
        string $groupHash = '',
47
        string $resignLink = ''
48
    ) {
49 21
        $getParameters = [];
50 6
        $postParameters = [
51 21
            'id_hash' => $campaignHash,
52
            'name' => $name ?: null,
53
            'url' => $urlToDownloadContent ?: null,
54
            'html' => $content ?: null,
55
            'subject' => $subject ?: null,
56
            'from_address' => $fromAddress ?: null,
57
            'from_name' => $fromName ?: null,
58
            'reply_to' => $replyTo ?: null,
59
            'list' => $listHash ?: null,
60
            'group' => $groupHash ?: null,
61
            'resignlink' => $resignLink ?: null
62
        ];
63
64 15
        $postParameters = array_filter($postParameters, function ($value) {
65 21
            return $value !== null;
66 21
        });
67 21
        $this->processRequest($getParameters, $postParameters);
68 7
        return null;
69
    }
70
71
    /**
72
     * @return string
73
     */
74 7
    protected function getApiEndpoint(): string
75
    {
76 7
        return self::API_ENDPOINT;
77
    }
78
}
79