Passed
Push — master ( 8bdcbb...696730 )
by Zbigniew
03:20
created

AccessTokenValidator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 46
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 4 2
A assertIsValid() 0 6 2
A isValidOrEmpty() 0 4 2
A assertIsValidOrEmpty() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the zibios/wrike-php-library package.
5
 *
6
 * (c) Zbigniew Ślązak
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zibios\WrikePhpLibrary\Validator;
13
14
/**
15
 * Access Token Validator.
16
 */
17
class AccessTokenValidator
18
{
19
    /**
20
     * @param mixed $value
21
     *
22
     * @return bool
23
     */
24 142
    public static function isValid($value)
25
    {
26 142
        return is_string($value) && trim($value) !== '';
27
    }
28
29
    /**
30
     * @param mixed $value
31
     *
32
     * @throws \InvalidArgumentException
33
     */
34 7
    public static function assertIsValid($value)
35
    {
36 7
        if (self::isValid($value) === false) {
37 4
            throw new \InvalidArgumentException(sprintf('Invalid Access Token, should be not empty string!'));
38
        }
39 3
    }
40
41
    /**
42
     * @param mixed $value
43
     *
44
     * @return bool
45
     */
46 136
    public static function isValidOrEmpty($value)
47
    {
48 136
        return self::isValid($value) || $value === '';
49
    }
50
51
    /**
52
     * @param mixed $value
53
     *
54
     * @throws \InvalidArgumentException
55
     */
56 36
    public static function assertIsValidOrEmpty($value)
57
    {
58 36
        if (self::isValidOrEmpty($value) === false) {
59 6
            throw new \InvalidArgumentException(sprintf('Invalid Access Token, should be not empty string!'));
60
        }
61 33
    }
62
}
63