Completed
Pull Request — master (#50)
by Dominic
02:22
created

StringChecker::checkStringArguments()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 6
nc 4
nop 1
crap 5
1
<?php
2
namespace Disque\Command\Argument;
3
4
trait StringChecker
5
{
6
    use ArrayChecker;
7
8
    /**
9
     * This command, with all its arguments, ready to be sent to Disque
10
     *
11
     * @param array $arguments Arguments
12
     * @param int $numberOfElements Number of elements that must be present in $arguments
13
     * @throws InvalidCommandArgumentException
14
     */
15 50
    protected function checkStringArgument(array $arguments, $numberOfElements = 1)
16
    {
17 50
        if (!$this->checkFixedArray($arguments, $numberOfElements) || !is_string($arguments[0])) {
18 36
            throw new InvalidCommandArgumentException($this, $arguments);
19
        }
20 14
    }
21
22
    /**
23
     * This command, with all its arguments, ready to be sent to Disque
24
     *
25
     * @param array $arguments Arguments
26
     * @throws InvalidCommandArgumentException
27
     */
28 53
    protected function checkStringArguments(array $arguments)
29
    {
30 53
        if (empty($arguments)) {
31 7
            throw new InvalidCommandArgumentException($this, $arguments);
32
        }
33
34 46
        foreach ($arguments as $argument) {
35 46
            if (!is_string($argument) || $argument === '') {
36 20
                throw new InvalidCommandArgumentException($this, $arguments);
37
            }
38 26
        }
39
    }
40
}