Completed
Push — master ( a1ce72...051ac9 )
by Tobias
33:52 queued 23:54
created

Customer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 0
loc 58
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 46 8
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
0 ignored issues
show
Bug introduced by
There is no parameter named $message. Was it maybe removed?

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 method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
25
     * @param string $location
0 ignored issues
show
Bug introduced by
There is no parameter named $location. Was it maybe removed?

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 method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
26
     * @param array  $hashtags
0 ignored issues
show
Bug introduced by
There is no parameter named $hashtags. Was it maybe removed?

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 method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
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;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
69
                default:
70
                    $this->handleErrors($response);
71
72
                    break;
73
            }
74
        }
75
76
        return $this->hydrator->hydrate($response, Model::class);
77
    }
78
}
79