Register::body()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 39
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 34
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 30
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 39
ccs 34
cts 34
cp 1
crap 3
rs 9.44
1
<?php
2
3
namespace LaravelWorkcast\RegistrationEndpoints;
4
5
use Illuminate\Http\Client\Response;
6
use Illuminate\Support\Str;
7
8
class Register extends AbstractEndpoint
9
{
10
    protected string $eventPak = '';
11
12
    protected array $eventSessions = [];
13
14
    protected string $contactTitle = '';
15
16
    protected string $contactFirstName = '';
17
18
    protected string $contactLastName = '';
19
20
    protected string $contactEmail = '';
21
22
    protected string $contactPhone = '';
23
24
    protected string $contactJobTitle = '';
25
26
    protected string $contactCompany = '';
27
28
    protected string $contactAddressLine1 = '';
29
30
    protected string $contactAddressLine2 = '';
31
32
    protected string $contactAddressLine3 = '';
33
34
    protected string $contactCity = '';
35
36
    protected string $contactCountyOrState = '';
37
38
    protected string $contactPostcode = '';
39
40
    protected string $contactCountryCode = '';
41
42
    protected array $contactCustomItems = [];
43
44 1
    public function eventPak(string $eventPak): static
45
    {
46 1
        $this->eventPak = Str::limit($eventPak, 16, '');
47
48 1
        return $this;
49
    }
50
51 1
    public function addEventSession(string $sessionPak): static
52
    {
53 1
        $sessionPak = Str::limit($sessionPak, 16, '');
54 1
        if (!in_array($sessionPak, $this->eventSessions)) {
55 1
            $this->eventSessions[] = $sessionPak;
56
        }
57
58 1
        return $this;
59
    }
60
61 1
    public function contactTitle(string $contactTitle): static
62
    {
63 1
        $this->contactTitle = Str::limit($contactTitle, 20, '');
64
65 1
        return $this;
66
    }
67
68 1
    public function contactFirstName(string $contactFirstName): static
69
    {
70 1
        $this->contactFirstName = Str::limit($contactFirstName, 50, '');
71
72 1
        return $this;
73
    }
74
75 1
    public function contactLastName(string $contactLastName): static
76
    {
77 1
        $this->contactLastName = Str::limit($contactLastName, 20, '');
78
79 1
        return $this;
80
    }
81
82 1
    public function contactEmail(string $contactEmail): static
83
    {
84 1
        $this->contactEmail = Str::limit($contactEmail, 100, '');
85
86 1
        return $this;
87
    }
88
89 1
    public function contactPhone(string $contactPhone): static
90
    {
91 1
        $this->contactPhone = Str::limit($contactPhone, 20, '');
92
93 1
        return $this;
94
    }
95
96 1
    public function contactJobTitle(string $contactJobTitle): static
97
    {
98 1
        $this->contactJobTitle = Str::limit($contactJobTitle, 50, '');
99
100 1
        return $this;
101
    }
102
103 1
    public function contactCompany(string $contactCompany): static
104
    {
105 1
        $this->contactCompany = Str::limit($contactCompany, 50, '');
106
107 1
        return $this;
108
    }
109
110 1
    public function contactAddressLine1(string $contactAddressLine1): static
111
    {
112 1
        $this->contactAddressLine1 = Str::limit($contactAddressLine1, 30, '');
113
114 1
        return $this;
115
    }
116
117 1
    public function contactAddressLine2(string $contactAddressLine2): static
118
    {
119 1
        $this->contactAddressLine2 = Str::limit($contactAddressLine2, 30, '');
120
121 1
        return $this;
122
    }
123
124 1
    public function contactAddressLine3(string $contactAddressLine3): static
125
    {
126 1
        $this->contactAddressLine3 = Str::limit($contactAddressLine3, 30, '');
127
128 1
        return $this;
129
    }
130
131 1
    public function contactCity(string $contactCity): static
132
    {
133 1
        $this->contactCity = Str::limit($contactCity, 20, '');
134
135 1
        return $this;
136
    }
137
138 1
    public function contactCountyOrState(string $contactCountyOrState): static
139
    {
140 1
        $this->contactCountyOrState =  Str::limit($contactCountyOrState, 20, '');
141
142 1
        return $this;
143
    }
144
145 1
    public function contactPostcode(string $contactPostcode): static
146
    {
147 1
        $this->contactPostcode = Str::limit($contactPostcode, 20, '');
148
149 1
        return $this;
150
    }
151
152 1
    public function contactCountryCode(string $contactCountryCode): static
153
    {
154 1
        $this->contactCountryCode = Str::limit($contactCountryCode, 5, '');
155
156 1
        return $this;
157
    }
158
159 1
    public function addContactContactCustomItem(string $key, mixed $value): static
160
    {
161 1
        $this->contactCustomItems[$key] = $value;
162
163 1
        return $this;
164
    }
165
166 1
    protected function body(): array
167
    {
168 1
        $customItems = [];
169 1
        foreach ($this->contactCustomItems as $key => $value) {
170 1
            $customItems[] = [
171 1
                'itemDesc'  => $key,
172 1
                'itemValue' => $value,
173 1
            ];
174
        }
175
176 1
        $sessions = [];
177 1
        foreach ($this->eventSessions as $pak) {
178 1
            $sessions[] = [
179 1
                'sessionPak' => $pak,
180 1
            ];
181
        }
182
183 1
        return [
184 1
            'registration' => [
185 1
                'event' => [
186 1
                    'eventPak' => $this->eventPak,
187 1
                    'sessions' => $sessions,
188 1
                ],
189 1
                'contact' => [
190 1
                    'title'              => $this->contactTitle,
191 1
                    'firstName'          => $this->contactFirstName,
192 1
                    'lastName'           => $this->contactLastName,
193 1
                    'email'              => $this->contactEmail,
194 1
                    'phone'              => $this->contactPhone,
195 1
                    'jobTitle'           => $this->contactJobTitle,
196 1
                    'company'            => $this->contactCompany,
197 1
                    'addressLine1'       => $this->contactAddressLine1,
198 1
                    'addressLine2'       => $this->contactAddressLine2,
199 1
                    'addressLine3'       => $this->contactAddressLine3,
200 1
                    'city'               => $this->contactCity,
201 1
                    'countyOrState'      => $this->contactCountyOrState,
202 1
                    'postCode'           => $this->contactPostcode,
203 1
                    'countryCode'        => $this->contactCountryCode,
204 1
                    'contactCustomItems' => $customItems,
205 1
                ],
206 1
            ],
207 1
        ];
208
    }
209
210 1
    public function send(): Response
211
    {
212 1
        return $this->httpClient()->put('register', $this->body());
213
    }
214
}
215