StringChecker::checkStringArgument()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 2
nop 2
crap 12
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
    protected function checkStringArgument(array $arguments, $numberOfElements = 1)
16
    {
17
        if (!$this->checkFixedArray($arguments, $numberOfElements) || !is_string($arguments[0])) {
18
            throw new InvalidCommandArgumentException($this, $arguments);
19
        }
20
    }
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
    protected function checkStringArguments(array $arguments)
29
    {
30
        if (empty($arguments)) {
31
            throw new InvalidCommandArgumentException($this, $arguments);
32
        }
33
34
        foreach ($arguments as $argument) {
35
            if (!is_string($argument) || $argument === '') {
36
                throw new InvalidCommandArgumentException($this, $arguments);
37
            }
38
        }
39
    }
40
}