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

StringChecker   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 37
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkStringArgument() 0 6 3
B checkStringArguments() 0 12 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
}