Completed
Push — master ( fc0ef9...fd9cb0 )
by Andrew
04:08
created

CredentialsValidator::validateSubdomain()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
4
namespace ddlzz\AmoAPI\Validator;
5
6
use ddlzz\AmoAPI\Exception\InvalidArgumentException;
7
use ddlzz\AmoAPI\Utils\StringUtil;
8
9
10
/**
11
 * Class CredentialsValidator
12
 * @package ddlzz\AmoAPI\Validator
13
 * @author ddlzz
14
 */
15
class CredentialsValidator
16
{
17
    /**
18
     * @param string $subdomain
19
     * @return bool
20
     * @throws InvalidArgumentException
21
     */
22 5
    public function validateSubdomain($subdomain)
23
    {
24 5
        if (!StringUtil::isAlNum($subdomain)) {
25 4
            $message = sprintf('"%s" is not a valid subdomain', $subdomain);
26 4
            throw new InvalidArgumentException($message);
27
        }
28
29 1
        return true;
30
    }
31
32
    /**
33
     * @param string $login
34
     * @return bool
35
     * @throws InvalidArgumentException
36
     */
37 6
    public function validateLogin($login)
38
    {
39 6
        if (!StringUtil::isEmail($login)) {
40 5
            $message = sprintf('"%s" is not a valid login', $login);
41 5
            throw new InvalidArgumentException($message);
42
        }
43
44 1
        return true;
45
    }
46
47
    /**
48
     * @param string $hash
49
     * @return bool
50
     * @throws InvalidArgumentException
51
     */
52 5
    public function validateHash($hash)
53
    {
54 5
        if (!StringUtil::isAlNum($hash)) {
55 4
            $message = sprintf('"%s" is not a valid hash', $hash);
56 4
            throw new InvalidArgumentException($message);
57
        }
58
59 1
        return true;
60
    }
61
}