Passed
Pull Request — master (#13)
by
unknown
02:17
created

Customer::getLastName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Skrill\ValueObject;
6
7
/**
8
 * Class Customer
9
 *
10
 * Value object for Customer Verification Service.
11
 * The customer verification service is used to check if one of your customers, identified by an email
12
 * address or customer ID, is registered with Skrill (i.e. the customer already has an active Skrill Digital
13
 * Wallet account).You can also verify information that you hold about the customer against Skrill’s
14
 * registration records.
15
 *
16
 * https://www.skrill.com/fileadmin/content/pdf/Skrill_Customer_Verification_Service_Guide_v1.1__1_.pdf
17
 *
18
 */
19
final class Customer
20
{
21
    /** @var string */
22
    private $lastName  = '';
23
24
    /** @var string */
25
    private $firstName = '';
26
27
    /**
28
     * CustomerName constructor.
29
     * @param string $firstName
30
     * @param string $lastName
31
     */
32
    public function __construct(string $firstName = '', string $lastName = '')
33
    {
34
        $firstName = trim($firstName);
35
        $lastName  = trim($lastName);
36
37
        if ($this->validateAlpha($firstName)) {
38
            $this->firstName = $firstName;
39
        }
40
41
        if ($this->validateAlpha($lastName)) {
42
            $this->lastName  = $lastName;
43
        }
44
    }
45
46
    /**
47
     * Customer’s first name.
48
     * @return string
49
     */
50
    public function getFirstName(): string
51
    {
52
        return $this->firstName;
53
    }
54
55
    /**
56
     * Customer’s last name
57
     * @return string
58
     */
59
    public function getLastName(): string
60
    {
61
        return $this->lastName;
62
    }
63
64
    /**
65
     * Validate that a field contains only alphabetic characters
66
     * @param  string $value
67
     * @return bool
68
     */
69
    private function validateAlpha($value): bool
70
    {
71
        return (bool)preg_match('/^([a-z])+$/i', $value);
72
    }
73
}
74