Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
77.78% |
7 / 9 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Availability | |
77.78% |
7 / 9 |
|
0.00% |
0 / 2 |
6.40 | |
0.00% |
0 / 1 |
| anyAvailable | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
3.14 | |||
| methodAvailable | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
3.07 | |||
| 1 | <?php |
| 2 | namespace ExecWithFallback; |
| 3 | |
| 4 | /** |
| 5 | * Check if any of the methods are available on the system. |
| 6 | * |
| 7 | * @package ExecWithFallback |
| 8 | * @author Bjørn Rosell <it@rosell.dk> |
| 9 | */ |
| 10 | class Availability extends ExecWithFallback |
| 11 | { |
| 12 | |
| 13 | /** |
| 14 | * Check if any of the methods are available on the system. |
| 15 | * |
| 16 | * @param boolean $needResultCode Whether the code using this library is going to supply $result_code to the exec |
| 17 | * call. This matters because shell_exec is only available when not. |
| 18 | */ |
| 19 | public static function anyAvailable($needResultCode = true) |
| 20 | { |
| 21 | foreach (self::$methods as $method) { |
| 22 | if (self::methodAvailable($method, $needResultCode)) { |
| 23 | return true; |
| 24 | } |
| 25 | } |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | public static function methodAvailable($method, $needResultCode = true) |
| 30 | { |
| 31 | if (!ExecWithFallback::functionEnabled($method)) { |
| 32 | return false; |
| 33 | } |
| 34 | if ($needResultCode) { |
| 35 | return ($method != 'shell_exec'); |
| 36 | } |
| 37 | return true; |
| 38 | } |
| 39 | } |