CredentialsValidator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validateSubdomain() 0 7 2
A validateHash() 0 7 2
A validateLogin() 0 7 2
1
<?php
2
3
namespace ddlzz\AmoAPI\Validator;
4
5
use ddlzz\AmoAPI\Exception\InvalidArgumentException;
6
use ddlzz\AmoAPI\Utils\StringUtil;
7
8
/**
9
 * Class CredentialsValidator.
10
 *
11
 * @author ddlzz
12
 */
13
class CredentialsValidator
14
{
15
    /**
16
     * @param string $subdomain
17
     *
18
     * @throws InvalidArgumentException
19
     *
20
     * @return bool
21
     */
22 5
    public function validateSubdomain($subdomain)
23
    {
24 5
        if (!StringUtil::isAlNum($subdomain)) {
25 4
            throw new InvalidArgumentException(sprintf('"%s" is not a valid subdomain', $subdomain));
26
        }
27
28 1
        return true;
29
    }
30
31
    /**
32
     * @param string $login
33
     *
34
     * @throws InvalidArgumentException
35
     *
36
     * @return bool
37
     */
38 6
    public function validateLogin($login)
39
    {
40 6
        if (!StringUtil::isEmail($login)) {
41 5
            throw new InvalidArgumentException(sprintf('"%s" is not a valid login', $login));
42
        }
43
44 1
        return true;
45
    }
46
47
    /**
48
     * @param string $hash
49
     *
50
     * @throws InvalidArgumentException
51
     *
52
     * @return bool
53
     */
54 5
    public function validateHash($hash)
55
    {
56 5
        if (!StringUtil::isAlNum($hash)) {
57 4
            throw new InvalidArgumentException(sprintf('"%s" is not a valid hash', $hash));
58
        }
59
60 1
        return true;
61
    }
62
}
63