Completed
Push — user_validation ( d439b2 )
by
unknown
08:05
created

UserValidationResponse   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 34
ccs 19
cts 19
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A buildResponse() 0 15 4
1
<?php
2
3
namespace Xsolla\SDK\Webhook\Response;
4
5
use Xsolla\SDK\API\XsollaClient;
6
use Xsolla\SDK\Webhook\WebhookResponse;
7
8
class UserValidationResponse extends WebhookResponse
9
{
10
    /**
11
     * UserValidationResponse constructor.
12
     * @param string      $userId
13
     * @param string|null $userEmail
14
     * @param string|null $userPhone
15
     * @param string|null $userCountry
16
     */
17 5
    public function __construct($userId, $userEmail = null, $userPhone = null, $userCountry = null)
18
    {
19 5
        $this->validateStringParameter('User id', $userId);
20 2
        parent::__construct(
21 2
            200,
22 2
            XsollaClient::jsonEncode($this->buildResponse($userId, $userEmail, $userPhone, $userCountry))
23 2
        );
24 2
    }
25
26 2
    private function buildResponse($userId, $userEmail, $userPhone, $userCountry)
27
    {
28 2
        $response = array('user_id' => $userId);
29 2
        if ($userEmail) {
30 1
            $response['email'] = $userEmail;
31 1
        }
32 2
        if ($userPhone) {
33 1
            $response['phone'] = $userPhone;
34 1
        }
35 2
        if ($userCountry) {
36 1
            $response['country'] = $userCountry;
37 1
        }
38
39 2
        return $response;
40
    }
41
}
42