Passed
Push — master ( 5e9e3d...710625 )
by Maciej
04:36 queued 11s
created

AccountCreateHandler::getApiEndpoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * File: AccountCreateHandler.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\FreshMail\Handler\Account;
10
11
use MSlwk\FreshMail\Handler\AbstractHandler;
12
13
/**
14
 * Class AccountCreateHandler
15
 *
16
 * @package MSlwk\FreshMail\Handler\Account
17
 */
18
class AccountCreateHandler extends AbstractHandler
19
{
20
    const API_ENDPOINT = '/rest/account/create';
21
22
    /**
23
     * @param string $login
24
     * @param string $password
25
     * @param string $firstname
26
     * @param string $lastname
27
     * @param string $phoneNumber
28
     * @param string $company
29
     * @param bool $sendActivationEmail
30
     * @param bool $requireActivation
31
     * @param bool $isChildAccount
32
     * @return \stdClass
33
     */
34 91
    public function registerNewAccount(
35
        string $login,
36
        string $password,
37
        string $firstname,
38
        string $lastname,
39
        string $phoneNumber,
40
        string $company = '',
41
        bool $sendActivationEmail = true,
42
        bool $requireActivation = true,
43
        bool $isChildAccount = false
44
    ): \stdClass {
45 91
        $getParameters = [];
46 26
        $postParameters = [
47 91
            'login' => $login,
48 91
            'password' => $password,
49 91
            'firstname' => $firstname,
50 91
            'lastname' => $lastname,
51 91
            'phone' => $phoneNumber,
52
            'company' => $company ?: null,
53 91
            'activation_mail' => $sendActivationEmail,
54 91
            'activation' => $requireActivation,
55 91
            'child_account' => $isChildAccount
56
        ];
57
58 65
        $postParameters = array_filter($postParameters, function ($value) {
59 91
            return $value !== null;
60 91
        });
61 91
        $response = $this->processRequest($getParameters, $postParameters);
62 7
        return $response->data;
63
    }
64
65
    /**
66
     * @return string
67
     */
68 7
    protected function getApiEndpoint(): string
69
    {
70 7
        return self::API_ENDPOINT;
71
    }
72
}
73