Completed
Push — master ( 741118...651715 )
by Dawid
03:43
created

StringUtils   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assertNotEmpty() 0 4 2
A assertAtLeastOneArgumentNotNull() 0 9 3
A assertNumericOrNull() 0 4 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiechu\SymfonyCommonsBundle\Utils;
6
7
class StringUtils
8
{
9
    /**
10
     * @param string $string
11
     * @param string $errorMessage
12
     *
13
     * @throws \InvalidArgumentException
14
     */
15 26
    public static function assertNotEmpty(string $string, string $errorMessage = 'Empty string provided'): void
16
    {
17 26
        if ('' === $string) {
18 2
            throw new \InvalidArgumentException($errorMessage);
19
        }
20 24
    }
21
22
    /**
23
     * @param null|string $string
24
     * @param string      $errorMessage
25
     *
26
     * @throws \InvalidArgumentException
27
     */
28 8
    public static function assertNumericOrNull(?string $string, string $errorMessage = 'Parameter is not numeric'): void
29
    {
30 8
        if (null !== $string && !is_numeric($string)) {
31 2
            throw new \InvalidArgumentException($errorMessage);
32
        }
33 7
    }
34
35
    /**
36
     * @param string          $errorMessage
37
     * @param null[]|string[] ...$arguments
38
     *
39
     * @throws \InvalidArgumentException
40
     */
41 6
    public static function assertAtLeastOneArgumentNotNull(string $errorMessage, ?string ...$arguments): void
42
    {
43 6
        foreach ($arguments as $argument) {
44 6
            if ($argument !== null) {
45 6
                return;
46
            }
47
        }
48
49 1
        throw new \InvalidArgumentException($errorMessage);
50
    }
51
}
52