CredentialsValidator::validateSubdomain()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
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