1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This software may be modified and distributed under the terms |
7
|
|
|
* of the MIT license. See the LICENSE file for details. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace FAPI\Sylius\Api; |
11
|
|
|
|
12
|
|
|
use FAPI\Sylius\Exception; |
13
|
|
|
use FAPI\Sylius\Exception\Domain as DomainExceptions; |
14
|
|
|
use FAPI\Sylius\Exception\InvalidArgumentException; |
15
|
|
|
use FAPI\Sylius\Model\Customer\Customer as Model; |
16
|
|
|
use Psr\Http\Message\ResponseInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Kasim Taskin <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
final class Customer extends HttpApi |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @param string $message |
|
|
|
|
25
|
|
|
* @param string $location |
|
|
|
|
26
|
|
|
* @param array $hashtags |
|
|
|
|
27
|
|
|
* |
28
|
|
|
* @throws Exception |
29
|
|
|
* |
30
|
|
|
* @return Customer|ResponseInterface |
31
|
|
|
*/ |
32
|
|
|
public function create(string $email, string $firstName, string $lastName, string $gender, array $optionalParams = []) |
33
|
|
|
{ |
34
|
|
|
if (empty($email)) { |
35
|
|
|
throw new InvalidArgumentException('Email cannot be empty'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if (empty($firstName)) { |
39
|
|
|
throw new InvalidArgumentException('First name cannot be empty'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if (empty($lastName)) { |
43
|
|
|
throw new InvalidArgumentException('Last name cannot be empty'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if (empty($gender)) { |
47
|
|
|
throw new InvalidArgumentException('Gender cannot be empty'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$params = array_merge([ |
51
|
|
|
'firstName' => $firstName, |
52
|
|
|
'lastName' => $lastName, |
53
|
|
|
'email' => $email, |
54
|
|
|
'gender' => $gender, |
55
|
|
|
], $optionalParams); |
56
|
|
|
|
57
|
|
|
$response = $this->httpPost('/api/v1/customers/', $params); |
58
|
|
|
|
59
|
|
|
if (!$this->hydrator) { |
60
|
|
|
return $response; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// Use any valid status code here |
64
|
|
|
if (201 !== $response->getStatusCode()) { |
65
|
|
|
switch ($response->getStatusCode()) { |
66
|
|
|
case 400: |
67
|
|
|
throw new DomainExceptions\ValidationException(); |
68
|
|
|
break; |
|
|
|
|
69
|
|
|
default: |
70
|
|
|
$this->handleErrors($response); |
71
|
|
|
|
72
|
|
|
break; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this->hydrator->hydrate($response, Model::class); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.