AccessTokenValidator::isValid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

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