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

StringChecker::checkStringArgument()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 2
nop 2
crap 3
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
}