Conditions | 3 |
Paths | 3 |
Total Lines | 16 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
19 | 6 | public function run(array $args) |
|
|
|||
20 | { |
||
21 | 6 | if (!isset($args[0])) { |
|
22 | 1 | return self::fromPhpType($_POST); |
|
23 | } |
||
24 | 5 | $this->expectArguments( |
|
25 | 5 | '.post', |
|
26 | 5 | [0 => ['Symbol', 'String']], |
|
27 | 5 | $args |
|
28 | ); |
||
29 | 4 | $index = $args[0]->value(); |
|
30 | 4 | if (!isset($_POST[$index])) { |
|
31 | 1 | throw new ArgumentException('".post": Index "' . $index . '" not found.'); |
|
32 | } |
||
33 | 3 | return self::fromPhpType($_POST[$index]); |
|
34 | } |
||
35 | } |
||
36 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: