1
|
|
|
<?php |
2
|
|
|
namespace Disque\Command\Argument; |
3
|
|
|
|
4
|
|
|
use Disque\Command\Argument\InvalidOptionException; |
5
|
|
|
|
6
|
|
|
trait OptionChecker |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Checks an array so that their keys are ints |
10
|
|
|
* |
11
|
|
|
* @param array $options Options |
12
|
|
|
* @param array $keys Keys to check |
13
|
|
|
* @throw InvalidOptionException |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
protected function checkOptionsInt(array $options, array $keys) |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
foreach ($keys as $intOption) { |
18
|
|
|
if (isset($options[$intOption]) && !is_int($options[$intOption])) { |
19
|
|
|
throw new InvalidOptionException($this, $options); |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Checks an array so that their keys are strings |
26
|
|
|
* |
27
|
|
|
* @param array $options Options |
28
|
|
|
* @param array $keys Keys to check |
29
|
|
|
* @throw InvalidOptionException |
30
|
|
|
*/ |
31
|
|
View Code Duplication |
protected function checkOptionsString(array $options, array $keys) |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
foreach ($keys as $intOption) { |
34
|
|
|
if (isset($options[$intOption]) && !is_string($options[$intOption])) { |
35
|
|
|
throw new InvalidOptionException($this, $options); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Checks an array so that their keys are arrays |
42
|
|
|
* |
43
|
|
|
* @param array $options Options |
44
|
|
|
* @param array $keys Keys to check |
45
|
|
|
* @throw InvalidOptionException |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
protected function checkOptionsArray(array $options, array $keys) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
foreach ($keys as $intOption) { |
50
|
|
|
if (isset($options[$intOption]) && !is_array($options[$intOption])) { |
51
|
|
|
throw new InvalidOptionException($this, $options); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.